From f2432bc356c7a15fef04898d47ac5f78d434cc29 Mon Sep 17 00:00:00 2001 From: ShubhamPalriwala Date: Wed, 14 Feb 2024 00:34:39 +0530 Subject: [PATCH] fix: only consider award comments on PR --- lib/github/hooks/issue.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/github/hooks/issue.ts b/lib/github/hooks/issue.ts index dcf14bf..c5a25b4 100644 --- a/lib/github/hooks/issue.ts +++ b/lib/github/hooks/issue.ts @@ -97,19 +97,23 @@ export const onAwardPoints = async (webhooks: Webhooks) => { webhooks.on(EVENT_TRIGGERS.ISSUE_COMMENTED, async (context) => { try { const octokit = getOctokitInstance(context.payload.installation?.id!); - - const issueNumber = context.payload.issue.number; const repo = context.payload.repository.name; const issueCommentBody = context.payload.comment.body; - const awardPointsRegex = new RegExp(`${AWARD_POINTS_IDENTIFIER}\\s+(\\d+)`); const match = issueCommentBody.match(awardPointsRegex); + const isPR = !!context.payload.issue.pull_request; + const issueNumber = isPR ? context.payload.issue.number : undefined; let comment: string = ""; if (match) { const points = parseInt(match[1], 10); + if (!issueNumber) { + console.error("Comment is not on a PR."); + return; + } + const ossGgRepo = await getRepositoryByGithubId(context.payload.repository.id); let usersThatCanAwardPoints = ossGgRepo?.installation.memberships.map((m) => m.userId);