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
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/platform/azure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ export async function findPr({
);

if (prTitle) {
prsFiltered = prsFiltered.filter((item) => item.title === prTitle);
prsFiltered = prsFiltered.filter(
(item) => item.title.toLowerCase() === prTitle.toLowerCase()
);
}

switch (state) {
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/repository/updates/generate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ describe('workers/repository/updates/generate', () => {
...defaultConfig,
depName: 'some-dep',
prTitle: 'Upgrade {{depName}}',
toLowerCase: true,
semanticCommitCasing: true,
}),
];
const res = generateBranchConfig(branch);
Expand Down
17 changes: 11 additions & 6 deletions lib/workers/repository/updates/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export function generateBranchConfig(
)})`;
}
upgrade.commitMessagePrefix = CommitMessage.formatPrefix(semanticPrefix);
upgrade.toLowerCase =
upgrade.semanticCommitCasing =
regEx(/[A-Z]/).exec(upgrade.semanticCommitType) === null && // TODO #12071
!upgrade.semanticCommitType.startsWith(':');
}
Expand All @@ -181,10 +181,13 @@ export function generateBranchConfig(
regEx(/to vv(\d)/), // TODO #12071
'to v$1'
);
if (upgrade.toLowerCase) {
// We only need to lowercase the first line
if (upgrade.semanticCommitCasing) {
// We only need to lowercase the first word
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.

(match) => match.toLowerCase()
);
upgrade.commitMessage = splitMessage.join('\n');
}
if (upgrade.commitBody) {
Expand All @@ -205,8 +208,10 @@ export function generateBranchConfig(
if (upgrade.prTitle !== sanitize(upgrade.prTitle)) {
throw new Error(CONFIG_SECRETS_EXPOSED);
}
if (upgrade.toLowerCase) {
upgrade.prTitle = upgrade.prTitle.toLowerCase();
if (upgrade.semanticCommitCasing) {
upgrade.prTitle = upgrade.prTitle.replace(regEx(/^\w+/), (match) =>
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
match.toLowerCase()
);
}
} else {
[upgrade.prTitle] = upgrade.commitMessage.split('\n');
Expand Down