Skip to content

ci: remove the branch check from the commit validation #6176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 8 additions & 45 deletions scripts/test-commit-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

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

const fs = require('fs');
const path = require('path');
const validateCommitMessage = require('./validate-commit-message');
const execSync = require('child_process').execSync;
const chalk = require('chalk');
const Logger = require('@ngtools/logger').Logger;
const configPath = path.resolve(__dirname, './validate-commit-message/commit-message.json');
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
require('rxjs/add/operator/filter');

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

// Find the branch
const branchRefs = {};
for (const name of config['branches']) {
try {
const output = execSync(`git show-ref --hash ${name}`, { encoding: 'utf-8' });
if (output) {
branchRefs[name] = output.replace(/\n/g, '').trim();
}
} catch (e) {
// Ignore.
}
}
logger.info(`Found refs for branches:\n ${Object.keys(branchRefs).map(key => {
return `${key} => ${JSON.stringify(branchRefs[key])}`;
}).join('\n ')}`);


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

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

const commitsByLine = [];
let branch = null;

// Finding the closest branch marker.
for (const line of output.split(/\n/)) {
const [hash, ...messageArray] = line.split(' ');
const message = messageArray.join(' ');

const maybeBranch = Object.keys(branchRefs).find(branchName => branchRefs[branchName] === hash);
if (maybeBranch) {
branch = maybeBranch;
break;
}
commitsByLine.push(message);
}

if (!branch) {
logger.fatal('Something wrong happened.');
process.exit(1);
}

logger.info(`Examining ${commitsByLine.length} commit(s) between HEAD and ${branch}`);

const someCommitsInvalid = !commitsByLine.every(message => validateCommitMessage(message, branch));
const someCommitsInvalid = !commitsByLine.every(message => validateCommitMessage(message));

if (someCommitsInvalid) {
logger.error('Please fix the failing commit messages before continuing...');
Expand Down
8 changes: 2 additions & 6 deletions scripts/validate-commit-message/commit-message.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@
"build": "",
"ci": "",
"docs": "",
"feat": "origin/1.1.x",
"feat": "",
"fix": "",
"perf": "",
"refactor": "",
"style": "",
"test": "",
"tool": ""
},
"branches": [
"origin/master",
"origin/1.1.x"
]
}
}
6 changes: 1 addition & 5 deletions scripts/validate-commit-message/validate-commit-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
const { packages, tools } = require('../../lib/packages');
const PATTERN = /^(revert\: )?(\w+)(?:\(([^)]+)\))?\: (.+)$/;

module.exports = function(commitSubject, branch) {
module.exports = function(commitSubject) {
if (commitSubject.length > config['maxLength']) {
error(`The commit message is longer than ${config['maxLength']} characters`, commitSubject);
return false;
Expand All @@ -43,10 +43,6 @@ module.exports = function(commitSubject, branch) {
error(`"${type}" is not an allowed type.\n => TYPES: "${types.join('", "')}"`, commitSubject);
return false;
}
if (config['types'][type] !== '' && config['types'][type] !== branch) {
error(`${type} is not allowed to be on branch ${branch}.`, commitSubject);
return false;
}

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