| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
import re |
| 4 |
from dataclasses import dataclass |
| 5 |
from pathlib import Path |
| 6 |
from typing import TYPE_CHECKING, Any |
| 7 |
from unittest.mock import Mock |
| 8 |
|
| 9 |
import pytest |
| 10 |
from jinja2 import FileSystemLoader |
| 11 |
|
| 12 |
from commitizen import changelog, git |
| 13 |
from commitizen.commands.changelog import Changelog |
| 14 |
from commitizen.config import BaseConfig |
| 15 |
from commitizen.cz.conventional_commits.conventional_commits import ( |
| 16 |
ConventionalCommitsCz, |
| 17 |
) |
| 18 |
from commitizen.exceptions import InvalidConfigurationError |
| 19 |
from commitizen.version_schemes import Pep440 |
| 20 |
|
| 21 |
if TYPE_CHECKING: |
| 22 |
from commitizen.changelog_formats import ChangelogFormat |
| 23 |
|
| 24 |
COMMITS_DATA: list[dict[str, Any]] = [ |
| 25 |
{ |
| 26 |
"rev": "141ee441c9c9da0809c554103a558eb17c30ed17", |
| 27 |
"parents": ["6c4948501031b7d6405b54b21d3d635827f9421b"], |
| 28 |
"title": "bump: version 1.1.1 → 1.2.0", |
| 29 |
"body": "", |
| 30 |
"author": "Commitizen", |
| 31 |
"author_email": "[email protected]", |
| 32 |
}, |
| 33 |
{ |
| 34 |
"rev": "6c4948501031b7d6405b54b21d3d635827f9421b", |
| 35 |
"parents": ["ddd220ad515502200fe2dde443614c1075d26238"], |
| 36 |
"title": "docs: how to create custom bumps", |
| 37 |
"body": "", |
| 38 |
"author": "Commitizen", |
| 39 |
"author_email": "[email protected]", |
| 40 |
}, |
| 41 |
{ |
| 42 |
"rev": "ddd220ad515502200fe2dde443614c1075d26238", |
| 43 |
"parents": ["ad17acff2e3a2e141cbc3c6efd7705e4e6de9bfc"], |
| 44 |
"title": "feat: custom cz plugins now support bumping version", |
| 45 |
"body": "", |
| 46 |
"author": "Commitizen", |
| 47 |
"author_email": "[email protected]", |
| 48 |
}, |
| 49 |
{ |
| 50 |
"rev": "ad17acff2e3a2e141cbc3c6efd7705e4e6de9bfc", |
| 51 |
"parents": ["56c8a8da84e42b526bcbe130bd194306f7c7e813"], |
| 52 |
"title": "docs: added bump gif", |
| 53 |
"body": "", |
| 54 |
"author": "Commitizen", |
| 55 |
"author_email": "[email protected]", |
| 56 |
}, |
| 57 |
{ |
| 58 |
"rev": "56c8a8da84e42b526bcbe130bd194306f7c7e813", |
| 59 |
"parents": ["74c6134b1b2e6bb8b07ed53410faabe99b204f36"], |
| 60 |
"title": "bump: version 1.1.0 → 1.1.1", |
| 61 |
"body": "", |
| 62 |
"author": "Commitizen", |
| 63 |
"author_email": "[email protected]", |
| 64 |
}, |
| 65 |
{ |
| 66 |
"rev": "74c6134b1b2e6bb8b07ed53410faabe99b204f36", |
| 67 |
"parents": ["cbc7b5f22c4e74deff4bc92d14e19bd93524711e"], |
| 68 |
"title": "refactor: changed stdout statements", |
| 69 |
"body": "", |
| 70 |
"author": "Commitizen", |
| 71 |
"author_email": "[email protected]", |
| 72 |
}, |
| 73 |
{ |
| 74 |
"rev": "cbc7b5f22c4e74deff4bc92d14e19bd93524711e", |
| 75 |
"parents": ["1ba46f2a63cb9d6e7472eaece21528c8cd28b118"], |
| 76 |
"title": "fix(bump): commit message now fits better with semver", |
| 77 |
"body": "", |
| 78 |
"author": "Commitizen", |
| 79 |
"author_email": "[email protected]", |
| 80 |
}, |
| 81 |
{ |
| 82 |
"rev": "1ba46f2a63cb9d6e7472eaece21528c8cd28b118", |
| 83 |
"parents": ["c35dbffd1bb98bb0b3d1593797e79d1c3366af8f"], |
| 84 |
"title": "fix: conventional commit 'breaking change' in body instead of title", |
| 85 |
"body": "closes #16", |
| 86 |
"author": "Commitizen", |
| 87 |
"author_email": "[email protected]", |
| 88 |
}, |
| 89 |
{ |
| 90 |
"rev": "c35dbffd1bb98bb0b3d1593797e79d1c3366af8f", |
| 91 |
"parents": ["25313397a4ac3dc5b5c986017bee2a614399509d"], |
| 92 |
"title": "refactor(schema): command logic removed from commitizen base", |
| 93 |
"body": "", |
| 94 |
"author": "Commitizen", |
| 95 |
"author_email": "[email protected]", |
| 96 |
}, |
| 97 |
{ |
| 98 |
"rev": "25313397a4ac3dc5b5c986017bee2a614399509d", |
| 99 |
"parents": ["d2f13ac41b4e48995b3b619d931c82451886e6ff"], |
| 100 |
"title": "refactor(info): command logic removed from commitizen base", |
| 101 |
"body": "", |
| 102 |
"author": "Commitizen", |
| 103 |
"author_email": "[email protected]", |
| 104 |
}, |
| 105 |
{ |
| 106 |
"rev": "d2f13ac41b4e48995b3b619d931c82451886e6ff", |
| 107 |
"parents": ["d839e317e5b26671b010584ad8cc6bf362400fa1"], |
| 108 |
"title": "refactor(example): command logic removed from commitizen base", |
| 109 |
"body": "", |
| 110 |
"author": "Commitizen", |
| 111 |
"author_email": "[email protected]", |
| 112 |
}, |
| 113 |
{ |
| 114 |
"rev": "d839e317e5b26671b010584ad8cc6bf362400fa1", |
| 115 |
"parents": ["12d0e65beda969f7983c444ceedc2a01584f4e08"], |
| 116 |
"title": "refactor(commit): moved most of the commit logic to the commit command", |
| 117 |
"body": "", |
| 118 |
"author": "Commitizen", |
| 119 |
"author_email": "[email protected]", |
| 120 |
}, |
| 121 |
{ |
| 122 |
"rev": "12d0e65beda969f7983c444ceedc2a01584f4e08", |
| 123 |
"parents": ["fb4c85abe51c228e50773e424cbd885a8b6c610d"], |
| 124 |
"title": "docs(README): updated documentation url)", |
| 125 |
"body": "", |
| 126 |
"author": "Commitizen", |
| 127 |
"author_email": "[email protected]", |
| 128 |
}, |
| 129 |
{ |
| 130 |
"rev": "fb4c85abe51c228e50773e424cbd885a8b6c610d", |
| 131 |
"parents": ["17efb44d2cd16f6621413691a543e467c7d2dda6"], |
| 132 |
"title": "docs: mkdocs documentation", |
| 133 |
"body": "", |
| 134 |
"author": "Commitizen", |
| 135 |
"author_email": "[email protected]", |
| 136 |
}, |
| 137 |
{ |
| 138 |
"rev": "17efb44d2cd16f6621413691a543e467c7d2dda6", |
| 139 |
"parents": ["6012d9eecfce8163d75c8fff179788e9ad5347da"], |
| 140 |
"title": "Bump version 1.0.0 → 1.1.0", |
| 141 |
"body": "", |
| 142 |
"author": "Commitizen", |
| 143 |
"author_email": "[email protected]", |
| 144 |
}, |
| 145 |
{ |
| 146 |
"rev": "6012d9eecfce8163d75c8fff179788e9ad5347da", |
| 147 |
"parents": ["0c7fb0ca0168864dfc55d83c210da57771a18319"], |
| 148 |
"title": "test: fixed issues with conf", |
| 149 |
"body": "", |
| 150 |
"author": "Commitizen", |
| 151 |
"author_email": "[email protected]", |
| 152 |
}, |
| 153 |
{ |
| 154 |
"rev": "0c7fb0ca0168864dfc55d83c210da57771a18319", |
| 155 |
"parents": ["cb1dd2019d522644da5bdc2594dd6dee17122d7f"], |
| 156 |
"title": "docs(README): some new information about bump", |
| 157 |
"body": "", |
| 158 |
"author": "Commitizen", |
| 159 |
"author_email": "[email protected]", |
| 160 |
}, |
| 161 |
{ |
| 162 |
"rev": "cb1dd2019d522644da5bdc2594dd6dee17122d7f", |
| 163 |
"parents": ["9c7450f85df6bf6be508e79abf00855a30c3c73c"], |
| 164 |
"title": "feat: new working bump command", |
| 165 |
"body": "", |
| 166 |
"author": "Commitizen", |
| 167 |
"author_email": "[email protected]", |
| 168 |
}, |
| 169 |
{ |
| 170 |
"rev": "9c7450f85df6bf6be508e79abf00855a30c3c73c", |
| 171 |
"parents": ["9f3af3772baab167e3fd8775d37f041440184251"], |
| 172 |
"title": "feat: create version tag", |
| 173 |
"body": "", |
| 174 |
"author": "Commitizen", |
| 175 |
"author_email": "[email protected]", |
| 176 |
}, |
| 177 |
{ |
| 178 |
"rev": "9f3af3772baab167e3fd8775d37f041440184251", |
| 179 |
"parents": ["b0d6a3defbfde14e676e7eb34946409297d0221b"], |
| 180 |
"title": "docs: added new changelog", |
| 181 |
"body": "", |
| 182 |
"author": "Commitizen", |
| 183 |
"author_email": "[email protected]", |
| 184 |
}, |
| 185 |
{ |
| 186 |
"rev": "b0d6a3defbfde14e676e7eb34946409297d0221b", |
| 187 |
"parents": ["d630d07d912e420f0880551f3ac94e933f9d3beb"], |
| 188 |
"title": "feat: update given files with new version", |
| 189 |
"body": "", |
| 190 |
"author": "Commitizen", |
| 191 |
"author_email": "[email protected]", |
| 192 |
}, |
| 193 |
{ |
| 194 |
"rev": "d630d07d912e420f0880551f3ac94e933f9d3beb", |
| 195 |
"parents": ["1792b8980c58787906dbe6836f93f31971b1ec2d"], |
| 196 |
"title": "fix: removed all from commit", |
| 197 |
"body": "", |
| 198 |
"author": "Commitizen", |
| 199 |
"author_email": "[email protected]", |
| 200 |
}, |
| 201 |
{ |
| 202 |
"rev": "1792b8980c58787906dbe6836f93f31971b1ec2d", |
| 203 |
"parents": ["52def1ea3555185ba4b936b463311949907e31ec"], |
| 204 |
"title": "feat(config): new set key, used to set version to cfg", |
| 205 |
"body": "", |
| 206 |
"author": "Commitizen", |
| 207 |
"author_email": "[email protected]", |
| 208 |
}, |
| 209 |
{ |
| 210 |
"rev": "52def1ea3555185ba4b936b463311949907e31ec", |
| 211 |
"parents": ["3127e05077288a5e2b62893345590bf1096141b7"], |
| 212 |
"title": "feat: support for pyproject.toml", |
| 213 |
"body": "", |
| 214 |
"author": "Commitizen", |
| 215 |
"author_email": "[email protected]", |
| 216 |
}, |
| 217 |
{ |
| 218 |
"rev": "3127e05077288a5e2b62893345590bf1096141b7", |
| 219 |
"parents": ["fd480ed90a80a6ffa540549408403d5b60d0e90c"], |
| 220 |
"title": "feat: first semantic version bump implementation", |
| 221 |
"body": "", |
| 222 |
"author": "Commitizen", |
| 223 |
"author_email": "[email protected]", |
| 224 |
}, |
| 225 |
{ |
| 226 |
"rev": "fd480ed90a80a6ffa540549408403d5b60d0e90c", |
| 227 |
"parents": ["e4840a059731c0bf488381ffc77e989e85dd81ad"], |
| 228 |
"title": "fix: fix config file not working", |
| 229 |
"body": "", |
| 230 |
"author": "Commitizen", |
| 231 |
"author_email": "[email protected]", |
| 232 |
}, |
| 233 |
{ |
| 234 |
"rev": "e4840a059731c0bf488381ffc77e989e85dd81ad", |
| 235 |
"parents": ["aa44a92d68014d0da98965c0c2cb8c07957d4362"], |
| 236 |
"title": "refactor: added commands folder, better integration with decli", |
| 237 |
"body": "", |
| 238 |
"author": "Commitizen", |
| 239 |
"author_email": "[email protected]", |
| 240 |
}, |
| 241 |
{ |
| 242 |
"rev": "aa44a92d68014d0da98965c0c2cb8c07957d4362", |
| 243 |
"parents": ["58bb709765380dbd46b74ce6e8978515764eb955"], |
| 244 |
"title": "Bump version: 1.0.0b2 → 1.0.0", |
| 245 |
"body": "", |
| 246 |
"author": "Commitizen", |
| 247 |
"author_email": "[email protected]", |
| 248 |
}, |
| 249 |
{ |
| 250 |
"rev": "58bb709765380dbd46b74ce6e8978515764eb955", |
| 251 |
"parents": ["97afb0bb48e72b6feca793091a8a23c706693257"], |
| 252 |
"title": "docs(README): new badges", |
| 253 |
"body": "", |
| 254 |
"author": "Commitizen", |
| 255 |
"author_email": "[email protected]", |
| 256 |
}, |
| 257 |
{ |
| 258 |
"rev": "97afb0bb48e72b6feca793091a8a23c706693257", |
| 259 |
"parents": [ |
| 260 |
"9cecb9224aa7fa68d4afeac37eba2a25770ef251", |
| 261 |
"e004a90b81ea5b374f118759bce5951202d03d69", |
| 262 |
], |
| 263 |
"title": "Merge pull request #10 from Woile/feat/decli", |
| 264 |
"body": "Feat/decli", |
| 265 |
"author": "Commitizen", |
| 266 |
"author_email": "[email protected]", |
| 267 |
}, |
| 268 |
{ |
| 269 |
"rev": "9cecb9224aa7fa68d4afeac37eba2a25770ef251", |
| 270 |
"parents": ["f5781d1a2954d71c14ade2a6a1a95b91310b2577"], |
| 271 |
"title": "style: black to files", |
| 272 |
"body": "", |
| 273 |
"author": "Commitizen", |
| 274 |
"author_email": "[email protected]", |
| 275 |
}, |
| 276 |
{ |
| 277 |
"rev": "f5781d1a2954d71c14ade2a6a1a95b91310b2577", |
| 278 |
"parents": ["80105fb3c6d45369bc0cbf787bd329fba603864c"], |
| 279 |
"title": "ci: added travis", |
| 280 |
"body": "", |
| 281 |
"author": "Commitizen", |
| 282 |
"author_email": "[email protected]", |
| 283 |
}, |
| 284 |
{ |
| 285 |
"rev": "80105fb3c6d45369bc0cbf787bd329fba603864c", |
| 286 |
"parents": ["a96008496ffefb6b1dd9b251cb479eac6a0487f7"], |
| 287 |
"title": "refactor: removed delegator, added decli and many tests", |
| 288 |
"body": "BREAKING CHANGE: API is stable", |
| 289 |
"author": "Commitizen", |
| 290 |
"author_email": "[email protected]", |
| 291 |
}, |
| 292 |
{ |
| 293 |
"rev": "a96008496ffefb6b1dd9b251cb479eac6a0487f7", |
| 294 |
"parents": ["aab33d13110f26604fb786878856ec0b9e5fc32b"], |
| 295 |
"title": "docs: updated test command", |
| 296 |
"body": "", |
| 297 |
"author": "Commitizen", |
| 298 |
"author_email": "[email protected]", |
| 299 |
}, |
| 300 |
{ |
| 301 |
"rev": "aab33d13110f26604fb786878856ec0b9e5fc32b", |
| 302 |
"parents": ["b73791563d2f218806786090fb49ef70faa51a3a"], |
| 303 |
"title": "Bump version: 1.0.0b1 → 1.0.0b2", |
| 304 |
"body": "", |
| 305 |
"author": "Commitizen", |
| 306 |
"author_email": "[email protected]", |
| 307 |
}, |
| 308 |
{ |
| 309 |
"rev": "b73791563d2f218806786090fb49ef70faa51a3a", |
| 310 |
"parents": ["7aa06a454fb717408b3657faa590731fb4ab3719"], |
| 311 |
"title": "docs(README): updated to reflect current state", |
| 312 |
"body": "", |
| 313 |
"author": "Commitizen", |
| 314 |
"author_email": "[email protected]", |
| 315 |
}, |
| 316 |
{ |
| 317 |
"rev": "7aa06a454fb717408b3657faa590731fb4ab3719", |
| 318 |
"parents": [ |
| 319 |
"7c7e96b723c2aaa1aec3a52561f680adf0b60e97", |
| 320 |
"9589a65880016996cff156b920472b9d28d771ca", |
| 321 |
], |
| 322 |
"title": "Merge pull request #9 from Woile/dev", |
| 323 |
"body": "feat: py3 only, tests and conventional commits 1.0", |
| 324 |
"author": "Commitizen", |
| 325 |
"author_email": "[email protected]", |
| 326 |
}, |
| 327 |
{ |
| 328 |
"rev": "7c7e96b723c2aaa1aec3a52561f680adf0b60e97", |
| 329 |
"parents": ["ed830019581c83ba633bfd734720e6758eca6061"], |
| 330 |
"title": "Bump version: 0.9.11 → 1.0.0b1", |
| 331 |
"body": "", |
| 332 |
"author": "Commitizen", |
| 333 |
"author_email": "[email protected]", |
| 334 |
}, |
| 335 |
{ |
| 336 |
"rev": "ed830019581c83ba633bfd734720e6758eca6061", |
| 337 |
"parents": ["c52eca6f74f844ab3ffbde61d98ef96071e132b7"], |
| 338 |
"title": "feat: py3 only, tests and conventional commits 1.0", |
| 339 |
"body": "more tests\npyproject instead of Pipfile\nquestionary instead of whaaaaat (promptkit 2.0.0 support)", |
| 340 |
"author": "Commitizen", |
| 341 |
"author_email": "[email protected]", |
| 342 |
}, |
| 343 |
{ |
| 344 |
"rev": "c52eca6f74f844ab3ffbde61d98ef96071e132b7", |
| 345 |
"parents": ["0326652b2657083929507ee66d4d1a0899e861ba"], |
| 346 |
"title": "Bump version: 0.9.10 → 0.9.11", |
| 347 |
"body": "", |
| 348 |
"author": "Commitizen", |
| 349 |
"author_email": "[email protected]", |
| 350 |
}, |
| 351 |
{ |
| 352 |
"rev": "0326652b2657083929507ee66d4d1a0899e861ba", |
| 353 |
"parents": ["b3f89892222340150e32631ae6b7aab65230036f"], |
| 354 |
"title": "fix(config): load config reads in order without failing if there is no commitizen section", |
| 355 |
"body": "Closes #8", |
| 356 |
"author": "Commitizen", |
| 357 |
"author_email": "[email protected]", |
| 358 |
}, |
| 359 |
{ |
| 360 |
"rev": "b3f89892222340150e32631ae6b7aab65230036f", |
| 361 |
"parents": ["5e837bf8ef0735193597372cd2d85e31a8f715b9"], |
| 362 |
"title": "Bump version: 0.9.9 → 0.9.10", |
| 363 |
"body": "", |
| 364 |
"author": "Commitizen", |
| 365 |
"author_email": "[email protected]", |
| 366 |
}, |
| 367 |
{ |
| 368 |
"rev": "5e837bf8ef0735193597372cd2d85e31a8f715b9", |
| 369 |
"parents": ["684e0259cc95c7c5e94854608cd3dcebbd53219e"], |
| 370 |
"title": "fix: parse scope (this is my punishment for not having tests)", |
| 371 |
"body": "", |
| 372 |
"author": "Commitizen", |
| 373 |
"author_email": "[email protected]", |
| 374 |
}, |
| 375 |
{ |
| 376 |
"rev": "684e0259cc95c7c5e94854608cd3dcebbd53219e", |
| 377 |
"parents": ["ca38eac6ff09870851b5c76a6ff0a2a8e5ecda15"], |
| 378 |
"title": "Bump version: 0.9.8 → 0.9.9", |
| 379 |
"body": "", |
| 380 |
"author": "Commitizen", |
| 381 |
"author_email": "[email protected]", |
| 382 |
}, |
| 383 |
{ |
| 384 |
"rev": "ca38eac6ff09870851b5c76a6ff0a2a8e5ecda15", |
| 385 |
"parents": ["64168f18d4628718c49689ee16430549e96c5d4b"], |
| 386 |
"title": "fix: parse scope empty", |
| 387 |
"body": "", |
| 388 |
"author": "Commitizen", |
| 389 |
"author_email": "[email protected]", |
| 390 |
}, |
| 391 |
{ |
| 392 |
"rev": "64168f18d4628718c49689ee16430549e96c5d4b", |
| 393 |
"parents": ["9d4def716ef235a1fa5ae61614366423fbc8256f"], |
| 394 |
"title": "Bump version: 0.9.7 → 0.9.8", |
| 395 |
"body": "", |
| 396 |
"author": "Commitizen", |
| 397 |
"author_email": "[email protected]", |
| 398 |
}, |
| 399 |
{ |
| 400 |
"rev": "9d4def716ef235a1fa5ae61614366423fbc8256f", |
| 401 |
"parents": ["33b0bf1a0a4dc60aac45ed47476d2e5473add09e"], |
| 402 |
"title": "fix(scope): parse correctly again", |
| 403 |
"body": "", |
| 404 |
"author": "Commitizen", |
| 405 |
"author_email": "[email protected]", |
| 406 |
}, |
| 407 |
{ |
| 408 |
"rev": "33b0bf1a0a4dc60aac45ed47476d2e5473add09e", |
| 409 |
"parents": ["696885e891ec35775daeb5fec3ba2ab92c2629e1"], |
| 410 |
"title": "Bump version: 0.9.6 → 0.9.7", |
| 411 |
"body": "", |
| 412 |
"author": "Commitizen", |
| 413 |
"author_email": "[email protected]", |
| 414 |
}, |
| 415 |
{ |
| 416 |
"rev": "696885e891ec35775daeb5fec3ba2ab92c2629e1", |
| 417 |
"parents": ["bef4a86761a3bda309c962bae5d22ce9b57119e4"], |
| 418 |
"title": "fix(scope): parse correctly", |
| 419 |
"body": "", |
| 420 |
"author": "Commitizen", |
| 421 |
"author_email": "[email protected]", |
| 422 |
}, |
| 423 |
{ |
| 424 |
"rev": "bef4a86761a3bda309c962bae5d22ce9b57119e4", |
| 425 |
"parents": ["72472efb80f08ee3fd844660afa012c8cb256e4b"], |
| 426 |
"title": "Bump version: 0.9.5 → 0.9.6", |
| 427 |
"body": "", |
| 428 |
"author": "Commitizen", |
| 429 |
"author_email": "[email protected]", |
| 430 |
}, |
| 431 |
{ |
| 432 |
"rev": "72472efb80f08ee3fd844660afa012c8cb256e4b", |
| 433 |
"parents": ["b5561ce0ab3b56bb87712c8f90bcf37cf2474f1b"], |
| 434 |
"title": "refactor(conventionalCommit): moved filters to questions instead of message", |
| 435 |
"body": "", |
| 436 |
"author": "Commitizen", |
| 437 |
"author_email": "[email protected]", |
| 438 |
}, |
| 439 |
{ |
| 440 |
"rev": "b5561ce0ab3b56bb87712c8f90bcf37cf2474f1b", |
| 441 |
"parents": ["3e31714dc737029d96898f412e4ecd2be1bcd0ce"], |
| 442 |
"title": "fix(manifest): included missing files", |
| 443 |
"body": "", |
| 444 |
"author": "Commitizen", |
| 445 |
"author_email": "[email protected]", |
| 446 |
}, |
| 447 |
{ |
| 448 |
"rev": "3e31714dc737029d96898f412e4ecd2be1bcd0ce", |
| 449 |
"parents": ["9df721e06595fdd216884c36a28770438b4f4a39"], |
| 450 |
"title": "Bump version: 0.9.4 → 0.9.5", |
| 451 |
"body": "", |
| 452 |
"author": "Commitizen", |
| 453 |
"author_email": "[email protected]", |
| 454 |
}, |
| 455 |
{ |
| 456 |
"rev": "9df721e06595fdd216884c36a28770438b4f4a39", |
| 457 |
"parents": ["0cf6ada372470c8d09e6c9e68ebf94bbd5a1656f"], |
| 458 |
"title": "fix(config): home path for python versions between 3.0 and 3.5", |
| 459 |
"body": "", |
| 460 |
"author": "Commitizen", |
| 461 |
"author_email": "[email protected]", |
| 462 |
}, |
| 463 |
{ |
| 464 |
"rev": "0cf6ada372470c8d09e6c9e68ebf94bbd5a1656f", |
| 465 |
"parents": ["973c6b3e100f6f69a3fe48bd8ee55c135b96c318"], |
| 466 |
"title": "Bump version: 0.9.3 → 0.9.4", |
| 467 |
"body": "", |
| 468 |
"author": "Commitizen", |
| 469 |
"author_email": "[email protected]", |
| 470 |
}, |
| 471 |
{ |
| 472 |
"rev": "973c6b3e100f6f69a3fe48bd8ee55c135b96c318", |
| 473 |
"parents": ["dacc86159b260ee98eb5f57941c99ba731a01399"], |
| 474 |
"title": "feat(cli): added version", |
| 475 |
"body": "", |
| 476 |
"author": "Commitizen", |
| 477 |
"author_email": "[email protected]", |
| 478 |
}, |
| 479 |
{ |
| 480 |
"rev": "dacc86159b260ee98eb5f57941c99ba731a01399", |
| 481 |
"parents": ["4368f3c3cbfd4a1ced339212230d854bc5bab496"], |
| 482 |
"title": "Bump version: 0.9.2 → 0.9.3", |
| 483 |
"body": "", |
| 484 |
"author": "Commitizen", |
| 485 |
"author_email": "[email protected]", |
| 486 |
}, |
| 487 |
{ |
| 488 |
"rev": "4368f3c3cbfd4a1ced339212230d854bc5bab496", |
| 489 |
"parents": ["da94133288727d35dae9b91866a25045038f2d38"], |
| 490 |
"title": "feat(committer): conventional commit is a bit more intelligent now", |
| 491 |
"body": "", |
| 492 |
"author": "Commitizen", |
| 493 |
"author_email": "[email protected]", |
| 494 |
}, |
| 495 |
{ |
| 496 |
"rev": "da94133288727d35dae9b91866a25045038f2d38", |
| 497 |
"parents": ["1541f54503d2e1cf39bd777c0ca5ab5eb78772ba"], |
| 498 |
"title": "docs(README): motivation", |
| 499 |
"body": "", |
| 500 |
"author": "Commitizen", |
| 501 |
"author_email": "[email protected]", |
| 502 |
}, |
| 503 |
{ |
| 504 |
"rev": "1541f54503d2e1cf39bd777c0ca5ab5eb78772ba", |
| 505 |
"parents": ["ddc855a637b7879108308b8dbd85a0fd27c7e0e7"], |
| 506 |
"title": "Bump version: 0.9.1 → 0.9.2", |
| 507 |
"body": "", |
| 508 |
"author": "Commitizen", |
| 509 |
"author_email": "[email protected]", |
| 510 |
}, |
| 511 |
{ |
| 512 |
"rev": "ddc855a637b7879108308b8dbd85a0fd27c7e0e7", |
| 513 |
"parents": ["46e9032e18a819e466618c7a014bcb0e9981af9e"], |
| 514 |
"title": "refactor: renamed conventional_changelog to conventional_commits, not backward compatible", |
| 515 |
"body": "", |
| 516 |
"author": "Commitizen", |
| 517 |
"author_email": "[email protected]", |
| 518 |
}, |
| 519 |
{ |
| 520 |
"rev": "46e9032e18a819e466618c7a014bcb0e9981af9e", |
| 521 |
"parents": ["0fef73cd7dc77a25b82e197e7c1d3144a58c1350"], |
| 522 |
"title": "Bump version: 0.9.0 → 0.9.1", |
| 523 |
"body": "", |
| 524 |
"author": "Commitizen", |
| 525 |
"author_email": "[email protected]", |
| 526 |
}, |
| 527 |
{ |
| 528 |
"rev": "0fef73cd7dc77a25b82e197e7c1d3144a58c1350", |
| 529 |
"parents": [], |
| 530 |
"title": "fix(setup.py): future is now required for every python version", |
| 531 |
"body": "", |
| 532 |
"author": "Commitizen", |
| 533 |
"author_email": "[email protected]", |
| 534 |
}, |
| 535 |
] |
| 536 |
|
| 537 |
|
| 538 |
TAGS = [ |
| 539 |
("v1.2.0", "141ee441c9c9da0809c554103a558eb17c30ed17", "2019-04-19"), |
| 540 |
("v1.1.1", "56c8a8da84e42b526bcbe130bd194306f7c7e813", "2019-04-18"), |
| 541 |
("v1.1.0", "17efb44d2cd16f6621413691a543e467c7d2dda6", "2019-04-14"), |
| 542 |
("v1.0.0", "aa44a92d68014d0da98965c0c2cb8c07957d4362", "2019-03-01"), |
| 543 |
("1.0.0b2", "aab33d13110f26604fb786878856ec0b9e5fc32b", "2019-01-18"), |
| 544 |
("v1.0.0b1", "7c7e96b723c2aaa1aec3a52561f680adf0b60e97", "2019-01-17"), |
| 545 |
("v0.9.11", "c52eca6f74f844ab3ffbde61d98ef96071e132b7", "2018-12-17"), |
| 546 |
("v0.9.10", "b3f89892222340150e32631ae6b7aab65230036f", "2018-09-22"), |
| 547 |
("v0.9.9", "684e0259cc95c7c5e94854608cd3dcebbd53219e", "2018-09-22"), |
| 548 |
("v0.9.8", "64168f18d4628718c49689ee16430549e96c5d4b", "2018-09-22"), |
| 549 |
("v0.9.7", "33b0bf1a0a4dc60aac45ed47476d2e5473add09e", "2018-09-22"), |
| 550 |
("v0.9.6", "bef4a86761a3bda309c962bae5d22ce9b57119e4", "2018-09-19"), |
| 551 |
("v0.9.5", "3e31714dc737029d96898f412e4ecd2be1bcd0ce", "2018-08-24"), |
| 552 |
("v0.9.4", "0cf6ada372470c8d09e6c9e68ebf94bbd5a1656f", "2018-08-02"), |
| 553 |
("v0.9.3", "dacc86159b260ee98eb5f57941c99ba731a01399", "2018-07-28"), |
| 554 |
("v0.9.2", "1541f54503d2e1cf39bd777c0ca5ab5eb78772ba", "2017-11-11"), |
| 555 |
("v0.9.1", "46e9032e18a819e466618c7a014bcb0e9981af9e", "2017-11-11"), |
| 556 |
] |
| 557 |
|
| 558 |
|
| 559 |
@pytest.fixture |
| 560 |
def gitcommits() -> list[git.GitCommit]: |
| 561 |
return [ |
| 562 |
git.GitCommit( |
| 563 |
commit["rev"], |
| 564 |
commit["title"], |
| 565 |
commit["body"], |
| 566 |
commit["author"], |
| 567 |
commit["author_email"], |
| 568 |
commit["parents"], |
| 569 |
) |
| 570 |
for commit in COMMITS_DATA |
| 571 |
] |
| 572 |
|
| 573 |
|
| 574 |
@pytest.fixture |
| 575 |
def tags() -> list[git.GitTag]: |
| 576 |
return [git.GitTag(*tag) for tag in TAGS] |
| 577 |
|
| 578 |
|
| 579 |
@pytest.fixture |
| 580 |
def changelog_content(data_dir: Path) -> str: |
| 581 |
changelog = data_dir / "CHANGELOG_FOR_TEST.md" |
| 582 |
return changelog.read_text(encoding="utf-8") |
| 583 |
|
| 584 |
|
| 585 |
def test_get_commit_tag_is_a_version(gitcommits, tags): |
| 586 |
commit = gitcommits[0] |
| 587 |
tag = git.GitTag(*TAGS[0]) |
| 588 |
assert changelog.get_commit_tag(commit, tags) == tag |
| 589 |
|
| 590 |
|
| 591 |
def test_get_commit_tag_is_None(gitcommits, tags): |
| 592 |
commit = gitcommits[1] |
| 593 |
assert changelog.get_commit_tag(commit, tags) is None |
| 594 |
|
| 595 |
|
| 596 |
@pytest.mark.parametrize("test_input", TAGS) |
| 597 |
def test_valid_tag_included_in_changelog(test_input): |
| 598 |
tag = git.GitTag(*test_input) |
| 599 |
rules = changelog.TagRules() |
| 600 |
assert rules.include_in_changelog(tag) is True |
| 601 |
|
| 602 |
|
| 603 |
def test_invalid_tag_included_in_changelog(): |
| 604 |
tag = git.GitTag("not_a_version", "rev", "date") |
| 605 |
rules = changelog.TagRules() |
| 606 |
assert rules.include_in_changelog(tag) is False |
| 607 |
|
| 608 |
|
| 609 |
COMMITS_TREE = ( |
| 610 |
{ |
| 611 |
"version": "v1.2.0", |
| 612 |
"date": "2019-04-19", |
| 613 |
"changes": { |
| 614 |
"feat": [ |
| 615 |
{ |
| 616 |
"scope": None, |
| 617 |
"breaking": None, |
| 618 |
"message": "custom cz plugins now support bumping version", |
| 619 |
} |
| 620 |
] |
| 621 |
}, |
| 622 |
}, |
| 623 |
{ |
| 624 |
"version": "v1.1.1", |
| 625 |
"date": "2019-04-18", |
| 626 |
"changes": { |
| 627 |
"refactor": [ |
| 628 |
{ |
| 629 |
"scope": None, |
| 630 |
"breaking": None, |
| 631 |
"message": "changed stdout statements", |
| 632 |
}, |
| 633 |
{ |
| 634 |
"scope": "schema", |
| 635 |
"breaking": None, |
| 636 |
"message": "command logic removed from commitizen base", |
| 637 |
}, |
| 638 |
{ |
| 639 |
"scope": "info", |
| 640 |
"breaking": None, |
| 641 |
"message": "command logic removed from commitizen base", |
| 642 |
}, |
| 643 |
{ |
| 644 |
"scope": "example", |
| 645 |
"breaking": None, |
| 646 |
"message": "command logic removed from commitizen base", |
| 647 |
}, |
| 648 |
{ |
| 649 |
"scope": "commit", |
| 650 |
"breaking": None, |
| 651 |
"message": "moved most of the commit logic to the commit command", |
| 652 |
}, |
| 653 |
], |
| 654 |
"fix": [ |
| 655 |
{ |
| 656 |
"scope": "bump", |
| 657 |
"breaking": None, |
| 658 |
"message": "commit message now fits better with semver", |
| 659 |
}, |
| 660 |
{ |
| 661 |
"scope": None, |
| 662 |
"breaking": None, |
| 663 |
"message": "conventional commit 'breaking change' in body instead of title", |
| 664 |
}, |
| 665 |
], |
| 666 |
}, |
| 667 |
}, |
| 668 |
{ |
| 669 |
"version": "v1.1.0", |
| 670 |
"date": "2019-04-14", |
| 671 |
"changes": { |
| 672 |
"feat": [ |
| 673 |
{ |
| 674 |
"scope": None, |
| 675 |
"breaking": None, |
| 676 |
"message": "new working bump command", |
| 677 |
}, |
| 678 |
{"scope": None, "breaking": None, "message": "create version tag"}, |
| 679 |
{ |
| 680 |
"scope": None, |
| 681 |
"breaking": None, |
| 682 |
"message": "update given files with new version", |
| 683 |
}, |
| 684 |
{ |
| 685 |
"scope": "config", |
| 686 |
"breaking": None, |
| 687 |
"message": "new set key, used to set version to cfg", |
| 688 |
}, |
| 689 |
{ |
| 690 |
"scope": None, |
| 691 |
"breaking": None, |
| 692 |
"message": "support for pyproject.toml", |
| 693 |
}, |
| 694 |
{ |
| 695 |
"scope": None, |
| 696 |
"breaking": None, |
| 697 |
"message": "first semantic version bump implementation", |
| 698 |
}, |
| 699 |
], |
| 700 |
"fix": [ |
| 701 |
{ |
| 702 |
"scope": None, |
| 703 |
"breaking": None, |
| 704 |
"message": "removed all from commit", |
| 705 |
}, |
| 706 |
{ |
| 707 |
"scope": None, |
| 708 |
"breaking": None, |
| 709 |
"message": "fix config file not working", |
| 710 |
}, |
| 711 |
], |
| 712 |
"refactor": [ |
| 713 |
{ |
| 714 |
"scope": None, |
| 715 |
"breaking": None, |
| 716 |
"message": "added commands folder, better integration with decli", |
| 717 |
} |
| 718 |
], |
| 719 |
}, |
| 720 |
}, |
| 721 |
{ |
| 722 |
"version": "v1.0.0", |
| 723 |
"date": "2019-03-01", |
| 724 |
"changes": { |
| 725 |
"refactor": [ |
| 726 |
{ |
| 727 |
"scope": None, |
| 728 |
"breaking": None, |
| 729 |
"message": "removed delegator, added decli and many tests", |
| 730 |
} |
| 731 |
], |
| 732 |
"BREAKING CHANGE": [ |
| 733 |
{"scope": None, "breaking": None, "message": "API is stable"} |
| 734 |
], |
| 735 |
}, |
| 736 |
}, |
| 737 |
{"version": "1.0.0b2", "date": "2019-01-18", "changes": {}}, |
| 738 |
{ |
| 739 |
"version": "v1.0.0b1", |
| 740 |
"date": "2019-01-17", |
| 741 |
"changes": { |
| 742 |
"feat": [ |
| 743 |
{ |
| 744 |
"scope": None, |
| 745 |
"breaking": None, |
| 746 |
"message": "py3 only, tests and conventional commits 1.0", |
| 747 |
} |
| 748 |
] |
| 749 |
}, |
| 750 |
}, |
| 751 |
{ |
| 752 |
"version": "v0.9.11", |
| 753 |
"date": "2018-12-17", |
| 754 |
"changes": { |
| 755 |
"fix": [ |
| 756 |
{ |
| 757 |
"scope": "config", |
| 758 |
"breaking": None, |
| 759 |
"message": "load config reads in order without failing if there is no commitizen section", |
| 760 |
} |
| 761 |
] |
| 762 |
}, |
| 763 |
}, |
| 764 |
{ |
| 765 |
"version": "v0.9.10", |
| 766 |
"date": "2018-09-22", |
| 767 |
"changes": { |
| 768 |
"fix": [ |
| 769 |
{ |
| 770 |
"scope": None, |
| 771 |
"breaking": None, |
| 772 |
"message": "parse scope (this is my punishment for not having tests)", |
| 773 |
} |
| 774 |
] |
| 775 |
}, |
| 776 |
}, |
| 777 |
{ |
| 778 |
"version": "v0.9.9", |
| 779 |
"date": "2018-09-22", |
| 780 |
"changes": { |
| 781 |
"fix": [{"scope": None, "breaking": None, "message": "parse scope empty"}] |
| 782 |
}, |
| 783 |
}, |
| 784 |
{ |
| 785 |
"version": "v0.9.8", |
| 786 |
"date": "2018-09-22", |
| 787 |
"changes": { |
| 788 |
"fix": [ |
| 789 |
{ |
| 790 |
"scope": "scope", |
| 791 |
"breaking": None, |
| 792 |
"message": "parse correctly again", |
| 793 |
} |
| 794 |
] |
| 795 |
}, |
| 796 |
}, |
| 797 |
{ |
| 798 |
"version": "v0.9.7", |
| 799 |
"date": "2018-09-22", |
| 800 |
"changes": { |
| 801 |
"fix": [{"scope": "scope", "breaking": None, "message": "parse correctly"}] |
| 802 |
}, |
| 803 |
}, |
| 804 |
{ |
| 805 |
"version": "v0.9.6", |
| 806 |
"date": "2018-09-19", |
| 807 |
"changes": { |
| 808 |
"refactor": [ |
| 809 |
{ |
| 810 |
"scope": "conventionalCommit", |
| 811 |
"breaking": None, |
| 812 |
"message": "moved filters to questions instead of message", |
| 813 |
} |
| 814 |
], |
| 815 |
"fix": [ |
| 816 |
{ |
| 817 |
"scope": "manifest", |
| 818 |
"breaking": None, |
| 819 |
"message": "included missing files", |
| 820 |
} |
| 821 |
], |
| 822 |
}, |
| 823 |
}, |
| 824 |
{ |
| 825 |
"version": "v0.9.5", |
| 826 |
"date": "2018-08-24", |
| 827 |
"changes": { |
| 828 |
"fix": [ |
| 829 |
{ |
| 830 |
"scope": "config", |
| 831 |
"breaking": None, |
| 832 |
"message": "home path for python versions between 3.0 and 3.5", |
| 833 |
} |
| 834 |
] |
| 835 |
}, |
| 836 |
}, |
| 837 |
{ |
| 838 |
"version": "v0.9.4", |
| 839 |
"date": "2018-08-02", |
| 840 |
"changes": { |
| 841 |
"feat": [{"scope": "cli", "breaking": None, "message": "added version"}] |
| 842 |
}, |
| 843 |
}, |
| 844 |
{ |
| 845 |
"version": "v0.9.3", |
| 846 |
"date": "2018-07-28", |
| 847 |
"changes": { |
| 848 |
"feat": [ |
| 849 |
{ |
| 850 |
"scope": "committer", |
| 851 |
"breaking": None, |
| 852 |
"message": "conventional commit is a bit more intelligent now", |
| 853 |
} |
| 854 |
] |
| 855 |
}, |
| 856 |
}, |
| 857 |
{ |
| 858 |
"version": "v0.9.2", |
| 859 |
"date": "2017-11-11", |
| 860 |
"changes": { |
| 861 |
"refactor": [ |
| 862 |
{ |
| 863 |
"scope": None, |
| 864 |
"breaking": None, |
| 865 |
"message": "renamed conventional_changelog to conventional_commits, not backward compatible", |
| 866 |
} |
| 867 |
] |
| 868 |
}, |
| 869 |
}, |
| 870 |
{ |
| 871 |
"version": "v0.9.1", |
| 872 |
"date": "2017-11-11", |
| 873 |
"changes": { |
| 874 |
"fix": [ |
| 875 |
{ |
| 876 |
"scope": "setup.py", |
| 877 |
"breaking": None, |
| 878 |
"message": "future is now required for every python version", |
| 879 |
} |
| 880 |
] |
| 881 |
}, |
| 882 |
}, |
| 883 |
) |
| 884 |
|
| 885 |
COMMITS_TREE_AFTER_MERGED_PRERELEASES = ( |
| 886 |
{ |
| 887 |
"version": "v1.2.0", |
| 888 |
"date": "2019-04-19", |
| 889 |
"changes": { |
| 890 |
"feat": [ |
| 891 |
{ |
| 892 |
"scope": None, |
| 893 |
"breaking": None, |
| 894 |
"message": "custom cz plugins now support bumping version", |
| 895 |
} |
| 896 |
] |
| 897 |
}, |
| 898 |
}, |
| 899 |
{ |
| 900 |
"version": "v1.1.1", |
| 901 |
"date": "2019-04-18", |
| 902 |
"changes": { |
| 903 |
"refactor": [ |
| 904 |
{ |
| 905 |
"scope": None, |
| 906 |
"breaking": None, |
| 907 |
"message": "changed stdout statements", |
| 908 |
}, |
| 909 |
{ |
| 910 |
"scope": "schema", |
| 911 |
"breaking": None, |
| 912 |
"message": "command logic removed from commitizen base", |
| 913 |
}, |
| 914 |
{ |
| 915 |
"scope": "info", |
| 916 |
"breaking": None, |
| 917 |
"message": "command logic removed from commitizen base", |
| 918 |
}, |
| 919 |
{ |
| 920 |
"scope": "example", |
| 921 |
"breaking": None, |
| 922 |
"message": "command logic removed from commitizen base", |
| 923 |
}, |
| 924 |
{ |
| 925 |
"scope": "commit", |
| 926 |
"breaking": None, |
| 927 |
"message": "moved most of the commit logic to the commit command", |
| 928 |
}, |
| 929 |
], |
| 930 |
"fix": [ |
| 931 |
{ |
| 932 |
"scope": "bump", |
| 933 |
"breaking": None, |
| 934 |
"message": "commit message now fits better with semver", |
| 935 |
}, |
| 936 |
{ |
| 937 |
"scope": None, |
| 938 |
"breaking": None, |
| 939 |
"message": "conventional commit 'breaking change' in body instead of title", |
| 940 |
}, |
| 941 |
], |
| 942 |
}, |
| 943 |
}, |
| 944 |
{ |
| 945 |
"version": "v1.1.0", |
| 946 |
"date": "2019-04-14", |
| 947 |
"changes": { |
| 948 |
"feat": [ |
| 949 |
{ |
| 950 |
"scope": None, |
| 951 |
"breaking": None, |
| 952 |
"message": "new working bump command", |
| 953 |
}, |
| 954 |
{"scope": None, "breaking": None, "message": "create version tag"}, |
| 955 |
{ |
| 956 |
"scope": None, |
| 957 |
"breaking": None, |
| 958 |
"message": "update given files with new version", |
| 959 |
}, |
| 960 |
{ |
| 961 |
"scope": "config", |
| 962 |
"breaking": None, |
| 963 |
"message": "new set key, used to set version to cfg", |
| 964 |
}, |
| 965 |
{ |
| 966 |
"scope": None, |
| 967 |
"breaking": None, |
| 968 |
"message": "support for pyproject.toml", |
| 969 |
}, |
| 970 |
{ |
| 971 |
"scope": None, |
| 972 |
"breaking": None, |
| 973 |
"message": "first semantic version bump implementation", |
| 974 |
}, |
| 975 |
], |
| 976 |
"fix": [ |
| 977 |
{ |
| 978 |
"scope": None, |
| 979 |
"breaking": None, |
| 980 |
"message": "removed all from commit", |
| 981 |
}, |
| 982 |
{ |
| 983 |
"scope": None, |
| 984 |
"breaking": None, |
| 985 |
"message": "fix config file not working", |
| 986 |
}, |
| 987 |
], |
| 988 |
"refactor": [ |
| 989 |
{ |
| 990 |
"scope": None, |
| 991 |
"breaking": None, |
| 992 |
"message": "added commands folder, better integration with decli", |
| 993 |
} |
| 994 |
], |
| 995 |
}, |
| 996 |
}, |
| 997 |
{ |
| 998 |
"version": "v1.0.0", |
| 999 |
"date": "2019-03-01", |
| 1000 |
"changes": { |
| 1001 |
"refactor": [ |
| 1002 |
{ |
| 1003 |
"scope": None, |
| 1004 |
"breaking": None, |
| 1005 |
"message": "removed delegator, added decli and many tests", |
| 1006 |
} |
| 1007 |
], |
| 1008 |
"feat": [ |
| 1009 |
{ |
| 1010 |
"scope": None, |
| 1011 |
"breaking": None, |
| 1012 |
"message": "py3 only, tests and conventional commits 1.0", |
| 1013 |
} |
| 1014 |
], |
| 1015 |
"BREAKING CHANGE": [ |
| 1016 |
{"scope": None, "breaking": None, "message": "API is stable"} |
| 1017 |
], |
| 1018 |
}, |
| 1019 |
}, |
| 1020 |
{ |
| 1021 |
"version": "v0.9.11", |
| 1022 |
"date": "2018-12-17", |
| 1023 |
"changes": { |
| 1024 |
"fix": [ |
| 1025 |
{ |
| 1026 |
"scope": "config", |
| 1027 |
"breaking": None, |
| 1028 |
"message": "load config reads in order without failing if there is no commitizen section", |
| 1029 |
} |
| 1030 |
] |
| 1031 |
}, |
| 1032 |
}, |
| 1033 |
{ |
| 1034 |
"version": "v0.9.10", |
| 1035 |
"date": "2018-09-22", |
| 1036 |
"changes": { |
| 1037 |
"fix": [ |
| 1038 |
{ |
| 1039 |
"scope": None, |
| 1040 |
"breaking": None, |
| 1041 |
"message": "parse scope (this is my punishment for not having tests)", |
| 1042 |
} |
| 1043 |
] |
| 1044 |
}, |
| 1045 |
}, |
| 1046 |
{ |
| 1047 |
"version": "v0.9.9", |
| 1048 |
"date": "2018-09-22", |
| 1049 |
"changes": { |
| 1050 |
"fix": [{"scope": None, "breaking": None, "message": "parse scope empty"}] |
| 1051 |
}, |
| 1052 |
}, |
| 1053 |
{ |
| 1054 |
"version": "v0.9.8", |
| 1055 |
"date": "2018-09-22", |
| 1056 |
"changes": { |
| 1057 |
"fix": [ |
| 1058 |
{ |
| 1059 |
"scope": "scope", |
| 1060 |
"breaking": None, |
| 1061 |
"message": "parse correctly again", |
| 1062 |
} |
| 1063 |
] |
| 1064 |
}, |
| 1065 |
}, |
| 1066 |
{ |
| 1067 |
"version": "v0.9.7", |
| 1068 |
"date": "2018-09-22", |
| 1069 |
"changes": { |
| 1070 |
"fix": [{"scope": "scope", "breaking": None, "message": "parse correctly"}] |
| 1071 |
}, |
| 1072 |
}, |
| 1073 |
{ |
| 1074 |
"version": "v0.9.6", |
| 1075 |
"date": "2018-09-19", |
| 1076 |
"changes": { |
| 1077 |
"refactor": [ |
| 1078 |
{ |
| 1079 |
"scope": "conventionalCommit", |
| 1080 |
"breaking": None, |
| 1081 |
"message": "moved filters to questions instead of message", |
| 1082 |
} |
| 1083 |
], |
| 1084 |
"fix": [ |
| 1085 |
{ |
| 1086 |
"scope": "manifest", |
| 1087 |
"breaking": None, |
| 1088 |
"message": "included missing files", |
| 1089 |
} |
| 1090 |
], |
| 1091 |
}, |
| 1092 |
}, |
| 1093 |
{ |
| 1094 |
"version": "v0.9.5", |
| 1095 |
"date": "2018-08-24", |
| 1096 |
"changes": { |
| 1097 |
"fix": [ |
| 1098 |
{ |
| 1099 |
"scope": "config", |
| 1100 |
"breaking": None, |
| 1101 |
"message": "home path for python versions between 3.0 and 3.5", |
| 1102 |
} |
| 1103 |
] |
| 1104 |
}, |
| 1105 |
}, |
| 1106 |
{ |
| 1107 |
"version": "v0.9.4", |
| 1108 |
"date": "2018-08-02", |
| 1109 |
"changes": { |
| 1110 |
"feat": [{"scope": "cli", "breaking": None, "message": "added version"}] |
| 1111 |
}, |
| 1112 |
}, |
| 1113 |
{ |
| 1114 |
"version": "v0.9.3", |
| 1115 |
"date": "2018-07-28", |
| 1116 |
"changes": { |
| 1117 |
"feat": [ |
| 1118 |
{ |
| 1119 |
"scope": "committer", |
| 1120 |
"breaking": None, |
| 1121 |
"message": "conventional commit is a bit more intelligent now", |
| 1122 |
} |
| 1123 |
] |
| 1124 |
}, |
| 1125 |
}, |
| 1126 |
{ |
| 1127 |
"version": "v0.9.2", |
| 1128 |
"date": "2017-11-11", |
| 1129 |
"changes": { |
| 1130 |
"refactor": [ |
| 1131 |
{ |
| 1132 |
"scope": None, |
| 1133 |
"breaking": None, |
| 1134 |
"message": "renamed conventional_changelog to conventional_commits, not backward compatible", |
| 1135 |
} |
| 1136 |
] |
| 1137 |
}, |
| 1138 |
}, |
| 1139 |
{ |
| 1140 |
"version": "v0.9.1", |
| 1141 |
"date": "2017-11-11", |
| 1142 |
"changes": { |
| 1143 |
"fix": [ |
| 1144 |
{ |
| 1145 |
"scope": "setup.py", |
| 1146 |
"breaking": None, |
| 1147 |
"message": "future is now required for every python version", |
| 1148 |
} |
| 1149 |
] |
| 1150 |
}, |
| 1151 |
}, |
| 1152 |
) |
| 1153 |
|
| 1154 |
|
| 1155 |
@pytest.mark.parametrize("merge_prereleases", [True, False]) |
| 1156 |
def test_generate_tree_from_commits(gitcommits, tags, merge_prereleases): |
| 1157 |
parser = ConventionalCommitsCz.commit_parser |
| 1158 |
changelog_pattern = ConventionalCommitsCz.bump_pattern |
| 1159 |
rules = changelog.TagRules( |
| 1160 |
merge_prereleases=merge_prereleases, |
| 1161 |
) |
| 1162 |
tree = changelog.generate_tree_from_commits( |
| 1163 |
gitcommits, tags, parser, changelog_pattern, rules=rules |
| 1164 |
) |
| 1165 |
expected = ( |
| 1166 |
COMMITS_TREE_AFTER_MERGED_PRERELEASES if merge_prereleases else COMMITS_TREE |
| 1167 |
) |
| 1168 |
|
| 1169 |
for release, expected_release in zip(tree, expected): |
| 1170 |
assert release["version"] == expected_release["version"] |
| 1171 |
assert release["date"] == expected_release["date"] |
| 1172 |
assert release["changes"].keys() == expected_release["changes"].keys() |
| 1173 |
for change_type in release["changes"]: |
| 1174 |
changes = release["changes"][change_type] |
| 1175 |
expected_changes = expected_release["changes"][change_type] |
| 1176 |
for change, expected_change in zip(changes, expected_changes): |
| 1177 |
assert change["scope"] == expected_change["scope"] |
| 1178 |
assert change["breaking"] == expected_change["breaking"] |
| 1179 |
assert change["message"] == expected_change["message"] |
| 1180 |
assert change["author"] == "Commitizen" |
| 1181 |
assert change["author_email"] in "[email protected]" |
| 1182 |
assert "sha1" in change |
| 1183 |
assert "parents" in change |
| 1184 |
|
| 1185 |
|
| 1186 |
def test_generate_tree_from_commits_with_no_commits(tags): |
| 1187 |
parser = ConventionalCommitsCz.commit_parser |
| 1188 |
changelog_pattern = ConventionalCommitsCz.bump_pattern |
| 1189 |
tree = changelog.generate_tree_from_commits([], tags, parser, changelog_pattern) |
| 1190 |
|
| 1191 |
assert tuple(tree) == ({"changes": {}, "date": "", "version": "Unreleased"},) |
| 1192 |
|
| 1193 |
|
| 1194 |
@pytest.mark.parametrize( |
| 1195 |
("change_type_order", "expected_reordering"), |
| 1196 |
[ |
| 1197 |
([], {}), |
| 1198 |
( |
| 1199 |
["BREAKING CHANGE", "refactor"], |
| 1200 |
{ |
| 1201 |
"1.1.0": { |
| 1202 |
"original": ["feat", "fix", "refactor"], |
| 1203 |
"sorted": ["refactor", "feat", "fix"], |
| 1204 |
}, |
| 1205 |
"1.0.0": { |
| 1206 |
"original": ["refactor", "BREAKING CHANGE"], |
| 1207 |
"sorted": ["BREAKING CHANGE", "refactor"], |
| 1208 |
}, |
| 1209 |
}, |
| 1210 |
), |
| 1211 |
], |
| 1212 |
) |
| 1213 |
def test_generate_ordered_changelog_tree(change_type_order, expected_reordering): |
| 1214 |
tree = changelog.generate_ordered_changelog_tree(COMMITS_TREE, change_type_order) |
| 1215 |
|
| 1216 |
for index, entry in enumerate(tuple(tree)): |
| 1217 |
version = entry["version"] |
| 1218 |
if version in expected_reordering: |
| 1219 |
# Verify that all keys are present |
| 1220 |
assert [*entry.keys()] == [*COMMITS_TREE[index].keys()] |
| 1221 |
# Verify that the reorder only impacted the returned dict and not the original |
| 1222 |
expected = expected_reordering[version] |
| 1223 |
assert [*entry["changes"].keys()] == expected["sorted"] |
| 1224 |
assert [*COMMITS_TREE[index]["changes"].keys()] == expected["original"] |
| 1225 |
else: |
| 1226 |
assert [*entry["changes"].keys()] == [*entry["changes"].keys()] |
| 1227 |
|
| 1228 |
|
| 1229 |
def test_generate_ordered_changelog_tree_raises(): |
| 1230 |
change_type_order = ["BREAKING CHANGE", "feat", "refactor", "feat"] |
| 1231 |
with pytest.raises( |
| 1232 |
InvalidConfigurationError, match="Change types contain duplicated types" |
| 1233 |
): |
| 1234 |
list(changelog.generate_ordered_changelog_tree(COMMITS_TREE, change_type_order)) |
| 1235 |
|
| 1236 |
|
| 1237 |
def test_render_changelog( |
| 1238 |
gitcommits, tags, changelog_content, any_changelog_format: ChangelogFormat |
| 1239 |
): |
| 1240 |
parser = ConventionalCommitsCz.commit_parser |
| 1241 |
changelog_pattern = ConventionalCommitsCz.changelog_pattern |
| 1242 |
loader = ConventionalCommitsCz.template_loader |
| 1243 |
template = any_changelog_format.template |
| 1244 |
tree = changelog.generate_tree_from_commits( |
| 1245 |
gitcommits, tags, parser, changelog_pattern |
| 1246 |
) |
| 1247 |
result = changelog.render_changelog(tree, loader, template) |
| 1248 |
assert result == changelog_content |
| 1249 |
|
| 1250 |
|
| 1251 |
def test_render_changelog_from_default_plugin_values( |
| 1252 |
gitcommits, tags, changelog_content, any_changelog_format: ChangelogFormat |
| 1253 |
): |
| 1254 |
parser = ConventionalCommitsCz.commit_parser |
| 1255 |
changelog_pattern = ConventionalCommitsCz.changelog_pattern |
| 1256 |
loader = ConventionalCommitsCz.template_loader |
| 1257 |
template = any_changelog_format.template |
| 1258 |
tree = changelog.generate_tree_from_commits( |
| 1259 |
gitcommits, tags, parser, changelog_pattern |
| 1260 |
) |
| 1261 |
result = changelog.render_changelog(tree, loader, template) |
| 1262 |
assert result == changelog_content |
| 1263 |
|
| 1264 |
|
| 1265 |
def test_render_changelog_override_loader(gitcommits, tags, tmp_path: Path): |
| 1266 |
loader = FileSystemLoader(tmp_path) |
| 1267 |
template = "tpl.j2" |
| 1268 |
tpl = "loader overridden" |
| 1269 |
(tmp_path / template).write_text(tpl) |
| 1270 |
parser = ConventionalCommitsCz.commit_parser |
| 1271 |
changelog_pattern = ConventionalCommitsCz.changelog_pattern |
| 1272 |
tree = changelog.generate_tree_from_commits( |
| 1273 |
gitcommits, tags, parser, changelog_pattern |
| 1274 |
) |
| 1275 |
result = changelog.render_changelog(tree, loader, template) |
| 1276 |
assert result == tpl |
| 1277 |
|
| 1278 |
|
| 1279 |
def test_render_changelog_override_template_from_cwd( |
| 1280 |
gitcommits, tags, chdir: Path, any_changelog_format: ChangelogFormat |
| 1281 |
): |
| 1282 |
tpl = "overridden from cwd" |
| 1283 |
template = any_changelog_format.template |
| 1284 |
(chdir / template).write_text(tpl) |
| 1285 |
parser = ConventionalCommitsCz.commit_parser |
| 1286 |
changelog_pattern = ConventionalCommitsCz.changelog_pattern |
| 1287 |
loader = ConventionalCommitsCz.template_loader |
| 1288 |
tree = changelog.generate_tree_from_commits( |
| 1289 |
gitcommits, tags, parser, changelog_pattern |
| 1290 |
) |
| 1291 |
result = changelog.render_changelog(tree, loader, template) |
| 1292 |
assert result == tpl |
| 1293 |
|
| 1294 |
|
| 1295 |
def test_render_changelog_override_template_from_cwd_with_custom_name( |
| 1296 |
gitcommits, tags, chdir: Path |
| 1297 |
): |
| 1298 |
tpl = "template overridden from cwd" |
| 1299 |
tpl_name = "tpl.j2" |
| 1300 |
(chdir / tpl_name).write_text(tpl) |
| 1301 |
parser = ConventionalCommitsCz.commit_parser |
| 1302 |
changelog_pattern = ConventionalCommitsCz.changelog_pattern |
| 1303 |
loader = ConventionalCommitsCz.template_loader |
| 1304 |
tree = changelog.generate_tree_from_commits( |
| 1305 |
gitcommits, tags, parser, changelog_pattern |
| 1306 |
) |
| 1307 |
result = changelog.render_changelog(tree, loader, tpl_name) |
| 1308 |
assert result == tpl |
| 1309 |
|
| 1310 |
|
| 1311 |
def test_render_changelog_override_loader_and_template( |
| 1312 |
gitcommits, tags, tmp_path: Path |
| 1313 |
): |
| 1314 |
loader = FileSystemLoader(tmp_path) |
| 1315 |
tpl = "loader and template overridden" |
| 1316 |
tpl_name = "tpl.j2" |
| 1317 |
(tmp_path / tpl_name).write_text(tpl) |
| 1318 |
parser = ConventionalCommitsCz.commit_parser |
| 1319 |
changelog_pattern = ConventionalCommitsCz.bump_pattern |
| 1320 |
tree = changelog.generate_tree_from_commits( |
| 1321 |
gitcommits, tags, parser, changelog_pattern |
| 1322 |
) |
| 1323 |
result = changelog.render_changelog(tree, loader, tpl_name) |
| 1324 |
assert result == tpl |
| 1325 |
|
| 1326 |
|
| 1327 |
def test_render_changelog_support_arbitrary_kwargs(gitcommits, tags, tmp_path: Path): |
| 1328 |
loader = FileSystemLoader(tmp_path) |
| 1329 |
tpl_name = "tpl.j2" |
| 1330 |
(tmp_path / tpl_name).write_text("{{ key }}") |
| 1331 |
parser = ConventionalCommitsCz.commit_parser |
| 1332 |
changelog_pattern = ConventionalCommitsCz.changelog_pattern |
| 1333 |
tree = changelog.generate_tree_from_commits( |
| 1334 |
gitcommits, tags, parser, changelog_pattern |
| 1335 |
) |
| 1336 |
result = changelog.render_changelog(tree, loader, tpl_name, key="value") |
| 1337 |
assert result == "value" |
| 1338 |
|
| 1339 |
|
| 1340 |
def test_render_changelog_unreleased(gitcommits, any_changelog_format: ChangelogFormat): |
| 1341 |
some_commits = gitcommits[:7] |
| 1342 |
parser = ConventionalCommitsCz.commit_parser |
| 1343 |
changelog_pattern = ConventionalCommitsCz.changelog_pattern |
| 1344 |
loader = ConventionalCommitsCz.template_loader |
| 1345 |
template = any_changelog_format.template |
| 1346 |
tree = changelog.generate_tree_from_commits( |
| 1347 |
some_commits, [], parser, changelog_pattern |
| 1348 |
) |
| 1349 |
result = changelog.render_changelog(tree, loader, template) |
| 1350 |
assert "Unreleased" in result |
| 1351 |
|
| 1352 |
|
| 1353 |
def test_render_changelog_tag_and_unreleased( |
| 1354 |
gitcommits, tags, any_changelog_format: ChangelogFormat |
| 1355 |
): |
| 1356 |
some_commits = gitcommits[:7] |
| 1357 |
single_tag = [ |
| 1358 |
tag for tag in tags if tag.rev == "56c8a8da84e42b526bcbe130bd194306f7c7e813" |
| 1359 |
] |
| 1360 |
|
| 1361 |
parser = ConventionalCommitsCz.commit_parser |
| 1362 |
changelog_pattern = ConventionalCommitsCz.changelog_pattern |
| 1363 |
loader = ConventionalCommitsCz.template_loader |
| 1364 |
template = any_changelog_format.template |
| 1365 |
tree = changelog.generate_tree_from_commits( |
| 1366 |
some_commits, single_tag, parser, changelog_pattern |
| 1367 |
) |
| 1368 |
result = changelog.render_changelog(tree, loader, template) |
| 1369 |
|
| 1370 |
assert "Unreleased" in result |
| 1371 |
assert "## v1.1.1" in result |
| 1372 |
|
| 1373 |
|
| 1374 |
def test_render_changelog_with_change_type( |
| 1375 |
gitcommits, tags, any_changelog_format: ChangelogFormat |
| 1376 |
): |
| 1377 |
new_title = ":some-emoji: feature" |
| 1378 |
change_type_map = {"feat": new_title} |
| 1379 |
parser = ConventionalCommitsCz.commit_parser |
| 1380 |
changelog_pattern = ConventionalCommitsCz.changelog_pattern |
| 1381 |
loader = ConventionalCommitsCz.template_loader |
| 1382 |
template = any_changelog_format.template |
| 1383 |
tree = changelog.generate_tree_from_commits( |
| 1384 |
gitcommits, tags, parser, changelog_pattern, change_type_map=change_type_map |
| 1385 |
) |
| 1386 |
result = changelog.render_changelog(tree, loader, template) |
| 1387 |
assert new_title in result |
| 1388 |
|
| 1389 |
|
| 1390 |
def test_render_changelog_with_changelog_message_builder_hook( |
| 1391 |
gitcommits, tags, any_changelog_format: ChangelogFormat |
| 1392 |
): |
| 1393 |
def changelog_message_builder_hook(message: dict, commit: git.GitCommit) -> dict: |
| 1394 |
message["message"] = ( |
| 1395 |
f"{message['message']} [link](github.com/232323232) {commit.author} {commit.author_email}" |
| 1396 |
) |
| 1397 |
return message |
| 1398 |
|
| 1399 |
parser = ConventionalCommitsCz.commit_parser |
| 1400 |
changelog_pattern = ConventionalCommitsCz.changelog_pattern |
| 1401 |
loader = ConventionalCommitsCz.template_loader |
| 1402 |
template = any_changelog_format.template |
| 1403 |
tree = changelog.generate_tree_from_commits( |
| 1404 |
gitcommits, |
| 1405 |
tags, |
| 1406 |
parser, |
| 1407 |
changelog_pattern, |
| 1408 |
changelog_message_builder_hook=changelog_message_builder_hook, |
| 1409 |
) |
| 1410 |
result = changelog.render_changelog(tree, loader, template) |
| 1411 |
|
| 1412 |
assert "[link](github.com/232323232) Commitizen [email protected]" in result |
| 1413 |
|
| 1414 |
|
| 1415 |
def test_changelog_message_builder_hook_can_remove_commits( |
| 1416 |
gitcommits, tags, any_changelog_format: ChangelogFormat |
| 1417 |
): |
| 1418 |
def changelog_message_builder_hook(message: dict, commit: git.GitCommit): |
| 1419 |
return None |
| 1420 |
|
| 1421 |
parser = ConventionalCommitsCz.commit_parser |
| 1422 |
changelog_pattern = ConventionalCommitsCz.changelog_pattern |
| 1423 |
loader = ConventionalCommitsCz.template_loader |
| 1424 |
template = any_changelog_format.template |
| 1425 |
tree = changelog.generate_tree_from_commits( |
| 1426 |
gitcommits, |
| 1427 |
tags, |
| 1428 |
parser, |
| 1429 |
changelog_pattern, |
| 1430 |
changelog_message_builder_hook=changelog_message_builder_hook, |
| 1431 |
) |
| 1432 |
result = changelog.render_changelog(tree, loader, template) |
| 1433 |
|
| 1434 |
RE_HEADER = re.compile(r"^## v?\d+\.\d+\.\d+(\w)* \(\d{4}-\d{2}-\d{2}\)$") |
| 1435 |
# Rendered changelog should be empty, only containing version headers |
| 1436 |
for no, line in enumerate(result.splitlines()): |
| 1437 |
if line := line.strip(): |
| 1438 |
assert RE_HEADER.match(line), f"Line {no} should not be there: {line}" |
| 1439 |
|
| 1440 |
|
| 1441 |
def test_render_changelog_with_changelog_message_builder_hook_multiple_entries( |
| 1442 |
gitcommits, tags, any_changelog_format: ChangelogFormat |
| 1443 |
): |
| 1444 |
def changelog_message_builder_hook(message: dict, commit: git.GitCommit): |
| 1445 |
messages = [message.copy(), message.copy(), message.copy()] |
| 1446 |
for idx, msg in enumerate(messages): |
| 1447 |
msg["message"] = f"Message #{idx}" |
| 1448 |
return messages |
| 1449 |
|
| 1450 |
parser = ConventionalCommitsCz.commit_parser |
| 1451 |
changelog_pattern = ConventionalCommitsCz.changelog_pattern |
| 1452 |
loader = ConventionalCommitsCz.template_loader |
| 1453 |
template = any_changelog_format.template |
| 1454 |
tree = changelog.generate_tree_from_commits( |
| 1455 |
gitcommits, |
| 1456 |
tags, |
| 1457 |
parser, |
| 1458 |
changelog_pattern, |
| 1459 |
changelog_message_builder_hook=changelog_message_builder_hook, |
| 1460 |
) |
| 1461 |
result = changelog.render_changelog(tree, loader, template) |
| 1462 |
|
| 1463 |
for idx in range(3): |
| 1464 |
assert f"Message #{idx}" in result |
| 1465 |
|
| 1466 |
|
| 1467 |
def test_changelog_message_builder_hook_can_access_and_modify_change_type( |
| 1468 |
gitcommits, tags, any_changelog_format: ChangelogFormat |
| 1469 |
): |
| 1470 |
def changelog_message_builder_hook(message: dict, commit: git.GitCommit): |
| 1471 |
assert "change_type" in message |
| 1472 |
message["change_type"] = "overridden" |
| 1473 |
return message |
| 1474 |
|
| 1475 |
parser = ConventionalCommitsCz.commit_parser |
| 1476 |
changelog_pattern = ConventionalCommitsCz.changelog_pattern |
| 1477 |
loader = ConventionalCommitsCz.template_loader |
| 1478 |
template = any_changelog_format.template |
| 1479 |
tree = changelog.generate_tree_from_commits( |
| 1480 |
gitcommits, |
| 1481 |
tags, |
| 1482 |
parser, |
| 1483 |
changelog_pattern, |
| 1484 |
changelog_message_builder_hook=changelog_message_builder_hook, |
| 1485 |
) |
| 1486 |
result = changelog.render_changelog(tree, loader, template) |
| 1487 |
|
| 1488 |
RE_HEADER = re.compile(r"^### (?P<type>.+)$") |
| 1489 |
# There should be only "overridden" change type headers |
| 1490 |
for no, line in enumerate(result.splitlines()): |
| 1491 |
if (line := line.strip()) and (match := RE_HEADER.match(line)): |
| 1492 |
change_type = match.group("type") |
| 1493 |
assert change_type == "overridden", ( |
| 1494 |
f"Line {no}: type {change_type} should have been overridden" |
| 1495 |
) |
| 1496 |
|
| 1497 |
|
| 1498 |
def test_render_changelog_with_changelog_release_hook( |
| 1499 |
gitcommits, tags, any_changelog_format: ChangelogFormat |
| 1500 |
): |
| 1501 |
def changelog_release_hook(release: dict, tag: git.GitTag | None) -> dict: |
| 1502 |
release["extra"] = "whatever" |
| 1503 |
return release |
| 1504 |
|
| 1505 |
parser = ConventionalCommitsCz.commit_parser |
| 1506 |
changelog_pattern = ConventionalCommitsCz.changelog_pattern |
| 1507 |
tree = changelog.generate_tree_from_commits( |
| 1508 |
gitcommits, |
| 1509 |
tags, |
| 1510 |
parser, |
| 1511 |
changelog_pattern, |
| 1512 |
changelog_release_hook=changelog_release_hook, |
| 1513 |
) |
| 1514 |
for release in tree: |
| 1515 |
assert release["extra"] == "whatever" |
| 1516 |
|
| 1517 |
|
| 1518 |
def test_get_smart_tag_range_returns_an_extra_for_a_range(tags): |
| 1519 |
start, end = ( |
| 1520 |
tags[0], |
| 1521 |
tags[2], |
| 1522 |
) # len here is 3, but we expect one more tag as designed |
| 1523 |
res = changelog.get_smart_tag_range(tags, start.name, end.name) |
| 1524 |
assert 4 == len(res) |
| 1525 |
|
| 1526 |
|
| 1527 |
def test_get_smart_tag_range_returns_an_extra_for_a_single_tag(tags): |
| 1528 |
start = tags[0] # len here is 1, but we expect one more tag as designed |
| 1529 |
res = changelog.get_smart_tag_range(tags, start.name) |
| 1530 |
assert 2 == len(res) |
| 1531 |
|
| 1532 |
|
| 1533 |
def test_get_next_tag_name_after_version(tags): |
| 1534 |
# Test finding next tag after a version |
| 1535 |
next_tag_name = changelog.get_next_tag_name_after_version(tags, "v1.2.0") |
| 1536 |
assert next_tag_name == "v1.1.1" |
| 1537 |
|
| 1538 |
next_tag_name = changelog.get_next_tag_name_after_version(tags, "v1.1.0") |
| 1539 |
assert next_tag_name == "v1.0.0" |
| 1540 |
|
| 1541 |
# Test finding last tag when given version is last |
| 1542 |
last_tag_name = changelog.get_next_tag_name_after_version(tags, "v0.9.1") |
| 1543 |
assert last_tag_name is None |
| 1544 |
|
| 1545 |
# Test error when version not found |
| 1546 |
with pytest.raises( |
| 1547 |
changelog.NoCommitsFoundError, match="Could not find a valid revision range" |
| 1548 |
): |
| 1549 |
changelog.get_next_tag_name_after_version(tags, "nonexistent") |
| 1550 |
|
| 1551 |
|
| 1552 |
@dataclass |
| 1553 |
class TagDef: |
| 1554 |
name: str |
| 1555 |
is_version: bool |
| 1556 |
is_legacy: bool |
| 1557 |
is_ignored: bool |
| 1558 |
|
| 1559 |
|
| 1560 |
TAGS_PARAMS = ( |
| 1561 |
pytest.param(TagDef("1.2.3", True, False, False), id="version"), |
| 1562 |
# We test with `v-` prefix as `v` prefix is a special case kept for backward compatibility |
| 1563 |
pytest.param(TagDef("v-1.2.3", False, True, False), id="v-prefix"), |
| 1564 |
pytest.param(TagDef("project-1.2.3", False, True, False), id="project-prefix"), |
| 1565 |
pytest.param(TagDef("ignored", False, False, True), id="ignored"), |
| 1566 |
pytest.param(TagDef("unknown", False, False, False), id="unknown"), |
| 1567 |
) |
| 1568 |
|
| 1569 |
|
| 1570 |
@pytest.mark.parametrize("tag", TAGS_PARAMS) |
| 1571 |
def test_tag_rules_tag_format_only(tag: TagDef): |
| 1572 |
rules = changelog.TagRules(Pep440, "$version") |
| 1573 |
assert rules.is_version_tag(tag.name) is tag.is_version |
| 1574 |
|
| 1575 |
|
| 1576 |
@pytest.mark.parametrize("tag", TAGS_PARAMS) |
| 1577 |
def test_tag_rules_with_legacy_tags(tag: TagDef): |
| 1578 |
rules = changelog.TagRules( |
| 1579 |
scheme=Pep440, |
| 1580 |
tag_format="$version", |
| 1581 |
legacy_tag_formats=["v-$version", "project-${version}"], |
| 1582 |
) |
| 1583 |
assert rules.is_version_tag(tag.name) is tag.is_version or tag.is_legacy |
| 1584 |
|
| 1585 |
|
| 1586 |
@pytest.mark.parametrize("tag", TAGS_PARAMS) |
| 1587 |
def test_tag_rules_with_ignored_tags(tag: TagDef): |
| 1588 |
rules = changelog.TagRules( |
| 1589 |
scheme=Pep440, tag_format="$version", ignored_tag_formats=["ignored"] |
| 1590 |
) |
| 1591 |
assert rules.is_ignored_tag(tag.name) is tag.is_ignored |
| 1592 |
|
| 1593 |
|
| 1594 |
def test_tags_rules_get_version_tags(capsys: pytest.CaptureFixture): |
| 1595 |
tags = [ |
| 1596 |
git.GitTag("v1.1.0", "17efb44d2cd16f6621413691a543e467c7d2dda6", "2019-04-14"), |
| 1597 |
git.GitTag("v1.0.0", "aa44a92d68014d0da98965c0c2cb8c07957d4362", "2019-03-01"), |
| 1598 |
git.GitTag("1.0.0b2", "aab33d13110f26604fb786878856ec0b9e5fc32b", "2019-01-18"), |
| 1599 |
git.GitTag( |
| 1600 |
"project-not-a-version", |
| 1601 |
"7c7e96b723c2aaa1aec3a52561f680adf0b60e97", |
| 1602 |
"2019-01-17", |
| 1603 |
), |
| 1604 |
git.GitTag( |
| 1605 |
"not-a-version", "c52eca6f74f844ab3ffbde61d98ef96071e132b7", "2018-12-17" |
| 1606 |
), |
| 1607 |
git.GitTag( |
| 1608 |
"star-something", "c52eca6f74f844ab3ffbde61d98fe96071e132b2", "2018-11-12" |
| 1609 |
), |
| 1610 |
git.GitTag("known", "b3f89892222340150e32631ae6b7aab65230036f", "2018-09-22"), |
| 1611 |
git.GitTag( |
| 1612 |
"ignored-0.9.3", "684e0259cc95c7c5e94854608cd3dcebbd53219e", "2018-09-22" |
| 1613 |
), |
| 1614 |
git.GitTag( |
| 1615 |
"project-0.9.3", "dacc86159b260ee98eb5f57941c99ba731a01399", "2018-07-28" |
| 1616 |
), |
| 1617 |
git.GitTag( |
| 1618 |
"anything-0.9", "5141f54503d2e1cf39bd666c0ca5ab5eb78772ab", "2018-01-10" |
| 1619 |
), |
| 1620 |
git.GitTag( |
| 1621 |
"project-0.9.2", "1541f54503d2e1cf39bd777c0ca5ab5eb78772ba", "2017-11-11" |
| 1622 |
), |
| 1623 |
git.GitTag( |
| 1624 |
"ignored-0.9.1", "46e9032e18a819e466618c7a014bcb0e9981af9e", "2017-11-11" |
| 1625 |
), |
| 1626 |
] |
| 1627 |
|
| 1628 |
rules = changelog.TagRules( |
| 1629 |
scheme=Pep440, |
| 1630 |
tag_format="v$version", |
| 1631 |
legacy_tag_formats=["$version", "project-${version}"], |
| 1632 |
ignored_tag_formats=[ |
| 1633 |
"known", |
| 1634 |
"ignored-${version}", |
| 1635 |
"star-*", |
| 1636 |
"*-${major}.${minor}", |
| 1637 |
], |
| 1638 |
) |
| 1639 |
|
| 1640 |
version_tags = rules.get_version_tags(tags, warn=True) |
| 1641 |
assert {t.name for t in version_tags} == { |
| 1642 |
"v1.1.0", |
| 1643 |
"v1.0.0", |
| 1644 |
"1.0.0b2", |
| 1645 |
"project-0.9.3", |
| 1646 |
"project-0.9.2", |
| 1647 |
} |
| 1648 |
|
| 1649 |
captured = capsys.readouterr() |
| 1650 |
assert captured.err.count("Invalid version tag:") == 2 |
| 1651 |
assert captured.err.count("not-a-version") == 2 |
| 1652 |
|
| 1653 |
|
| 1654 |
@pytest.mark.usefixtures("in_repo_root") |
| 1655 |
def test_changelog_file_name_from_args_and_config(): |
| 1656 |
mock_config = Mock(spec=BaseConfig) |
| 1657 |
mock_path = Mock(spec=Path) |
| 1658 |
mock_path.parent = Path("/my/project") |
| 1659 |
mock_config.path = mock_path |
| 1660 |
mock_config.settings = { |
| 1661 |
"name": "cz_conventional_commits", |
| 1662 |
"changelog_file": "CHANGELOG.md", |
| 1663 |
"encoding": "utf-8", |
| 1664 |
"changelog_start_rev": "v1.0.0", |
| 1665 |
"tag_format": "$version", |
| 1666 |
"legacy_tag_formats": [], |
| 1667 |
"ignored_tag_formats": [], |
| 1668 |
"incremental": True, |
| 1669 |
"changelog_merge_prerelease": True, |
| 1670 |
} |
| 1671 |
|
| 1672 |
args = { |
| 1673 |
"file_name": "CUSTOM.md", |
| 1674 |
"unreleased_version": "1.0.1", |
| 1675 |
} |
| 1676 |
changelog = Changelog(mock_config, args) |
| 1677 |
assert ( |
| 1678 |
Path(changelog.file_name).resolve() == Path("/my/project/CUSTOM.md").resolve() |
| 1679 |
) |
| 1680 |
|
| 1681 |
args = {"unreleased_version": "1.0.1"} |
| 1682 |
changelog = Changelog(mock_config, args) |
| 1683 |
assert ( |
| 1684 |
Path(changelog.file_name).resolve() |
| 1685 |
== Path("/my/project/CHANGELOG.md").resolve() |
| 1686 |
) |