Skip to content

Commit

Permalink
chore(prlint): all prefixes must be lowercase + better failure message (
Browse files Browse the repository at this point in the history
#33102)

Updates the PR linter to remove `Revert` as a valid title prefix, in favor of `revert`. To be fair, this is a stylistic change, but I think its unclean to have every other valid prefix as lowercase except for `Revert`. The reason is because github automatically titles revert PRs with `Revert`, but I don't think it's much effort for engineers to update the title so it fits in the style with everything else.

In addition, I've updated the failure message to make it clear what it's looking for, rather than a link to conventionalcommits.

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
kaizencc authored Jan 23, 2025
1 parent 6409246 commit 809a7f0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tools/@aws-cdk/prlint/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,12 @@ function validateBreakingChangeFormat(pr: GitHubPr, _files: GitHubFile[]): TestR
*/
function validateTitlePrefix(pr: GitHubPr): TestResult {
const result = new TestResult();
const titleRe = /^(feat|fix|build|chore|ci|docs|style|refactor|perf|test|(r|R)evert)(\([\w_-]+\))?: /;
const validTypes = "feat|fix|build|chore|ci|docs|style|refactor|perf|test|revert";
const titleRe = new RegExp(`^(${validTypes})(\\([\\w_-]+\\))?: `);
const m = titleRe.exec(pr.title);
result.assessFailure(
!m,
'The title of this pull request does not follow the Conventional Commits format, see https://www.conventionalcommits.org/.');
`The title prefix of this pull request must be one of "${validTypes}"`);
return result;
}

Expand Down
18 changes: 18 additions & 0 deletions tools/@aws-cdk/prlint/test/lint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,24 @@ describe('commit message format', () => {
expect(legacyValidatePullRequestTarget(await prLinter)).resolves;
});

test('invalid with capital letters in prefix', async () => {
const issue = {
number: 1,
title: 'Revert(s3): some title',
body: '',
labels: [{ name: 'pr-linter/exempt-test' }, { name: 'pr-linter/exempt-integ-test' }],
user: {
login: 'author',
},
};
const prLinter = configureMock(issue, undefined);
await expect(prLinter.validatePullRequestTarget()).resolves.toEqual(expect.objectContaining({
requestChanges: expect.objectContaining({
failures: ['The title prefix of this pull request must be one of "feat|fix|build|chore|ci|docs|style|refactor|perf|test|revert"'],
}),
}));
});

test('invalid capitalized title', async () => {
const issue = {
number: 1,
Expand Down

0 comments on commit 809a7f0

Please sign in to comment.