-
Notifications
You must be signed in to change notification settings - Fork 65
/
issue.js
52 lines (43 loc) · 1.63 KB
/
issue.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
import _ from "lodash";
export const run = async function (payload) {
const action = payload.action;
const issue = payload.issue;
const repo = payload.repository;
const label = payload.label;
if (payload.assignee && this.cfg.activity.issues.inProgress) {
this.responses.get("issueState").progress(payload);
}
if (["labeled", "unlabeled"].includes(action)) {
await this.responses.get("areaLabel").run(issue, repo, label);
} else if (action === "closed" && this.cfg.activity.issues.clearClosed) {
this.responses.get("issueState").close(issue, repo);
} else if (action === "reopened") {
this.responses.get("issueState").reopen(issue);
} else if (action === "opened" || action === "created") {
parse.call(this, payload);
}
};
function parse(payload) {
const data = payload.comment || payload.issue;
const commenter = data.user.login;
const body = data.body;
const username = this.cfg.auth.username;
if (commenter === username || !body) return;
const prefix = new RegExp(
`@${_.escapeRegExp(username)} +(\\w+)( +(--\\w+|"[^"]+"))*`,
"g",
);
const parsed = body.match(prefix);
if (!parsed) return;
for (const command of parsed) {
const codeBlocks = [`\`\`\`\r\n${command}\r\n\`\`\``, `\`${command}\``];
if (codeBlocks.some((block) => body.includes(block))) continue;
const [, keyword] = command.replace(/\s+/, " ").split(" ");
const args = command.replace(/\s+/, " ").split(" ").slice(2).join(" ");
const file = this.commands.get(keyword);
if (file) {
file.run.call(this, payload, commenter, args);
}
}
}
export const events = ["issues", "issue_comment"];