feat(dev-infra): commit message validation should skip lines consisting of URLs (#37890)

The dev-infra commit message validation optionally can check for lines
to not exceed a given amount of characters. This is desired for most
commit messages, but sometimes not actionable if a long URL is inserted
into the commit message. With this commit, we skip the max line length
check for lines that start with an URL.

PR Close #37890
This commit is contained in:
Paul Gschwendtner
2020-07-07 15:58:11 +02:00
committed by Andrew Scott
parent e6afcf1f94
commit 9bd4b74b06
2 changed files with 17 additions and 1 deletions

View File

@ -22,6 +22,7 @@ const REVERT_PREFIX_RE = /^revert:? /i;
const TYPE_SCOPE_RE = /^(\w+)(?:\(([^)]+)\))?\:\s(.+)$/;
const COMMIT_HEADER_RE = /^(.*)/i;
const COMMIT_BODY_RE = /^.*\n\n([\s\S]*)$/;
const COMMIT_BODY_URL_LINE_RE = /^https?:\/\/.*$/;
/** Parse a full commit message into its composite parts. */
export function parseCommitMessage(commitMsg: string) {
@ -156,7 +157,13 @@ export function validateCommitMessage(
}
const bodyByLine = commit.body.split('\n');
if (bodyByLine.some(line => line.length > config.maxLineLength)) {
const lineExceedsMaxLength = bodyByLine.some(line => {
// Check if any line exceeds the max line length limit. The limit is ignored for
// lines that just contain an URL (as these usually cannot be wrapped or shortened).
return line.length > config.maxLineLength && !COMMIT_BODY_URL_LINE_RE.test(line);
});
if (lineExceedsMaxLength) {
printError(
`The commit message body contains lines greater than ${config.maxLineLength} characters`);
return false;