-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
58 lines (45 loc) · 1.39 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
58
const { validateTimeUnit } = require("./src/types/TimeUnit");
/**
* The GitLab spend directives.
* @see https://docs.gitlab.com/ee/user/project/quick_actions.html#issues-merge-requests-and-epics
*/
const spendDirectives = ["/spend", "/spend_time"];
module.exports = {
rules: {
spend: (ctx, applicable) => {
if (applicable === "never") {
return [false, 'the "spend" rule does not support "never"'];
}
const { body } = ctx;
if (!body) {
// Require a body
return [false, "Commit message body must contain a spend directive"];
}
const lines = body.split("\n");
const spendLines = lines.filter((line) =>
spendDirectives.some((directive) => line.startsWith(directive))
);
if (spendLines.length === 0) {
return [
false,
"Commit message body must contain a line starting with a spend directive",
];
}
for (const line of spendLines) {
const lineSplit = line.split(" ");
if (lineSplit.length < 2) {
return [
false,
"Spend directive must be provided with at least one time value",
];
}
const timeValues = lineSplit.slice(1);
const [isValid, msg] = validateTimeUnit(timeValues);
if (!isValid) {
return [false, msg];
}
}
return [true, undefined];
},
},
};