diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-03-13 14:59:13 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-13 18:59:13 +0000 |
commit | b9d2ac32d54110636a3abd7863ed00af030fec84 (patch) | |
tree | 3107168e1c9a3071fbc9772a961d7781071dd1fa /tools/verify_pr_title.js | |
parent | 44b0d4cb11853bcdc7aa61c1412719a13d572b24 (diff) |
chore(ci): verify the PR title as part of linting (#18163)
This verifies the PR title as part of the lint step.
Diffstat (limited to 'tools/verify_pr_title.js')
-rw-r--r-- | tools/verify_pr_title.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tools/verify_pr_title.js b/tools/verify_pr_title.js new file mode 100644 index 000000000..be877bbfd --- /dev/null +++ b/tools/verify_pr_title.js @@ -0,0 +1,47 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +const prTitle = Deno.args[0]; + +if (prTitle == null) { + Deno.exit(0); // not a PR +} + +console.log("PR title:", prTitle); + +// This is a release PR, so it's valid. +if (/^[^\s]+\.[^\s]+\.[^\s]+$/.test(prTitle)) { + console.log("Valid."); + Deno.exit(0); +} + +const validPrefixes = [ + "chore", + "fix", + "feat", + "perf", + "ci", + "cleanup", + "docs", + "bench", + "build", + "refactor", + "test", + // allow Revert PRs because it allows us to remove the landed + // commit from the generated changelog + "Revert ", +]; + +if (validPrefixes.some((prefix) => prTitle.startsWith(prefix))) { + console.log("Valid."); +} else { + console.error( + "The PR title must start with one of the following prefixes:\n", + ); + for (const prefix of validPrefixes) { + console.error(` - ${prefix}`); + } + console.error( + "\nPlease fix the PR title according to https://www.conventionalcommits.org " + + "then push an empty commit to reset the CI.", + ); + Deno.exit(1); +} |