Skip to content

Ensure At Least One Blank Line Between Old and New Changelog Content #511

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
merged 6 commits into from
May 10, 2022

Conversation

Kurt-von-Laven
Copy link
Contributor

@Kurt-von-Laven Kurt-von-Laven commented May 4, 2022

Description

Ensure there is at least one blank line separating old and new content when appending incrementally to the changelog. Log entries for each release are already separated with blank lines, so separate pre-existing content from the first release with a blank line as well. If the pre-existing content ends with a blank line, then don't add an extra one.

I also fixed some unrelated pre-existing issues with .pre-commit-config.yaml in order to be able to comply with the contributing guidelines.

Please let me know which documentation I should update if you feel this change warrants mention. I wasn't sure whether to classify this as a tiny feature or a bug fix.

Closes #509.

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

Expected behavior

If the changelog already says "This changelog is auto-generated by the Python-based
Commitizen.", then when the first release is added by Commitizen, it doesn't ram right up against the pre-existing content.

Steps to Test This Pull Request

  1. Create CHANGELOG.md, and add some content to it that doesn't end in an extra blank line (besides the one at the end of the file).
  2. Make a feature commit.
  3. Run cz changelog --incremental.
  4. The changelog is updated with a note for the new feature appended to the bottom of the file. There is exactly one blank line between the pre-existing and new content.

Upgrade self-test hook from v1.23.0 to v2.24.0. The former version
crashes with the following error:

ImportError: cannot import name 'soft_unicode' from 'markupsafe'

Configure Commitizen to automatically bump the version of its own hook
that it uses.

Use the new location of the repository in the commitizen-tools org.
The existing regex had numerous bugs and boiled down to a very complex
way of matching any file whatsoever in the tests directory. Correct the
syntax issues, and make a best guess at the original intent.
Replace "script" with the current name of the directory, "scripts."
The original explanation has some minor grammatical errors.
- Specify what output_lines and lines are lists of, namely strings.
- Remove unnecessary test of whether latest_version_position is an int since
  x != None for any integer x.
- Replace two consecutive list.append calls with a single list.extend call.
Ensure there is at least one blank line separating old and new content.
We already separate the log entries for each release with blank lines,
so separate pre-existing content from the first release with a blank
line as well. If the pre-existing content ends in a blank line, then
don't add an extra one.
@codecov
Copy link

codecov bot commented May 4, 2022

Codecov Report

Merging #511 (7b69599) into master (8dcf97f) will increase coverage by 0.06%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #511      +/-   ##
==========================================
+ Coverage   97.85%   97.92%   +0.06%     
==========================================
  Files          39       39              
  Lines        1539     1540       +1     
==========================================
+ Hits         1506     1508       +2     
+ Misses         33       32       -1     
Flag Coverage Δ
unittests 97.92% <100.00%> (+0.06%) ⬆️

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

Impacted Files Coverage Δ
commitizen/changelog.py 97.26% <100.00%> (+0.56%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 354f9ea...7b69599. Read the comment docs.

@woile woile requested a review from Lee-W May 10, 2022 11:50
@woile woile merged commit dd4364e into commitizen-tools:master May 10, 2022
@Kurt-von-Laven Kurt-von-Laven deleted the changelog branch May 10, 2022 18:21
@@ -3,7 +3,8 @@ version = "2.24.0"
tag_format = "v$version"
version_files = [
"pyproject.toml:version",
"commitizen/__version__.py"
"commitizen/__version__.py",
".pre-commit-config.yaml:rev.\\s+(?=[^\\n]+Commitizen)"
Copy link
Member

Choose a reason for hiding this comment

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

This is neat!

@@ -270,16 +270,14 @@ def incremental_build(new_content: str, lines: List, metadata: Dict) -> List:
if skip:
continue

if (
isinstance(latest_version_position, int)
Copy link
Member

Choose a reason for hiding this comment

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

Wondering why this condition is removed

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.

Ensure At Least One Blank Line Above When Updating Changelog
3 participants