Skip to content

Commit

Permalink
labels: defer resolving labels
Browse files Browse the repository at this point in the history
These changes defer the process of label resolving
to prevent 404 errors from Github API

Closes nodejs#79
  • Loading branch information
sejoker committed Sep 19, 2016
1 parent 70ac583 commit 0e3bb57
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
11 changes: 10 additions & 1 deletion lib/node-repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ const githubClient = require('./github-client')

const resolveLabels = require('./node-labels').resolveLabels

function deferredResolveLabelsThenUpdatePr (options) {
if (options.timeoutInSec) {
setTimeout(() => resolveLabelsThenUpdatePr(options),
options.timeoutInSec * 1000)
} else {
resolveLabelsThenUpdatePr(options)
}
}

function resolveLabelsThenUpdatePr (options) {
githubClient.pullRequests.getFiles({
user: options.owner,
Expand Down Expand Up @@ -40,4 +49,4 @@ function updatePrWithLabels (options, labels) {
})
}

exports.resolveLabelsThenUpdatePr = resolveLabelsThenUpdatePr
exports.resolveLabelsThenUpdatePr = deferredResolveLabelsThenUpdatePr
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
},
"devDependencies": {
"eventsource": "^0.2.1",
"lolex": "^1.5.1",
"nock": "^8.0.0",
"nodemon": "^1.9.1",
"proxyquire": "^1.7.10",
Expand Down
3 changes: 2 additions & 1 deletion scripts/node-subsystem-label.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ module.exports = function (app) {
repo,
prId,
logger,
baseBranch
baseBranch,
timeoutInSec: 2
})
}
}
9 changes: 7 additions & 2 deletions test/integration/node-labels-webhook.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const url = require('url')
const nock = require('nock')
const supertest = require('supertest')
const proxyquire = require('proxyquire')
const lolex = require('lolex')

const testStubs = {
'./github-secret': {
Expand All @@ -23,6 +24,7 @@ const app = proxyquire('../../app', testStubs)
setupNoRequestMatchHandler()

tap.test('Sends POST request to https://api.github.com/repos/nodejs/node/issues/<PR-NUMBER>/labels', (t) => {
const clock = lolex.install()
const expectedLabels = ['timers']
const webhookPayload = readFixture('pull-request-opened.json')

Expand All @@ -37,19 +39,21 @@ tap.test('Sends POST request to https://api.github.com/repos/nodejs/node/issues/
.reply(200)

t.plan(1)
t.tearDown(() => filesScope.done() && newLabelsScope.done())
t.tearDown(() => filesScope.done() && newLabelsScope.done() && clock.uninstall())

supertest(app)
.post('/hooks/github')
.set('x-github-event', 'pull_request')
.send(webhookPayload)
.expect(200)
.end((err, res) => {
clock.runAll()
t.equal(err, null)
})
})

tap.test('Adds v6.x label when PR is targeting the v6.x-staging branch', (t) => {
const clock = lolex.install()
const expectedLabels = ['timers', 'v6.x']
const webhookPayload = readFixture('pull-request-opened-v6.x.json')

Expand All @@ -64,14 +68,15 @@ tap.test('Adds v6.x label when PR is targeting the v6.x-staging branch', (t) =>
.reply(200)

t.plan(1)
t.tearDown(() => filesScope.done() && newLabelsScope.done())
t.tearDown(() => filesScope.done() && newLabelsScope.done() && clock.uninstall())

supertest(app)
.post('/hooks/github')
.set('x-github-event', 'pull_request')
.send(webhookPayload)
.expect(200)
.end((err, res) => {
clock.runAll()
t.equal(err, null)
})
})
Expand Down

0 comments on commit 0e3bb57

Please sign in to comment.