Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/node-repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ const githubClient = require('./github-client')

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

function deferredResolveLabelsThenUpdatePr (options) {
const timeoutMillis = (options.timeoutInSec || 0) * 1000
setTimeout(resolveLabelsThenUpdatePr, timeoutMillis, options)
}

function resolveLabelsThenUpdatePr (options) {
githubClient.pullRequests.getFiles({
user: options.owner,
Expand Down Expand Up @@ -40,4 +45,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