forked from ubiquity/ubiquibot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomment-created.ts
More file actions
48 lines (38 loc) · 1.57 KB
/
Copy pathcomment-created.ts
File metadata and controls
48 lines (38 loc) · 1.57 KB
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
import { Context } from "../../types/context";
import { GitHubComment, GitHubPayload } from "../../types/payload";
import { commentParser, userCommands } from "./handlers/comment-handler-main";
import { verifyFirstCommentInRepository } from "./handlers/first";
export async function commentCreated(context: Context) {
const config = context.config,
logger = context.logger,
payload = context.event.payload as GitHubPayload;
const comment = payload.comment as GitHubComment;
const body = comment.body;
const commentedCommand = commentParser(body);
if (!comment) {
logger.info(`Comment is null. Skipping`);
}
const issue = payload.issue;
if (!issue) {
throw logger.error("Issue is null. Skipping", { issue });
}
if (commentedCommand) {
await verifyFirstCommentInRepository(context);
}
const allCommands = userCommands(config.miscellaneous.registerWalletWithVerification);
const userCommand = allCommands.find((i) => i.id == commentedCommand);
if (userCommand) {
const { id, handler } = userCommand;
logger.info("Running a comment handler", { id, handler: handler.name });
const isDisabled = config.disabledCommands.some((command) => command === id.replace("/", ""));
if (isDisabled && id !== "/help") {
return logger.error("Skipping because it is disabled on this repo.", { id });
}
return await handler(context, body);
} else {
const sanitizedBody = body.replace(/<!--[\s\S]*?-->/g, "");
return logger.verbose("Comment event received without a recognized user command.", {
sanitizedBody,
});
}
}