build: autosquashes SHAs as part of merge-pr script (#21791)
To support `git checkin --fixup` and `git checkin —squash` we need to make sure that `merge-pr` squashes the sepecial commits before they are merged. For more details see: https://robots.thoughtbot.com/autosquashing-git-commits PR Close #21791
This commit is contained in:

committed by
Misko Hevery

parent
27ecd077d4
commit
637515e71b
@ -20,30 +20,35 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const configPath = path.resolve(__dirname, './commit-message.json');
|
||||
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
||||
const PATTERN = /^(revert\: )?(\w+)(?:\(([^)]+)\))?\: (.+)$/;
|
||||
const PATTERN = /^(\w+)(?:\(([^)]+)\))?\: (.+)$/;
|
||||
const FIXUP_SQUASH = /^(fixup|squash)\! /i;
|
||||
const REVERT = /^revert: (\"(.*)\"|(.*))?$/i;
|
||||
|
||||
module.exports = function(commitSubject) {
|
||||
commitSubject = commitSubject.replace(FIXUP_SQUASH, '');
|
||||
commitSubject = commitSubject.replace(REVERT, function(m, g1, g2, g3) { return g2 || g3; });
|
||||
|
||||
if (commitSubject.length > config['maxLength']) {
|
||||
error(`The commit message is longer than ${config['maxLength']} characters`, commitSubject);
|
||||
return false;
|
||||
}
|
||||
|
||||
const match = PATTERN.exec(commitSubject);
|
||||
if (!match || match[2] === 'revert') {
|
||||
if (!match) {
|
||||
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>"'`,
|
||||
commitSubject);
|
||||
return false;
|
||||
}
|
||||
|
||||
const type = match[2];
|
||||
const type = match[1];
|
||||
if (config['types'].indexOf(type) === -1) {
|
||||
error(
|
||||
`${type} is not an allowed type.\n => TYPES: ${config['types'].join(', ')}`, commitSubject);
|
||||
return false;
|
||||
}
|
||||
|
||||
const scope = match[3];
|
||||
const scope = match[2];
|
||||
|
||||
if (scope && !config['scopes'].includes(scope)) {
|
||||
error(
|
||||
|
Reference in New Issue
Block a user