Skip to content

Commit

Permalink
Merge pull request #392 from nextcloud/fix/catch-reaction-failure
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv authored Jan 26, 2024
2 parents edf5f42 + 13208e3 commit 2036caa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/backport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ export const backport = (task: Task) => new Promise<void>((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) {
Expand Down
16 changes: 13 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 2036caa

Please sign in to comment.