|
2 | 2 |
|
3 | 3 | require('../lib/bootstrap-local');
|
4 | 4 |
|
5 |
| -const fs = require('fs'); |
6 |
| -const path = require('path'); |
7 | 5 | const validateCommitMessage = require('./validate-commit-message');
|
8 | 6 | const execSync = require('child_process').execSync;
|
9 | 7 | const chalk = require('chalk');
|
10 | 8 | 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')); |
13 | 9 | require('rxjs/add/operator/filter');
|
14 | 10 |
|
15 | 11 | // Configure logger
|
@@ -38,54 +34,21 @@ logger
|
38 | 34 | // Note: This is based on the gulp task found in the angular/angular repository
|
39 | 35 | execSync('git fetch origin');
|
40 | 36 |
|
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 ')}`); |
56 | 37 |
|
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 | +}); |
59 | 41 |
|
60 | 42 | if (output.length === 0) {
|
61 | 43 | logger.warn('There are zero new commits between this HEAD and master');
|
62 | 44 | process.exit(0);
|
63 | 45 | }
|
| 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`); |
64 | 50 |
|
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)); |
89 | 52 |
|
90 | 53 | if (someCommitsInvalid) {
|
91 | 54 | logger.error('Please fix the failing commit messages before continuing...');
|
|
0 commit comments