Skip to content

Commit

Permalink
fix: catch -1 reaction failures
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ <[email protected]>
  • Loading branch information
skjnldsv committed Jan 26, 2024
1 parent 34bfc11 commit 13208e3
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)

Check warning on line 146 in src/backport.ts

View check run for this annotation

Codecov / codecov/patch

src/backport.ts#L146

Added line #L146 was not covered by tests
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)

Check warning on line 171 in src/index.ts

View check run for this annotation

Codecov / codecov/patch

src/index.ts#L170-L171

Added lines #L170 - L171 were not covered by tests
} catch (e) {
// Safely ignore
warn(`Failed to add reaction to comment: ${e.message}`)

Check warning on line 174 in src/index.ts

View check run for this annotation

Codecov / codecov/patch

src/index.ts#L174

Added line #L174 was not covered by tests
}
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)

Check warning on line 260 in src/index.ts

View check run for this annotation

Codecov / codecov/patch

src/index.ts#L259-L260

Added lines #L259 - L260 were not covered by tests
} catch (e) {
// Safely ignore
warn(`Failed to add reaction to comment: ${e.message}`)

Check warning on line 263 in src/index.ts

View check run for this annotation

Codecov / codecov/patch

src/index.ts#L263

Added line #L263 was not covered by tests
}
error(`Failed to handle backport request: ${e.message}`)
return
}
Expand Down

0 comments on commit 13208e3

Please sign in to comment.