generated from JoshuaKGoldberg/create-typescript-app
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgetCommitMeaning.ts
38 lines (30 loc) · 1.04 KB
/
getCommitMeaning.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
import conventionalCommitsParser from "conventional-commits-parser";
const alwaysMeaningfulTypes = new Set(["feat", "fix", "perf"]);
const alwaysIgnoredTypes = new Set(["docs", "refactor", "style", "test"]);
const releaseCommitTester =
/^(?:chore(?:\(.*\))?:?)?\s*release|v?\d+\.\d+\.\d+/;
export function getCommitMeaning(message: string) {
// Some types are always meaningful or ignored, regardless of potentially release-like messages
const { header, notes, type } = conventionalCommitsParser.sync(message, {
breakingHeaderPattern: /^(\w*)(?:\((.*)\))?!: (.*)$/,
});
if (
notes.some((note) => note.title.match(/^BREAKING[ -]CHANGE$/)) ||
header?.match(/^BREAKING[ -]CHANGE(?: \([^)]+\))?:/)
) {
return "meaningful";
}
if (type) {
if (alwaysMeaningfulTypes.has(type)) {
return "meaningful";
}
if (alwaysIgnoredTypes.has(type)) {
return { type };
}
}
// If we've hit a release commit, we know we don't need to release
if (releaseCommitTester.test(message)) {
return "release";
}
return { type: type ?? undefined };
}