Skip to content

Commit

Permalink
Add thumbs up to comments which run commands (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed May 16, 2024
1 parent 2f8f943 commit d808eb6
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions GithubCommentReader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ const testItCommands = [
* issueNumber: number;
* commentId: number;
* commentBody: string;
* commentIsFromIssue: boolean;
* isPr: boolean;
* commentUser: string;
* authorAssociation: AuthorAssociation
Expand Down Expand Up @@ -551,6 +552,18 @@ async function webhook(params) {
return;
}

log(`Reacting to ${params.commentIsFromIssue ? "issue" : "review"} comment ${params.commentId}`);
try {
const createReaction = params.commentIsFromIssue ? cli.reactions.createForIssueComment : cli.reactions.createForPullRequestReviewComment;
await createReaction({
owner: "microsoft",
repo: "TypeScript",
comment_id: params.commentId,
content: "+1",
});
} catch (e) {
log(`Failed to react to comment: ${e}`);
}

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

const isNewComment = "action" in event
&& (event.action === "created" || event.action === "submitted")
&& ("issue" in event || "pull_request" in event);
&& (
(event.action === "created" && "issue" in event) // issue_comment.created
|| (event.action === "submitted" && "review" in event) // pull_request_review.submitted
)
if (!isNewComment) {
context.log("Not a new comment")
return {};
}

const comment = "comment" in event ? event.comment : event.review;
const commentIsFromIssue = "comment" in event;
const comment = commentIsFromIssue ? event.comment : event.review;
if (!comment.body) {
context.log("No comment body")
return {};
Expand All @@ -726,6 +742,7 @@ async function handler(request, context) {
issueNumber,
commentId: comment.id,
commentBody: comment.body,
commentIsFromIssue,
isPr,
commentUser: comment.user.login,
authorAssociation: comment.author_association,
Expand Down

0 comments on commit d808eb6

Please sign in to comment.