Skip to content

Commit d808eb6

Browse files
authored
Add thumbs up to comments which run commands (#50)
1 parent 2f8f943 commit d808eb6

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

GithubCommentReader/index.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ const testItCommands = [
500500
* issueNumber: number;
501501
* commentId: number;
502502
* commentBody: string;
503+
* commentIsFromIssue: boolean;
503504
* isPr: boolean;
504505
* commentUser: string;
505506
* authorAssociation: AuthorAssociation
@@ -551,6 +552,18 @@ async function webhook(params) {
551552
return;
552553
}
553554

555+
log(`Reacting to ${params.commentIsFromIssue ? "issue" : "review"} comment ${params.commentId}`);
556+
try {
557+
const createReaction = params.commentIsFromIssue ? cli.reactions.createForIssueComment : cli.reactions.createForPullRequestReviewComment;
558+
await createReaction({
559+
owner: "microsoft",
560+
repo: "TypeScript",
561+
comment_id: params.commentId,
562+
content: "+1",
563+
});
564+
} catch (e) {
565+
log(`Failed to react to comment: ${e}`);
566+
}
554567

555568
const start = Date.now();
556569
const created = `>=${new Date(start).toISOString()}`;
@@ -700,14 +713,17 @@ async function handler(request, context) {
700713
context.log("Inspecting comment...");
701714

702715
const isNewComment = "action" in event
703-
&& (event.action === "created" || event.action === "submitted")
704-
&& ("issue" in event || "pull_request" in event);
716+
&& (
717+
(event.action === "created" && "issue" in event) // issue_comment.created
718+
|| (event.action === "submitted" && "review" in event) // pull_request_review.submitted
719+
)
705720
if (!isNewComment) {
706721
context.log("Not a new comment")
707722
return {};
708723
}
709724

710-
const comment = "comment" in event ? event.comment : event.review;
725+
const commentIsFromIssue = "comment" in event;
726+
const comment = commentIsFromIssue ? event.comment : event.review;
711727
if (!comment.body) {
712728
context.log("No comment body")
713729
return {};
@@ -726,6 +742,7 @@ async function handler(request, context) {
726742
issueNumber,
727743
commentId: comment.id,
728744
commentBody: comment.body,
745+
commentIsFromIssue,
729746
isPr,
730747
commentUser: comment.user.login,
731748
authorAssociation: comment.author_association,

0 commit comments

Comments
 (0)