From 13208e30469a20ba47e62221da5e40e88978fbf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= Date: Fri, 26 Jan 2024 08:38:36 +0100 Subject: [PATCH] fix: catch `-1` reaction failures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ --- src/backport.ts | 2 +- src/index.ts | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/backport.ts b/src/backport.ts index 0ab986f..df53439 100644 --- a/src/backport.ts +++ b/src/backport.ts @@ -142,8 +142,8 @@ export const backport = (task: Task) => new Promise((resolve, reject) => { addReaction(octokit, task, Reaction.HOORAY) } catch (e) { // Add a thumbs down reaction to the comment to indicate that we failed - addReaction(octokit, task, Reaction.THUMBS_DOWN) try { + addReaction(octokit, task, Reaction.THUMBS_DOWN) const failureComment = getFailureCommentBody(task, backportBranch, e?.message) await commentOnPR(octokit, task, failureComment) } catch (e) { diff --git a/src/index.ts b/src/index.ts index 9c0b773..02dcb05 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ import { createNodeMiddleware } from '@octokit/webhooks' import { createServer } from 'http' -import { info, error } from 'node:console' +import { info, error, warn } from 'node:console' import { Octokit } from '@octokit/rest' import { addToQueue } from './queue' @@ -167,7 +167,12 @@ app.webhooks.on(['issue_comment.created'], async ({ payload }) => { const isMerged = typeof payload.issue?.pull_request?.merged_at === 'string' if (isClosed && !isMerged) { - addReaction(authOctokit, { owner, repo, commentId } as Task, Reaction.THUMBS_DOWN) + try { + addReaction(authOctokit, { owner, repo, commentId } as Task, Reaction.THUMBS_DOWN) + } catch (e) { + // Safely ignore + warn(`Failed to add reaction to comment: ${e.message}`) + } error(`Ignoring comment on closed but unmerged PR ${htmlUrl}`) return } @@ -251,7 +256,12 @@ app.webhooks.on(['issue_comment.created'], async ({ payload }) => { } catch (e) { // This should really not happen, but if it does, we want to know about it if (e instanceof Error) { - addReaction(authOctokit, { owner, repo, commentId } as Task, Reaction.THUMBS_DOWN) + try { + addReaction(authOctokit, { owner, repo, commentId } as Task, Reaction.THUMBS_DOWN) + } catch (e) { + // Safely ignore + warn(`Failed to add reaction to comment: ${e.message}`) + } error(`Failed to handle backport request: ${e.message}`) return }