Skip to content

Commit 809a7f0

Browse files
authored
chore(prlint): all prefixes must be lowercase + better failure message (#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*
1 parent 6409246 commit 809a7f0

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

tools/@aws-cdk/prlint/lint.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -401,11 +401,12 @@ function validateBreakingChangeFormat(pr: GitHubPr, _files: GitHubFile[]): TestR
401401
*/
402402
function validateTitlePrefix(pr: GitHubPr): TestResult {
403403
const result = new TestResult();
404-
const titleRe = /^(feat|fix|build|chore|ci|docs|style|refactor|perf|test|(r|R)evert)(\([\w_-]+\))?: /;
404+
const validTypes = "feat|fix|build|chore|ci|docs|style|refactor|perf|test|revert";
405+
const titleRe = new RegExp(`^(${validTypes})(\\([\\w_-]+\\))?: `);
405406
const m = titleRe.exec(pr.title);
406407
result.assessFailure(
407408
!m,
408-
'The title of this pull request does not follow the Conventional Commits format, see https://www.conventionalcommits.org/.');
409+
`The title prefix of this pull request must be one of "${validTypes}"`);
409410
return result;
410411
}
411412

tools/@aws-cdk/prlint/test/lint.test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,24 @@ describe('commit message format', () => {
219219
expect(legacyValidatePullRequestTarget(await prLinter)).resolves;
220220
});
221221

222+
test('invalid with capital letters in prefix', async () => {
223+
const issue = {
224+
number: 1,
225+
title: 'Revert(s3): some title',
226+
body: '',
227+
labels: [{ name: 'pr-linter/exempt-test' }, { name: 'pr-linter/exempt-integ-test' }],
228+
user: {
229+
login: 'author',
230+
},
231+
};
232+
const prLinter = configureMock(issue, undefined);
233+
await expect(prLinter.validatePullRequestTarget()).resolves.toEqual(expect.objectContaining({
234+
requestChanges: expect.objectContaining({
235+
failures: ['The title prefix of this pull request must be one of "feat|fix|build|chore|ci|docs|style|refactor|perf|test|revert"'],
236+
}),
237+
}));
238+
});
239+
222240
test('invalid capitalized title', async () => {
223241
const issue = {
224242
number: 1,

0 commit comments

Comments
 (0)