diff --git a/scripts/test-commit-messages.js b/scripts/test-commit-messages.js index a173e6105763..c888cf1fa9d3 100644 --- a/scripts/test-commit-messages.js +++ b/scripts/test-commit-messages.js @@ -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 @@ -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...'); diff --git a/scripts/validate-commit-message/commit-message.json b/scripts/validate-commit-message/commit-message.json index 9cbfdaa65fc3..9a73359ccf0d 100644 --- a/scripts/validate-commit-message/commit-message.json +++ b/scripts/validate-commit-message/commit-message.json @@ -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" - ] + } } diff --git a/scripts/validate-commit-message/validate-commit-message.js b/scripts/validate-commit-message/validate-commit-message.js index 0a341431dd84..2139064524ee 100644 --- a/scripts/validate-commit-message/validate-commit-message.js +++ b/scripts/validate-commit-message/validate-commit-message.js @@ -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; @@ -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));