Skip to content

Commit 6409246

Browse files
authored
chore(prlint): ensure scope is lowercase (#33103)
PR linter now checks for lowercase scope. Valid: `fix(s3): blah` Invalid: `fix(S3): blah` ### 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 b77e937 commit 6409246

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ function validateTitlePrefix(pr: GitHubPr): TestResult {
410410
}
411411

412412
/**
413-
* Check that the PR title uses the typical convention for package names.
413+
* Check that the PR title uses the typical convention for package names, and is lowercase.
414414
*
415415
* For example, "fix(s3)" is preferred over "fix(aws-s3)".
416416
*/
@@ -427,7 +427,17 @@ function validateTitleScope(pr: GitHubPr): TestResult {
427427
if (m && !scopesExemptFromThisRule.includes(m[2])) {
428428
result.assessFailure(
429429
!!(m[2] && m[3]),
430-
`The title of the pull request should omit 'aws-' from the name of modified packages. Use '${m[3]}' instead of '${m[2]}'.`,
430+
`The title scope of the pull request should omit 'aws-' from the name of modified packages. Use '${m[3]}' instead of '${m[2]}'.`,
431+
);
432+
}
433+
434+
// Title scope is lowercase
435+
const scopeRe = /^\w+\(([\w_-]+)\)?: /; // Isolate the scope
436+
const scope = scopeRe.exec(pr.title);
437+
if (scope && scope[1]) {
438+
result.assessFailure(
439+
scope[1] !== scope[1].toLocaleLowerCase(),
440+
`The title scope of the pull request should be entirely in lowercase. Use '${scope[1].toLocaleLowerCase()}' instead.`,
431441
);
432442
}
433443
return result;

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,25 @@ describe('commit message format', () => {
142142
},
143143
};
144144
const prLinter = configureMock(issue, undefined);
145-
await expect(legacyValidatePullRequestTarget(prLinter)).rejects.toThrow(/The title of the pull request should omit 'aws-' from the name of modified packages. Use 's3' instead of 'aws-s3'./);
145+
await expect(legacyValidatePullRequestTarget(prLinter)).rejects.toThrow(/The title scope of the pull request should omit 'aws-' from the name of modified packages. Use 's3' instead of 'aws-s3'./);
146+
});
147+
148+
test('invalid scope with capital letters', async () => {
149+
const issue = {
150+
number: 1,
151+
title: 'fix(S3): some title',
152+
body: '',
153+
labels: [{ name: 'pr-linter/exempt-test' }, { name: 'pr-linter/exempt-integ-test' }],
154+
user: {
155+
login: 'author',
156+
},
157+
};
158+
const prLinter = configureMock(issue, undefined);
159+
await expect(prLinter.validatePullRequestTarget()).resolves.toEqual(expect.objectContaining({
160+
requestChanges: expect.objectContaining({
161+
failures: ["The title scope of the pull request should be entirely in lowercase. Use 's3' instead."],
162+
}),
163+
}));
146164
});
147165

148166
test('valid scope with aws- in summary and body', async () => {

0 commit comments

Comments
 (0)