Skip to content

Commit 10c9458

Browse files
authored
chore(prlint): enforce lowercase pr title (#29002)
Enforces that the title looks like `chore(prlint): enforce lowercase pr title` and not `chore(prlint): Enforce lowercase pr title`. Why does this matter? It doesn't really. But [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) tells us to be consistent, and their examples are all in lowercase, and most of our pr titles are already lowercase. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 5996856 commit 10c9458

File tree

2 files changed

+54
-18
lines changed

2 files changed

+54
-18
lines changed

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

+23-15
Original file line numberDiff line numberDiff line change
@@ -542,20 +542,6 @@ export class PullRequestLinter {
542542
testRuleSet: [{ test: featureContainsIntegTest }, { test: fixContainsIntegTest }],
543543
});
544544

545-
validationCollector.validateRuleSet({
546-
testRuleSet: [{ test: validateBreakingChangeFormat }],
547-
});
548-
549-
validationCollector.validateRuleSet({
550-
testRuleSet: [{ test: validateTitlePrefix }],
551-
});
552-
validationCollector.validateRuleSet({
553-
testRuleSet: [{ test: validateTitleScope }],
554-
});
555-
validationCollector.validateRuleSet({
556-
testRuleSet: [{ test: validateBranch }],
557-
})
558-
559545
validationCollector.validateRuleSet({
560546
exemption: shouldExemptBreakingChange,
561547
exemptionMessage: `Not validating breaking changes since the PR is labeled with '${Exemption.BREAKING_CHANGE}'`,
@@ -570,7 +556,17 @@ export class PullRequestLinter {
570556
validationCollector.validateRuleSet({
571557
exemption: (pr) => pr.user?.login === 'aws-cdk-automation',
572558
testRuleSet: [{ test: noMetadataChanges }],
573-
})
559+
});
560+
561+
validationCollector.validateRuleSet({
562+
testRuleSet: [
563+
{ test: validateBreakingChangeFormat },
564+
{ test: validateTitlePrefix },
565+
{ test: validateTitleScope },
566+
{ test: validateTitleLowercase },
567+
{ test: validateBranch },
568+
],
569+
});
574570

575571
await this.deletePRLinterComment();
576572
try {
@@ -735,6 +731,18 @@ function validateTitleScope(pr: GitHubPr): TestResult {
735731
return result;
736732
}
737733

734+
function validateTitleLowercase(pr: GitHubPr): TestResult {
735+
const result = new TestResult();
736+
const start = pr.title.indexOf(':');
737+
const firstLetter = pr.title.charAt(start + 2);
738+
console.log(firstLetter, firstLetter.toLocaleLowerCase());
739+
result.assessFailure(
740+
firstLetter !== firstLetter.toLocaleLowerCase(),
741+
'The first word of the pull request title should not be capitalized. If the title starts with a CDK construct, it should be in backticks "``".',
742+
);
743+
return result;
744+
}
745+
738746
/**
739747
* Check that the PR is not opened from main branch of author's fork
740748
*

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

+31-3
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,34 @@ describe('commit message format', () => {
197197
const prLinter = configureMock(issue, undefined);
198198
expect(await prLinter.validatePullRequestTarget(SHA)).resolves;
199199
});
200+
201+
test('invalid capitalized title', async () => {
202+
const issue = {
203+
number: 1,
204+
title: 'fix(aws-cdk-lib): Some title',
205+
body: '',
206+
labels: [{ name: 'pr-linter/exempt-test' }, { name: 'pr-linter/exempt-integ-test' }],
207+
user: {
208+
login: 'author',
209+
},
210+
};
211+
const prLinter = configureMock(issue, undefined);
212+
await expect(prLinter.validatePullRequestTarget(SHA)).rejects.toThrow(/The first word of the pull request title should not be capitalized. If the title starts with a CDK construct, it should be in backticks "``"/);
213+
});
214+
215+
test('valid capitalized title with backticks', async () => {
216+
const issue = {
217+
number: 1,
218+
title: 'fix(aws-cdk-lib): `CfnConstruct`',
219+
body: '',
220+
labels: [{ name: 'pr-linter/exempt-test' }, { name: 'pr-linter/exempt-integ-test' }],
221+
user: {
222+
login: 'author',
223+
},
224+
};
225+
const prLinter = configureMock(issue, undefined);
226+
expect(await prLinter.validatePullRequestTarget(SHA)).resolves;
227+
});
200228
});
201229

202230
describe('ban breaking changes in stable modules', () => {
@@ -1018,11 +1046,11 @@ describe('integration tests required on features', () => {
10181046

10191047
test('with aws-cdk-automation author', async () => {
10201048
const pr = {
1021-
title: 'chore: Update regions',
1049+
title: 'chore: update regions',
10221050
number: 1234,
10231051
labels: [],
10241052
user: {
1025-
login: 'aws-cdk-automation'
1053+
login: 'aws-cdk-automation',
10261054
},
10271055
};
10281056

@@ -1032,7 +1060,7 @@ describe('integration tests required on features', () => {
10321060

10331061
test('with another author', async () => {
10341062
const pr = {
1035-
title: 'chore: Update regions',
1063+
title: 'chore: update regions',
10361064
number: 1234,
10371065
labels: [],
10381066
user: {

0 commit comments

Comments
 (0)