forked from ZeWaka/KeywordLabeler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
56 lines (47 loc) · 1.52 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
module.exports = robot => {
robot.on(
[
"issues.opened",
"issues.reopened",
"issues.edited",
"pull_request.opened",
"pull_request.reopened",
"pull_request.edited"
],
async context => {
const config = await context.config("context-labeler.yml", {
matchTitle: true,
matchBody: true,
caseSensitive: true
});
if (!config) {
console.log('Config file named "context-labeler.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 ? fetchedTitle.includes(tokenName) : false) ||
(config.matchBody ? fetchedBody.includes(tokenName) : false)
) {
labelsToAdd.push(config.labelMappings[token]);
}
}
return context.github.issues.addLabels(
context.issue({ labels: labelsToAdd })
);
}
);
};