Skip to content

Commit

Permalink
add error handling for failed GitHub API requests
Browse files Browse the repository at this point in the history
  • Loading branch information
dabrady committed Jul 24, 2022
1 parent 2b27c65 commit bd3ea08
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,26 @@ module.exports = (app: Probot) => {
}

if (requiredLabelsSatisfied && ownerSatisfied) {
const reviews = await getAutoapprovalReviews(context, config.registered_app_slug)

if (reviews.length > 0) {
context.log('PR has already reviews')
if (context.payload.action === 'dismissed') {
try {
const reviews = await getAutoapprovalReviews(context, config.registered_app_slug)

if (reviews.length > 0) {
context.log('PR has already reviews')
if (context.payload.action === 'dismissed') {
await applyAutoMerge(context, prLabels, config.auto_merge_labels, config.auto_rebase_merge_labels, config.auto_squash_merge_labels)
approvePullRequest(context)
applyLabels(context, config.apply_labels as string[])
context.log('Review was dismissed, approve again')
}
} else {
await applyAutoMerge(context, prLabels, config.auto_merge_labels, config.auto_rebase_merge_labels, config.auto_squash_merge_labels)
approvePullRequest(context)
applyLabels(context, config.apply_labels as string[])
context.log('Review was dismissed, approve again')
context.log('PR approved first time')
}
} else {
await applyAutoMerge(context, prLabels, config.auto_merge_labels, config.auto_rebase_merge_labels, config.auto_squash_merge_labels)
approvePullRequest(context)
applyLabels(context, config.apply_labels as string[])
context.log('PR approved first time')
} catch (error) {
context.log.fatal(error as object, "Oh noes!")
return
}
} else {
// one of the checks failed
Expand Down

0 comments on commit bd3ea08

Please sign in to comment.