Skip to content

Commit

Permalink
chore: Updating the prlinter (aws#22113)
Browse files Browse the repository at this point in the history
Adding the title check for all submitted PRs, not only the breaking change ones.


----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
Naumel authored and madeline-k committed Oct 10, 2022
1 parent 5941c33 commit 2806ca5
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions tools/@aws-cdk/prlint/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ function validateBreakingChangeFormat(title: string, body: string) {
}
}

/**
* Check that the PR title has the correct prefix.
*/
function validateTitlePrefix(title: string) {
const titleRe = /^(feat|fix|build|chore|ci|docs|style|refactor|perf|test)(\([\w-]+\)){0,1}: /;
if (!titleRe.exec(title)) {
throw new LinterError("❗️ The title of this PR must have the correct conventional prefix");
}
}

function assertStability(title: string, body: string) {
const breakingStable = breakingModules(title, body)
.filter(mod => 'stable' === moduleStability(findModulePath(mod)));
Expand All @@ -138,24 +148,24 @@ export async function validatePr(number: number) {
}

const gh = createGitHubClient();

const issues = gh.getIssues(OWNER, REPO);
const repo = gh.getRepo(OWNER, REPO);

console.log(`⌛ Fetching PR number ${number}`);
const issue = (await issues.getIssue(number)).data;

console.log(`⌛ Fetching files for PR number ${number}`);
const files = (await repo.listPullRequestFiles(number)).data;

console.log("⌛ Validating...");

if (shouldExemptReadme(issue)) {
console.log(`Not validating README changes since the PR is labeled with '${EXEMPT_README}'`);
} else {
featureContainsReadme(issue, files);
}

if (shouldExemptTest(issue)) {
console.log(`Not validating test changes since the PR is labeled with '${EXEMPT_TEST}'`);
} else {
Expand All @@ -168,14 +178,16 @@ export async function validatePr(number: number) {
} else {
featureContainsIntegTest(issue, files);
}

validateBreakingChangeFormat(issue.title, issue.body);
if (shouldExemptBreakingChange(issue)) {
console.log(`Not validating breaking changes since the PR is labeled with '${EXEMPT_BREAKING_CHANGE}'`);
} else {
assertStability(issue.title, issue.body);
}

validateTitlePrefix(issue.title);

console.log("✅ Success");
}

Expand Down

0 comments on commit 2806ca5

Please sign in to comment.