Skip to content

Commit 31d0d2e

Browse files
authored
labels: retry request for PR files if GitHub request fails (#130)
Trying to get around some intermittent GitHub API 404 failures, probably due to a race condition where the API hasn't yet got to update its PR cache or something similar.
1 parent 5dbc9b8 commit 31d0d2e

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lib/node-repo.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
'use strict'
22

33
const LRU = require('lru-cache')
4+
const retry = require('async').retry
45

56
const githubClient = require('./github-client')
67
const resolveLabels = require('./node-labels').resolveLabels
78
const existingLabelsCache = new LRU({ max: 1, maxAge: 1000 * 60 * 60 })
89

10+
const fiveSeconds = 5 * 1000
11+
912
function deferredResolveLabelsThenUpdatePr (options) {
1013
const timeoutMillis = (options.timeoutInSec || 0) * 1000
1114
setTimeout(resolveLabelsThenUpdatePr, timeoutMillis, options)
@@ -14,11 +17,15 @@ function deferredResolveLabelsThenUpdatePr (options) {
1417
function resolveLabelsThenUpdatePr (options) {
1518
options.logger.debug('Fetching PR files for labelling')
1619

17-
githubClient.pullRequests.getFiles({
18-
owner: options.owner,
19-
repo: options.repo,
20-
number: options.prId
21-
}, (err, res) => {
20+
const getFiles = (cb) => {
21+
githubClient.pullRequests.getFiles({
22+
owner: options.owner,
23+
repo: options.repo,
24+
number: options.prId
25+
}, cb)
26+
}
27+
28+
retry({ times: 5, interval: fiveSeconds }, getFiles, (err, res) => {
2229
if (err) {
2330
return options.logger.error(err, 'Error retrieving files from GitHub')
2431
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"private": true,
1414
"license": "MIT",
1515
"dependencies": {
16+
"async": "2.1.5",
1617
"basic-auth": "^1.0.4",
1718
"body-parser": "^1.15.0",
1819
"bunyan": "^1.8.1",

0 commit comments

Comments
 (0)