-
Notifications
You must be signed in to change notification settings - Fork 150
/
app.js
69 lines (62 loc) · 2.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
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
63
64
65
66
67
68
69
const isMessageByApp = require("./lib/is-message-by-app");
const isMessageForApp = require("./lib/is-message-for-app");
const CommentReply = require("./lib/modules/comment-reply");
const processIssueComment = require("./lib/process-issue-comment");
const { AllContributorBotError } = require("./lib/modules/errors");
/**
* @param {import('probot').Probot} app
*/
module.exports = (app) => {
app.on("issue_comment.created", async (context) => {
if (isMessageByApp(context)) return;
if (!isMessageForApp(context)) return;
// process comment and reply
const commentReply = new CommentReply(context);
try {
await processIssueComment({ context, commentReply });
} catch (error) {
const isKnownError = error instanceof AllContributorBotError;
if (!isKnownError) {
commentReply.reply(
`We had trouble processing your request. Please try again later.`
);
throw error;
}
context.log.info({ isKnownError, error: error.name }, error.message);
commentReply.reply(error.message);
} finally {
await commentReply.send();
}
});
app.on(
["installation", "installation_repositories"],
async ({ name, payload, log }) => {
const {
action,
repositories,
repositories_added,
repositories_removed,
installation,
} = payload;
const repositoriesChange =
action === "created"
? repositories.length
: action === "deleted"
? -repositories.length
: repositories_added
? repositories_added.length - repositories_removed.length
: 0;
const meta = {
event: name,
action,
account: installation.account.id,
accountType: installation.account.type.toLowerCase(),
accountLogin: installation.account.login,
installation: installation.id,
selection: installation.repository_selection,
repositoriesChange,
};
log.info(meta, `${meta.accountLogin}: ${name} ${action}`);
}
);
};