Skip to content
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

fix: lowercase first word of commit message #12440

Closed
wants to merge 6 commits into from
Closed

fix: lowercase first word of commit message #12440

wants to merge 6 commits into from

Conversation

RahulGautamSingh
Copy link
Collaborator

Changes:

Updated code so that only first word of commit messages and prTitle is lowercased instead of the whole message.

Context:

Closes #12062

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please tick one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added/modified unit tests, or
  • No unit tests but ran on a real repository, or
  • Both unit tests + ran on a real repository

@RahulGautamSingh RahulGautamSingh changed the title Fix/lowercase first word of commit msg fix: lowercase first word of commit msg Nov 2, 2021
@RahulGautamSingh RahulGautamSingh changed the title fix: lowercase first word of commit msg fix : lowercase first word of commit msg Nov 2, 2021
@RahulGautamSingh RahulGautamSingh changed the title fix : lowercase first word of commit msg fix: lowercase first word of commit message Nov 2, 2021
Copy link
Collaborator

@rarkins rarkins left a comment

Choose a reason for hiding this comment

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

Needs more tests added. I think you'll find it doesn't work as expected. e.g. we should test:

fix: Upgrade something, fix(docs): Something else, Really great feature: Foo, etc.

const splitMessage = upgrade.commitMessage.split('\n');
splitMessage[0] = splitMessage[0].toLowerCase();
splitMessage[0] = splitMessage[0].replace(
splitMessage[0].includes(':') ? regEx(/: \w+/) : regEx(/^\w+/),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure this is accurate enough

Copy link
Member

Choose a reason for hiding this comment

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

I think this should be done in commit message builder.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

str = str.replace(
        str.includes(':') ? /.*: \w+/ : /^\w+/,
        (match) => match.toLowerCase()
      );

This snippet works fine for the all the cases except Really great feature: Foo, for this type of message it lowercases the whole string which is a problem. Isn't such a commit message valid, cause it violates the good-commit-message rules?

Regarding the accuracy of the regex, we are only targeting the sub-string we want to lowercase

  1. /.*: \w/ -> It will look for a semi-colon and a word after it (i.e first word of message)
    -Eg. fix: Upgrade something for this our match is fix: Upgrade
  2. /^\w/ -> It matches first word of the message.
    -Eg. Upgrade Something Please -> It matches Upgrade.

Also I was wondering what would be the updated commit message for Really great feature: Foo

  1. really great feature: Foo or,
  2. really great feature: foo

Copy link
Member

Choose a reason for hiding this comment

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

i still suggest to move the whole logic to this file:

https://github.com/renovatebot/renovate/blob/5af1b77f6919b554b3170c2465094a1442eb0221/lib/workers/repository/model/commit-message.ts#L1-L55

As we build the message there, so it should be more easily to fix it there for all

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@viceice I am not sure where the changes need to be updated in the new file, could you please guide me by commenting on the file where the certain functionalities needs to be added.

Copy link
Contributor

Choose a reason for hiding this comment

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

@RahulGautamSingh I guess in general would be nice if BranchUpgradeConfig interface will have instance of CommitMessage class. Therefore need to refactor lib/workers/repository/updates/generate.ts to using this class. During this refactoring maybe will be required extend functionality of CommitMessage or create inherited class for specific purposes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the help @pret-a-porter . Seems that I need to go through the code and refactor it. I am closing this PR for now and will create a new one when I have updated the code.

Hey @rarkins ,once you give the above suggestion by @pret-a-porter a 👍 I will start my work.

lib/workers/repository/updates/generate.ts Show resolved Hide resolved
@rarkins rarkins marked this pull request as draft November 5, 2021 07:03
@RahulGautamSingh RahulGautamSingh marked this pull request as ready for review November 8, 2021 04:02
@RahulGautamSingh RahulGautamSingh marked this pull request as draft November 8, 2021 04:27
@RahulGautamSingh RahulGautamSingh deleted the fix/lowercase-first-word-of-commit-msg branch November 8, 2021 05:40
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Commit messages should not be fully lowercased
4 participants