Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading