Skip to content

Commit

Permalink
Remove waiting for 2 seconds before resolving labels
Browse files Browse the repository at this point in the history
In the github-bot we have found the need to wait a couple of seconds
before resolving labels on newly opened PRs.

That's because we stumbled upon what felt like consistency issues on
GitHub's side, where the github-bot got a webhook event about an opened
PR, its API would in some scenarios return 404 when fetching existing
labels on that PR.

Waiting a couple of seconds did the trick.

When the same code runs in a GitHub Action, we'd that same effect of not
asking too early out of the box, because it takes a while for Actions
to boot up and do their thing.

Refs nodejs/github-bot#79
  • Loading branch information
phillipj committed Mar 6, 2021
1 parent dbaf054 commit 9252057
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions lib/node-repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ const existingLabelsCache = new LRU({ max: 1, maxAge: 1000 * 60 * 60 })

const fiveSeconds = 5 * 1000

const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms))

async function deferredResolveLabelsThenUpdatePr (options) {
const timeoutMillis = (options.timeoutInSec || 0) * 1000
await sleep(timeoutMillis)
return resolveLabelsThenUpdatePr(options)
}

async function resolveLabelsThenUpdatePr (options) {
const times = options.retries || 5
const interval = options.retryInterval || fiveSeconds
Expand Down Expand Up @@ -127,7 +119,7 @@ async function listFiles ({ owner, repo, pull_number }) {
}

exports.fetchExistingThenUpdatePr = fetchExistingThenUpdatePr
exports.resolveLabelsThenUpdatePr = deferredResolveLabelsThenUpdatePr
exports.resolveLabelsThenUpdatePr = resolveLabelsThenUpdatePr

// exposed for testability
exports._fetchExistingLabels = fetchExistingLabels

0 comments on commit 9252057

Please sign in to comment.