Skip to content

fix: changelog release commit search logic - #530

Merged
bernardcooke53 merged 2 commits into
python-semantic-release:masterfrom
css-optivoy:patch-1
Jan 15, 2023
Merged

bernardcooke53 merged 2 commits into
python-semantic-release:masterfrom
css-optivoy:patch-1

Conversation

@css-optivoy

@css-optivoy css-optivoy commented Nov 17, 2022 •

Copy link
Copy Markdown
Contributor

Running semantic-release changelog currently fails to identify "the last commit in [a] release" because the compared commit messages have superfluous whitespace. (Likely related to the issue causing #490)

The logic to iterate through the commits, to identify the boundary between the two versions, fails to identify the release commit message generated by semantic-release, and skips all the commits.
This ultimately results in no commits being printed as part of the changelog.

Fixes:

I have a log looking like this:

$ git log --oneline
a501da0 (HEAD -> main, tag: 0.2.0-dev.4, origin/main) 0.2.0-dev.4
812e796 Merge pull request #41 from [...]
8ccc600 (origin/todo) refactor: [...]
e06c3b4 Merge pull request #40 from [...]
94a4d35 (origin/v) refactor: Remove verbose.
302254d [...]
07846a6 ci(semrel): [...]
0b9560c 0.2.0-dev.3
ac25e8d (tag: 0.2.0-dev.3) Merge pull request #39 from ...

But running changelog fails to find the three changes labelled with 'ci' and 'refactor':

$ semantic-release changelog -D changelog_sections="refactor,ci"
[nothing here]

After the PR I get the expected output:

$ semantic-release changelog -D changelog_sections="refactor,ci"
### Refactor
* [...] ([`8ccc600`](https://github.com/...))
* [...] ([`94a4d35`](https://github.com/...))

### Ci
* **semrel:** [...] ([`07846a6`](https://github.com/...))

Running `semantic-release changelog` currently fails to identify "the last commit in [a] release" because the compared commit messages have superfluous whitespace.
Likely related to the issue causing: python-semantic-release#490
@bernardcooke53

Copy link
Copy Markdown
Contributor

Just checking my understanding - you're saying 0b9560c isn't identified as from_version_commit because of its newline?

Is there a chance you could post the output of semantic-release -version DEBUG -D "changelog_sections=ci,refactor" please?

@css-optivoy

css-optivoy commented Nov 18, 2022 •

Copy link
Copy Markdown
Contributor Author

Just checking my understanding - you're saying 0b9560c isn't identified as from_version_commit because of its newline?

The other way around. a501da0 isn't recognised by the logic at:

# Skip until we find the last commit in this release
# (we are looping in the order of newest -> oldest)
if to_version_commit and commit_message != to_version_commit:
continue

Which is what is causing it to skip past all the commit in the entire range.

I tried dumping the contents of commit_message and to_version_commit, and the former had an extra newline at the end.
Much like what seems to have been the case down here:

# See https://github.com/relekang/python-semantic-release/issues/490 -
# commit messages (which we compare with ==) have a trailing newline
if (
from_version_commit
and commit_message.strip() == from_version_commit.strip()
):

Is there a chance you could post the output of semantic-release -version DEBUG -D "changelog_sections=ci,refactor" please?

Without the patch:

$ semantic-release changelog -v DEBUG -D changelog_sections="refactor,ci"
debug: get_current_version_by_config_file()
debug: Regex matched version: 0.2.0-dev.4
debug: get_current_version_by_config_file -> 0.2.0-dev.4
debug: get_previous_version(0.2.0-dev.4)
debug: Checking commit a501da0...
debug: Found version in commit "0.2.0-dev.4
debug: 
debug: Automatically generated by python-semantic-release
debug: "
debug: Checking commit 812e796...
debug: Checking commit 8ccc600...
debug: Checking commit e06c3b4...
debug: Checking commit 94a4d35...
debug: Checking commit 302254d...
debug: Checking commit 07846a6...
debug: Checking commit 0b9560c...
debug: Version matches regex 0.2.0-dev.3
debug: 
debug: Automatically generated by python-semantic-release
debug: get_previous_version -> 0.2.0-dev.3
debug: generate_changelog('0.2.0-dev.3', 0.2.0-dev.4)
debug: generate_changelog -> {'breaking': []}
debug: get_repository_owner_and_name()
debug: get_repository_owner_and_name -> ('[...]', '[...]')
debug: markdown_changelog('[...]', '[...]', 0.2.0-dev.4, {'breaking': []}, header=False)
debug: markdown_changelog -> 

(Note how a501da0 has a newline at the end of the commit message, which is what we're stripping with this change.)

With:

debug: get_current_version_by_config_file()
debug: Regex matched version: 0.2.0-dev.4
debug: get_current_version_by_config_file -> 0.2.0-dev.4
debug: get_previous_version(0.2.0-dev.4)
debug: Checking commit a501da0...
debug: Found version in commit "0.2.0-dev.4
debug: 
debug: Automatically generated by python-semantic-release
debug: "
debug: Checking commit 812e796...
debug: Checking commit 8ccc600...
debug: Checking commit e06c3b4...
debug: Checking commit 94a4d35...
debug: Checking commit 302254d...
debug: Checking commit 07846a6...
debug: Checking commit 0b9560c...
debug: Version matches regex 0.2.0-dev.3
debug: 
debug: Automatically generated by python-semantic-release
debug: get_previous_version -> 0.2.0-dev.3
debug: generate_changelog('0.2.0-dev.3', 0.2.0-dev.4)
debug: Reached the start of 0.2.0-dev.4, beginning changelog generation
debug: parse_commit_message('0.2.0-dev.4
debug: 
debug: Automatically generated by python-semantic-release')
debug: Ignoring UnknownCommitMessageStyleError: Unable to parse the given commit message: 0.2.0-dev.4
debug: 
debug: Automatically generated by python-semantic-release
debug: parse_commit_message('Merge pull request #41 from [...]')
debug: Ignoring UnknownCommitMessageStyleError: Unable to parse the given commit message: Merge pull request #41 from [...]
debug: parse_commit_message('refactor: [...]')
debug: parse_commit_message -> ParsedCommit(bump=0, type='refactor', scope=None, descriptions=['...'], breaking_descriptions=[])
debug: Creating new changelog section for refactor 
debug: parse_commit_message('Merge pull request #40 from [...]')
debug: Ignoring UnknownCommitMessageStyleError: Unable to parse the given commit message: Merge pull request #40 from [...]
debug: parse_commit_message('refactor: [...]')
debug: parse_commit_message -> ParsedCommit(bump=0, type='refactor', scope=None, descriptions=['...'], breaking_descriptions=[])
debug: parse_commit_message('[...]')
debug: Ignoring UnknownCommitMessageStyleError: Unable to parse the given commit message: Typo.
debug: parse_commit_message('ci(semrel): [...]')
debug: parse_commit_message -> ParsedCommit(bump=0, type='ci', scope='semrel', descriptions=['[...]'], breaking_descriptions=[])
debug: Creating new changelog section for ci 
debug: 0.2.0-dev.3 reached, ending changelog generation
debug: generate_changelog -> {'breaking': [], 'refactor': [('8ccc600...', '[...]'), ('94a4d35...', '[...]')], 'ci': [('07846a6...', '**semrel:** [...]')]}
debug: get_repository_owner_and_name()
debug: get_repository_owner_and_name -> ('[...]', '[...]')
debug: markdown_changelog('[...]', '[...]', 0.2.0-dev.4, {'breaking': [], 'refactor': [('8ccc600...', '[...]'), ('94a4d35...', '[...]')], 'ci': [('07846a6...', '**semrel:** [...]')]}, header=False)
debug: markdown_changelog -> ### Refactor
debug: * [...] ([`8ccc600`](https://github.com/...))
debug: * [...] ([`94a4d35`](https://github.com/...))
debug: 
debug: ### Ci
debug: * **semrel:** [...] ([`07846a6`](https://github.com/...))
[...]

@css-optivoy

Copy link
Copy Markdown
Contributor Author

Is there anything else I can do to help this review along?

@css-optivoy

Copy link
Copy Markdown
Contributor Author

@relekang perhaps you can weigh in? Or tap someone else to do so?

This is affecting our whole dev setup, so it'd be nice to have a rough ETA on when this will be looked at.
Thanks in advance.

@bernardcooke53 bernardcooke53 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for finding this @css-optivoy 👍

@bernardcooke53 bernardcooke53 changed the title Fixes changelog release commit search logic fix: changelog release commit search logic Jan 15, 2023
@bernardcooke53
bernardcooke53 merged commit efb3410 into python-semantic-release:master Jan 15, 2023
kibidev pushed a commit to kibidev/python-semantic-release that referenced this pull request Feb 1, 2023
* Fixes changelog release commit search logic

Running `semantic-release changelog` currently fails to identify "the last commit in [a] release" because the compared commit messages have superfluous whitespace.
Likely related to the issue causing: python-semantic-release#490

* Removes a couple of extra `strip()`s.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants