Skip to content

Commit 3a66995

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

File tree

3 files changed

+11
-56
lines changed

3 files changed

+11
-56
lines changed

scripts/test-commit-messages.js

+8-45
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22

33
require('../lib/bootstrap-local');
44

5-
const fs = require('fs');
6-
const path = require('path');
75
const validateCommitMessage = require('./validate-commit-message');
86
const execSync = require('child_process').execSync;
97
const chalk = require('chalk');
108
const Logger = require('@ngtools/logger').Logger;
11-
const configPath = path.resolve(__dirname, './validate-commit-message/commit-message.json');
12-
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
139
require('rxjs/add/operator/filter');
1410

1511
// Configure logger
@@ -38,54 +34,21 @@ logger
3834
// Note: This is based on the gulp task found in the angular/angular repository
3935
execSync('git fetch origin');
4036

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 ')}`);
5637

57-
58-
const output = execSync('git log --format="%H %s" --no-merges', { encoding: 'utf-8' });
38+
const output = execSync('git log master.. --reverse --format="%H %s" --no-merges', {
39+
encoding: 'utf-8'
40+
});
5941

6042
if (output.length === 0) {
6143
logger.warn('There are zero new commits between this HEAD and master');
6244
process.exit(0);
6345
}
46+
const commitsByLine = output.trim().split(/\n/).map(line => {
47+
return line.trim().split(' ').slice(1).join(' ');
48+
});
49+
logger.info(`Examining ${commitsByLine.length} commit(s) between HEAD and master`);
6450

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));
51+
const someCommitsInvalid = !commitsByLine.every(message => validateCommitMessage(message));
8952

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

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

+2-6
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

+1-5
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)