diff --git a/dev-infra/commit-message/validate.spec.ts b/dev-infra/commit-message/validate.spec.ts index ad1bf5b1e9..edc0bab802 100644 --- a/dev-infra/commit-message/validate.spec.ts +++ b/dev-infra/commit-message/validate.spec.ts @@ -77,6 +77,15 @@ describe('validate-commit-message.js', () => { config.commitMessage.maxLineLength} characters`); }); + it('should skip max length limit for URLs', () => { + const msg = 'fix(compiler): this is just an usual commit message tile\n\n' + + 'This is a normal commit message body which does not exceed the max length\n' + + 'limit. For more details see the following super long URL:\n\n' + + 'https://github.com/angular/components/commit/e2ace018ddfad10608e0e32932c43dcfef4095d7#diff-9879d6db96fd29134fc802214163b95a'; + + expect(validateCommitMessage(msg)).toBe(VALID); + }); + it('should validate "(): " format', () => { const msg = 'not correct format'; diff --git a/dev-infra/commit-message/validate.ts b/dev-infra/commit-message/validate.ts index a9b01f1c4d..7108a63cac 100644 --- a/dev-infra/commit-message/validate.ts +++ b/dev-infra/commit-message/validate.ts @@ -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;