-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
62 lines (53 loc) · 1.73 KB
/
app.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
59
60
61
62
module.exports = (app, { getRouter }) => {
app.on(
[
"issues.opened",
"issues.reopened",
"issues.edited",
"pull_request.opened",
"pull_request.reopened",
"pull_request.edited"
],
async context => {
const config = await context.config("keylabeler.yml", {
matchTitle: true,
matchBody: true,
caseSensitive: true,
useRegex: false,
});
if (!config) {
console.log('Config file named "keylabeler.yml" not found. Exiting.');
return;
}
let labelsToAdd = [];
var ourIssueOrPR = context.payload.issue;
if (ourIssueOrPR == null) ourIssueOrPR = context.payload.pull_request; //If there's no issue field, then it's a pull request trigger 😎
let fetchedTitle = ourIssueOrPR.title.slice();
let fetchedBody = ourIssueOrPR.body.slice();
if (config.caseSensitive === false) {
fetchedTitle = fetchedTitle.toLowerCase();
fetchedBody = fetchedBody.toLowerCase();
}
for (let token in config.labelMappings) {
let tokenName = token.slice();
if (config.caseSensitive === false) {
tokenName = tokenName.toLowerCase();
}
if ((
config.matchTitle &&
(config.useRegex && fetchedTitle.match(tokenName)
|| !config.useRegex && fetchedTitle.includes(tokenName))
) || (
config.matchBody &&
(config.useRegex && fetchedBody.match(tokenName)
|| !config.useRegex && fetchedBody.includes(tokenName))
)) {
labelsToAdd.push(config.labelMappings[token]);
}
}
return context.octokit.issues.addLabels(
context.issue({ labels: labelsToAdd })
);
}
);
};