-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
36 lines (28 loc) · 1.03 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
const reprimand = require("./reprimand.js");
const [isNegativeSentiment, makeRandomResponse] =
[reprimand.isNegativeSentiment, reprimand.makeRandomResponse];
const events = ["issues.opened", "issues.edited"
, "issue_comment.created", "issue_comment.edited"
, "commit_comment.created"
, "discussion.created", "discussion.edited"
, "discussion_comment.created", "discussion_comment.edited"
];
async function replyToIssue(context) {
if (context.isBot) return; // Don't want recursive - effect
const sentBy = context.payload.sender.login;
let messageLocation = "issue";
if (context.name.includes("comment")){
messageLocation = "comment";
}
const message = context.payload[messageLocation].body;
const rebukeMessage = makeRandomResponse(sentBy, message);
if (!isNegativeSentiment(message)) return;
const issueComment = context.issue({
body: rebukeMessage
});
return context.octokit.issues.createComment(issueComment);
}
console.log("GOT TO THE APP");
module.exports = (app) => {
app.on(events, replyToIssue);
};