Skip to content

Commit 9cfc60c

Browse files
committed
ci: remove the branch check from the commit validation
1 parent 7f7bf70 commit 9cfc60c

File tree

3 files changed

+11
-52
lines changed

3 files changed

+11
-52
lines changed

scripts/test-commit-messages.js

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -38,54 +38,21 @@ logger
3838
// Note: This is based on the gulp task found in the angular/angular repository
3939
execSync('git fetch origin');
4040

41-
// Find the branch
42-
const branchRefs = {};
43-
for (const name of config['branches']) {
44-
try {
45-
const output = execSync(`git show-ref --hash ${name}`, { encoding: 'utf-8' });
46-
if (output) {
47-
branchRefs[name] = output.replace(/\n/g, '').trim();
48-
}
49-
} catch (e) {
50-
// Ignore.
51-
}
52-
}
53-
logger.info(`Found refs for branches:\n ${Object.keys(branchRefs).map(key => {
54-
return `${key} => ${JSON.stringify(branchRefs[key])}`;
55-
}).join('\n ')}`);
5641

57-
58-
const output = execSync('git log --format="%H %s" --no-merges', { encoding: 'utf-8' });
42+
const output = execSync('git log master.. --reverse --format="%H %s" --no-merges', {
43+
encoding: 'utf-8'
44+
});
5945

6046
if (output.length === 0) {
6147
logger.warn('There are zero new commits between this HEAD and master');
6248
process.exit(0);
6349
}
50+
const commitsByLine = output.trim().split(/\n/).map(line => {
51+
return line.trim().split(' ').slice(1).join(' ');
52+
});
53+
logger.info(`Examining ${commitsByLine.length} commit(s) between HEAD and master`);
6454

65-
const commitsByLine = [];
66-
let branch = null;
67-
68-
// Finding the closest branch marker.
69-
for (const line of output.split(/\n/)) {
70-
const [hash, ...messageArray] = line.split(' ');
71-
const message = messageArray.join(' ');
72-
73-
const maybeBranch = Object.keys(branchRefs).find(branchName => branchRefs[branchName] === hash);
74-
if (maybeBranch) {
75-
branch = maybeBranch;
76-
break;
77-
}
78-
commitsByLine.push(message);
79-
}
80-
81-
if (!branch) {
82-
logger.fatal('Something wrong happened.');
83-
process.exit(1);
84-
}
85-
86-
logger.info(`Examining ${commitsByLine.length} commit(s) between HEAD and ${branch}`);
87-
88-
const someCommitsInvalid = !commitsByLine.every(message => validateCommitMessage(message, branch));
55+
const someCommitsInvalid = !commitsByLine.every(message => validateCommitMessage(message));
8956

9057
if (someCommitsInvalid) {
9158
logger.error('Please fix the failing commit messages before continuing...');

scripts/validate-commit-message/commit-message.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,12 @@
44
"build": "",
55
"ci": "",
66
"docs": "",
7-
"feat": "origin/1.1.x",
7+
"feat": "",
88
"fix": "",
99
"perf": "",
1010
"refactor": "",
1111
"style": "",
1212
"test": "",
1313
"tool": ""
14-
},
15-
"branches": [
16-
"origin/master",
17-
"origin/1.1.x"
18-
]
14+
}
1915
}

scripts/validate-commit-message/validate-commit-message.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
2424
const { packages, tools } = require('../../lib/packages');
2525
const PATTERN = /^(revert\: )?(\w+)(?:\(([^)]+)\))?\: (.+)$/;
2626

27-
module.exports = function(commitSubject, branch) {
27+
module.exports = function(commitSubject) {
2828
if (commitSubject.length > config['maxLength']) {
2929
error(`The commit message is longer than ${config['maxLength']} characters`, commitSubject);
3030
return false;
@@ -43,10 +43,6 @@ module.exports = function(commitSubject, branch) {
4343
error(`"${type}" is not an allowed type.\n => TYPES: "${types.join('", "')}"`, commitSubject);
4444
return false;
4545
}
46-
if (config['types'][type] !== '' && config['types'][type] !== branch) {
47-
error(`${type} is not allowed to be on branch ${branch}.`, commitSubject);
48-
return false;
49-
}
5046

5147
const scope = match[3];
5248
const allScopes = Object.keys(packages).concat(Object.keys(tools));

0 commit comments

Comments
 (0)