-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
57 lines (48 loc) · 1.46 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict';
const parser = require('conventional-commits-parser').sync;
/**
* Determine the type of release to create based on a list of commits.
*
* @param {Object} [config={}] semantic-release configuration
* @param {Object} options semantic-release options
* @param {Array} options.commits array of commits
*
* @return {Promise}
* The release type to use.
*/
async function conventionalCommitsAnalyzer(config, { commits }) {
let type = null;
const {
majorTypes = [],
minorTypes = ['feat', 'chore'],
patchTypes = ['fix', 'docs', 'refactor', 'style', 'test'],
mergePattern = /^Merge pull request #(\d+) from (.*)$/,
mergeCorrespondence = ['id', 'source'],
} = config;
const parserOptions = {
mergePattern,
mergeCorrespondence,
};
commits.map(commit => parser(commit.message, parserOptions))
.filter(commit => commit)
.every((commit) => {
// TODO - handle squash merge commits with lots of sub-commits.
if (
majorTypes.indexOf(commit.type) !== -1 ||
commit.header.match(/^[^!:]+!:/) ||
commit.notes.find(note => note.title.toUpperCase().match(/BREAKING CHANGE/))
) {
type = 'major';
return false;
}
if (minorTypes.indexOf(commit.type) !== -1) {
type = 'minor';
}
if (!type && patchTypes.indexOf(commit.type) !== -1) {
type = 'patch';
}
return true;
});
return type;
}
module.exports = conventionalCommitsAnalyzer;