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:
parent
e6afcf1f94
commit
9bd4b74b06
|
@ -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 "<type>(<scope>): <subject>" format', () => {
|
||||
const msg = 'not correct format';
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue