Skip to content

fix(commit_parser): strip DOS carriage-returns in commits #956

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

wyardley
Copy link
Contributor

@wyardley wyardley commented Jun 15, 2024

The default template can result in mixed (UNIX / DOS style) carriage returns in the generated changelog. Use a string replace in the commit parser to strip the DOS CRs ("\r"). While it's possible to do the replacement in the template, IMO, this is the better / correct way to fix it.

I checked, and seems like maybe it's only needed when we're not doing a byte decode (so the case where m is a raw string)? I can add it back to both if you'd like, though.

Fixes #955
Note: this may result in some diffs in generated changelogs.

See also #952

I'm happy to adjust existing tests in a way that would catch this and / or add a new test if someone can give me a general pointer on the best way / best place to do this. Also feel free to suggest a terser or more idiomatic way to do this.

@wyardley wyardley force-pushed the wyardley/issues/955/fix branch 3 times, most recently from bef4166 to b46a193 Compare June 15, 2024 15:03
@codejedi365 codejedi365 self-requested a review June 15, 2024 16:40
@codejedi365
Copy link
Contributor

I know this seems a bit like a crazy idea but maybe we don't strip the \r out but instead format the changelog with \r\n or windows style, because then it is always readable cross-platform. If we remove the \r then we restrict it only to Linux machines for reviewing the changelog and it does not work inheritly on windows. However the reverse will work on both.

Maybe this actually just bleeds into the code that handles the rendering rather than the content of the commit message. So it is likely your modification to remove them essentially is correct, then the during the writing of the file is when we apply the \r\n's.

@codejedi365 codejedi365 force-pushed the wyardley/issues/955/fix branch from 309ef0f to 35fb0f2 Compare June 17, 2024 06:12
@wyardley
Copy link
Contributor Author

I don’t think that’s necessary? The rest of the codebase and most of the generated changelog is already using regular UNIX style CRs and it doesn’t sound like that’s caused any issues for people?

@wyardley
Copy link
Contributor Author

Also, I think Python in normal cases will honor os.linesep when writing files, though in this case since we’re using Jinja, the behavior could be slightly different.

Either way, I think removing the mixed in ones should work for most. For sure IDEs and common text editors on Windows will render it fine, and I think other editors will as well, whereas with the \r\n you’ll see ^Ms in the file (as you do now in some lines on this project’s changelog).

btw, I don’t think these were introduced via commits on windows machines. I think maybe it’s how the strings are coming back from PyGithub, but could be wrong.

@codejedi365
Copy link
Contributor

I noticed that if someone uses the GitHub editor to make a commit that the commit message from the text area in the webUI will create commits with /r/n. That is more likely where those odd ones are coming from in our changelog.

Copy link
Contributor

@codejedi365 codejedi365 left a comment

Choose a reason for hiding this comment

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

I like the second way as stated above. Thanks for the effort

@wyardley
Copy link
Contributor Author

I like the second way as stated above. Thanks for the effort

Updated.

I noticed that if someone uses the GitHub editor to make a commit that the commit message from the text area in the webUI will create commits with /r/n.

Now this makes a lot of sense, and that's probably the reason.

@wyardley wyardley requested a review from codejedi365 June 17, 2024 18:58
@wyardley wyardley force-pushed the wyardley/issues/955/fix branch from 35fb0f2 to fbbd066 Compare June 17, 2024 19:00
The default template can result in mixed (UNIX / DOS style) carriage
returns in the generated changelog. Use a string replace in the commit
parser to strip the DOS CRs ("\r"). This is only needed in the case when
we are _not_ byte decoding.

Fixes python-semantic-release#955
@codejedi365 codejedi365 force-pushed the wyardley/issues/955/fix branch from fbbd066 to 75d5d30 Compare June 17, 2024 19:03
@codejedi365 codejedi365 merged commit 0b005df into python-semantic-release:master Jun 18, 2024
7 checks passed
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.

Inconsistent carriage returns in generated changelogs
2 participants