build: make commit validation accept typical Revert messages (#23480)
fixes #23479 PR Close #23480
This commit is contained in:
parent
b9431e88fb
commit
212b806eda
@ -22,18 +22,21 @@ const configPath = path.resolve(__dirname, './commit-message.json');
|
|||||||
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
||||||
const PATTERN = /^(\w+)(?:\(([^)]+)\))?\: (.+)$/;
|
const PATTERN = /^(\w+)(?:\(([^)]+)\))?\: (.+)$/;
|
||||||
const FIXUP_SQUASH = /^(fixup|squash)\! /i;
|
const FIXUP_SQUASH = /^(fixup|squash)\! /i;
|
||||||
const REVERT = /^revert:? (\"(.*)\"|(.*))?$/i;
|
const REVERT = /^revert:? /i;
|
||||||
|
|
||||||
module.exports = function(commitSubject) {
|
module.exports = function(commitSubject) {
|
||||||
commitSubject = commitSubject.replace(FIXUP_SQUASH, '');
|
const subject = commitSubject.replace(FIXUP_SQUASH, '');
|
||||||
commitSubject = commitSubject.replace(REVERT, function(m, g1, g2, g3) { return g2 || g3; });
|
|
||||||
|
|
||||||
if (commitSubject.length > config['maxLength']) {
|
if (subject.match(REVERT)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (subject.length > config['maxLength']) {
|
||||||
error(`The commit message is longer than ${config['maxLength']} characters`, commitSubject);
|
error(`The commit message is longer than ${config['maxLength']} characters`, commitSubject);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const match = PATTERN.exec(commitSubject);
|
const match = PATTERN.exec(subject);
|
||||||
if (!match) {
|
if (!match) {
|
||||||
error(
|
error(
|
||||||
`The commit message does not match the format of '<type>(<scope>): <subject>' OR 'Revert: "type(<scope>): <subject>"'`,
|
`The commit message does not match the format of '<type>(<scope>): <subject>' OR 'Revert: "type(<scope>): <subject>"'`,
|
||||||
|
@ -98,20 +98,26 @@ describe('validate-commit-message.js', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should support "revert: type(scope):" syntax and reject "revert(scope):" syntax',
|
it('should support "revert: type(scope):" syntax', function() {
|
||||||
function() {
|
const correctMsg = 'revert: fix(compiler): reduce generated code payload size by 65%';
|
||||||
let correctMsg = 'revert: fix(compiler): reduce generated code payload size by 65%';
|
expect(validateMessage(correctMsg)).toBe(VALID);
|
||||||
expect(validateMessage(correctMsg)).toBe(VALID);
|
});
|
||||||
|
|
||||||
let incorretMsg = 'revert(compiler): reduce generated code payload size by 65%';
|
it('should support reject "revert(scope):" syntax', function() {
|
||||||
expect(validateMessage(incorretMsg)).toBe(INVALID);
|
const incorretMsg = 'revert(compiler): reduce generated code payload size by 65%';
|
||||||
expect(errors).toEqual([
|
expect(validateMessage(incorretMsg)).toBe(INVALID);
|
||||||
'INVALID COMMIT MSG: "revert(compiler): reduce generated code payload size by 65%"\n' +
|
expect(errors).toEqual(
|
||||||
|
['INVALID COMMIT MSG: "revert(compiler): reduce generated code payload size by 65%"\n' +
|
||||||
' => ERROR: revert is not an allowed type.\n' +
|
' => ERROR: revert is not an allowed type.\n' +
|
||||||
' => TYPES: ' + TYPES
|
' => TYPES: ' + TYPES]);
|
||||||
]);
|
});
|
||||||
});
|
|
||||||
|
|
||||||
|
// https://github.com/angular/angular/issues/23479
|
||||||
|
it('should support typical Angular messages generated by git', function() {
|
||||||
|
const correctMsg =
|
||||||
|
'Revert "fix(compiler): Pretty print object instead of [Object object] (#22689)" (#23442)';
|
||||||
|
expect(validateMessage(correctMsg)).toBe(VALID);
|
||||||
|
});
|
||||||
|
|
||||||
it('should validate type', function() {
|
it('should validate type', function() {
|
||||||
expect(validateMessage('weird($filter): something')).toBe(INVALID);
|
expect(validateMessage('weird($filter): something')).toBe(INVALID);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user