Skip to content

Commit 9bd4b74

Browse files
devversionatscott
authored andcommitted
feat(dev-infra): commit message validation should skip lines consisting of URLs (angular#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 angular#37890
1 parent e6afcf1 commit 9bd4b74

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

dev-infra/commit-message/validate.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ describe('validate-commit-message.js', () => {
7777
config.commitMessage.maxLineLength} characters`);
7878
});
7979

80+
it('should skip max length limit for URLs', () => {
81+
const msg = 'fix(compiler): this is just an usual commit message tile\n\n' +
82+
'This is a normal commit message body which does not exceed the max length\n' +
83+
'limit. For more details see the following super long URL:\n\n' +
84+
'https://github.com/angular/components/commit/e2ace018ddfad10608e0e32932c43dcfef4095d7#diff-9879d6db96fd29134fc802214163b95a';
85+
86+
expect(validateCommitMessage(msg)).toBe(VALID);
87+
});
88+
8089
it('should validate "<type>(<scope>): <subject>" format', () => {
8190
const msg = 'not correct format';
8291

dev-infra/commit-message/validate.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const REVERT_PREFIX_RE = /^revert:? /i;
2222
const TYPE_SCOPE_RE = /^(\w+)(?:\(([^)]+)\))?\:\s(.+)$/;
2323
const COMMIT_HEADER_RE = /^(.*)/i;
2424
const COMMIT_BODY_RE = /^.*\n\n([\s\S]*)$/;
25+
const COMMIT_BODY_URL_LINE_RE = /^https?:\/\/.*$/;
2526

2627
/** Parse a full commit message into its composite parts. */
2728
export function parseCommitMessage(commitMsg: string) {
@@ -156,7 +157,13 @@ export function validateCommitMessage(
156157
}
157158

158159
const bodyByLine = commit.body.split('\n');
159-
if (bodyByLine.some(line => line.length > config.maxLineLength)) {
160+
const lineExceedsMaxLength = bodyByLine.some(line => {
161+
// Check if any line exceeds the max line length limit. The limit is ignored for
162+
// lines that just contain an URL (as these usually cannot be wrapped or shortened).
163+
return line.length > config.maxLineLength && !COMMIT_BODY_URL_LINE_RE.test(line);
164+
});
165+
166+
if (lineExceedsMaxLength) {
160167
printError(
161168
`The commit message body contains lines greater than ${config.maxLineLength} characters`);
162169
return false;

0 commit comments

Comments
 (0)