-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathget-conventional-bump.ts
52 lines (47 loc) · 1.51 KB
/
get-conventional-bump.ts
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
import { getFullPackageName, getSHA1HashesRegexp } from '#lib/utils';
import type { Options } from 'commander';
import { Bumper, packagePrefix } from 'conventional-recommended-bump';
export async function getConventionalBump(options: Options) {
const bumper = new Bumper().commits(
{
path: process.cwd(),
ignore: Array.isArray(options.skipCommit) ? getSHA1HashesRegexp(options.skipCommit) : undefined
},
{
headerPattern: /^(\w*)(?:\((.*)\))?: (.*)$/,
headerCorrespondence: ['type', 'scope', 'subject'],
noteKeywords: ['BREAKING CHANGE'],
revertPattern: /^(?:Revert|revert:)\s"?([\s\S]+?)"?\s*This reverts commit (\w*)\./i,
revertCorrespondence: ['header', 'hash'],
breakingHeaderPattern: /^(\w*)(?:\((.*)\))?!: (.*)$/
}
);
if (options.monoRepo) {
bumper.tag({
prefix: packagePrefix(getFullPackageName(options))
});
}
return bumper.bump((commits) => {
let level: 0 | 1 | 2 | 3 = 2;
let breakings = 0;
let features = 0;
commits.forEach((commit) => {
if (commit.notes.length > 0) {
breakings += commit.notes.length;
level = 0;
} else if (commit.type === 'feat') {
features += 1;
if (level === 2) {
level = 1;
}
}
});
return Promise.resolve({
level,
reason:
breakings === 1
? `There is ${breakings} BREAKING CHANGE and ${features} features`
: `There are ${breakings} BREAKING CHANGES and ${features} features`
});
});
}