Skip to content

Commit

Permalink
chore(prlint): ensure scope is lowercase (#33103)
Browse files Browse the repository at this point in the history
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*
  • Loading branch information
kaizencc authored Jan 23, 2025
1 parent b77e937 commit 6409246
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
14 changes: 12 additions & 2 deletions tools/@aws-cdk/prlint/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ function validateTitlePrefix(pr: GitHubPr): TestResult {
}

/**
* Check that the PR title uses the typical convention for package names.
* Check that the PR title uses the typical convention for package names, and is lowercase.
*
* For example, "fix(s3)" is preferred over "fix(aws-s3)".
*/
Expand All @@ -427,7 +427,17 @@ function validateTitleScope(pr: GitHubPr): TestResult {
if (m && !scopesExemptFromThisRule.includes(m[2])) {
result.assessFailure(
!!(m[2] && m[3]),
`The title of the pull request should omit 'aws-' from the name of modified packages. Use '${m[3]}' instead of '${m[2]}'.`,
`The title scope of the pull request should omit 'aws-' from the name of modified packages. Use '${m[3]}' instead of '${m[2]}'.`,
);
}

// Title scope is lowercase
const scopeRe = /^\w+\(([\w_-]+)\)?: /; // Isolate the scope
const scope = scopeRe.exec(pr.title);
if (scope && scope[1]) {
result.assessFailure(
scope[1] !== scope[1].toLocaleLowerCase(),
`The title scope of the pull request should be entirely in lowercase. Use '${scope[1].toLocaleLowerCase()}' instead.`,
);
}
return result;
Expand Down
20 changes: 19 additions & 1 deletion tools/@aws-cdk/prlint/test/lint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,25 @@ describe('commit message format', () => {
},
};
const prLinter = configureMock(issue, undefined);
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'./);
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'./);
});

test('invalid scope with capital letters', async () => {
const issue = {
number: 1,
title: 'fix(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 scope of the pull request should be entirely in lowercase. Use 's3' instead."],
}),
}));
});

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

0 comments on commit 6409246

Please sign in to comment.