Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix: use only version tags in changelog #740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

sacha-c
Copy link
Contributor

@sacha-c sacha-c commented May 10, 2023

All tags used to generate the changelog must be version tags.
This PR fixes two issues:

  • The 'latest' commit was not being checked for it being a version tag, which can result in some non-version tag written as a header for the changelog
  • The rev-range created when running cz changelog 3.2.0 could use a non-version tag as a lower-bound, resulting in an incomplete changelog if the non-version tag was in the middle of two versions.

Description

Changelogs should be generated only with version tags as headers. Tags are indeed being checked that they are version tags when generating the changelog here, but this logic is missing for the latest commit's tag.

This means that changelogs can be generated with an incorrect tag for the latest version

For example, if I have a project with a commit "feat: some change" tagged with a tag "i_am_not_a_version", running cz changelog will generate something like:
See that the output is

## i_am_not_a_version (2023-05-10)

### Feat

- some change

instead of

## Unreleased
...

or

## 0.1.0 (2023-05-10)
...

Checklist

  • Add test cases to all the changes you introduce
  • Run ./scripts/format and ./scripts/test locally to ensure this change passes linter check and test
  • Test the changes on the local machine manually
  • Update the documentation for the changes (not relevant)

Expected behavior

The changelog should only contain version tags

Steps to Test This Pull Request

On a project with commitizen setup

  1. touch some-change
  2. git commit -m "feat: some change"
  3. git tag a-tag-that-has-nothing-to-do-with-versions
  4. cz changelog --dry-run

closes #741

@codecov
Copy link

codecov bot commented May 10, 2023

Codecov Report

Patch coverage: 98.59% and project coverage change: +0.10 🎉

Comparison is base (eb39f8b) 97.31% compared to head (b28670a) 97.41%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #740      +/-   ##
==========================================
+ Coverage   97.31%   97.41%   +0.10%     
==========================================
  Files          42       42              
  Lines        2045     2086      +41     
==========================================
+ Hits         1990     2032      +42     
+ Misses         55       54       -1     
Flag Coverage Δ
unittests 97.41% <98.59%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...en/cz/conventional_commits/conventional_commits.py 100.00% <ø> (ø)
commitizen/providers.py 97.47% <88.88%> (+0.18%) ⬆️
commitizen/commands/bump.py 97.63% <96.55%> (-0.52%) ⬇️
commitizen/version_schemes.py 98.42% <98.42%> (ø)
commitizen/__version__.py 100.00% <100.00%> (ø)
commitizen/bump.py 100.00% <100.00%> (ø)
commitizen/changelog.py 99.49% <100.00%> (-0.51%) ⬇️
commitizen/changelog_parser.py 96.96% <100.00%> (+0.04%) ⬆️
commitizen/cli.py 94.20% <100.00%> (ø)
commitizen/commands/changelog.py 98.92% <100.00%> (-0.03%) ⬇️
... and 14 more

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@sacha-c sacha-c marked this pull request as draft May 16, 2023 15:04
@sacha-c sacha-c force-pushed the fix/changelog-only-version-tags branch 6 times, most recently from c349d86 to 5cd12cb Compare May 17, 2023 10:53
@sacha-c
Copy link
Contributor Author

sacha-c commented May 17, 2023

My PR is not passing coverage/patch because my changes include code that is run conditionally based on the OS (if os.name == 'nt)

My code is actually covered through tests, but it doesn't end up in coverage.xml because codecov only uses coverage.xml generated from linux runs:

- name: Upload coverage to Codecov
if: runner.os == 'Linux'

Any suggestion on how to proceed?

EDIT: added pragma: no cov

@sacha-c sacha-c force-pushed the fix/changelog-only-version-tags branch 2 times, most recently from eae6463 to 4fd3439 Compare June 12, 2023 06:53
@sacha-c sacha-c marked this pull request as ready for review June 12, 2023 07:16
@Lee-W
Copy link
Member

Lee-W commented Jun 23, 2023

Hi @sacha-c sorry for the late reply. Both maintainers are a bit overwhelmed these days. I've verified this issue and am now going to take a deeper look at this PR. Thanks for your contribution!

This commit ensures that the tags used to generate the changelog are all correctly parsed by Version()
This fixes two bugs:
- The header of the changelog could be a non-version tag
- The rev-range computed when running  could use a non-version tag as a lower bound
@Lee-W Lee-W force-pushed the fix/changelog-only-version-tags branch from 4fd3439 to 87df201 Compare June 23, 2023 10:53
@Lee-W Lee-W requested a review from woile June 23, 2023 11:02
@Lee-W
Copy link
Member

Lee-W commented Jun 23, 2023

Hi @sacha-c , I tried to resolve the conflict due to the latest merged PRs, but it seems to fail on the windows instance. Could you please take a look at the windows issue? I think we're almost ready to merge this one 💪

@sacha-c
Copy link
Contributor Author

sacha-c commented Jun 23, 2023

Hi @sacha-c , I tried to resolve the conflict due to the latest merged PRs, but it seems to fail on the windows instance. Could you please take a look at the windows issue? I think we're almost ready to merge this one 💪

Thanks for checking this issue! 🙂

I had a look at the error and at first glance it seems unrelated to the changes of this PR. The test failing is test_bump_pre_commit_changelog, and the exception is thrown when installing pre-commit
* Install prebuilt node (20.3.1) .Failed to download from https://nodejs.org/download/release/v20.3.1/node-v20.3.1-win-x64.zip
Is there a way to re-run the test suite and see if that fixes it?

@Lee-W
Copy link
Member

Lee-W commented Jun 23, 2023

Yep, you're right. After I reran it, it succeeded. 🙂

Copy link
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix looks good to me.

@woile I'm planning to merge it this weekend. Let me know if you want to take a deeper look 🙂

commitizen/changelog.py Outdated Show resolved Hide resolved
commitizen/changelog.py Outdated Show resolved Hide resolved
@Lee-W Lee-W added pr-status: ready-to-merge almost ready to merge. just keep it for a few days for others to check type: bug and removed os: Windows pr-status: wait-for-modification labels Jun 23, 2023
@Lee-W Lee-W merged commit 26a7d32 into commitizen-tools:master Jun 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-status: ready-to-merge almost ready to merge. just keep it for a few days for others to check type: bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Changelog can be generated with non-version tags as a header
3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.