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
23 changes: 15 additions & 8 deletions lib/push-jenkins-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const url = require('url')

const githubClient = require('./github-client')

function pushStarted (options, build) {
function pushStarted (options, build, cb) {
const pr = findPrInRef(build.ref)

// create unique logger which is easily traceable for every subsequent log statement
Expand All @@ -15,7 +15,9 @@ function pushStarted (options, build) {

findLatestCommitInPr(optsWithPr, (err, latestCommit) => {
if (err) {
return logger.error(err, 'Got error when retrieving GitHub commits for PR')
logger.error(err, 'Got error when retrieving GitHub commits for PR')
cb(err)
return
}

const statusOpts = Object.assign({
Expand All @@ -26,11 +28,11 @@ function pushStarted (options, build) {
message: build.message || 'running tests'
}, options)

createGhStatus(statusOpts, logger)
createGhStatus(statusOpts, logger, cb)
})
}

function pushEnded (options, build) {
function pushEnded (options, build, cb) {
const pr = findPrInRef(build.ref)

// create unique logger which is easily traceable for every subsequent log statement
Expand All @@ -41,7 +43,9 @@ function pushEnded (options, build) {

findLatestCommitInPr(optsWithPr, (err, latestCommit) => {
if (err) {
return logger.error(err, 'Got error when retrieving GitHub commits for PR')
logger.error(err, 'Got error when retrieving GitHub commits for PR')
cb(err)
return
}

const statusOpts = Object.assign({
Expand All @@ -52,7 +56,7 @@ function pushEnded (options, build) {
message: build.message || 'all tests passed'
}, options)

createGhStatus(statusOpts, logger)
createGhStatus(statusOpts, logger, cb)
})
}

Expand Down Expand Up @@ -89,7 +93,7 @@ function findLatestCommitInPr (options, cb, pageNumber = 1) {
})
}

function createGhStatus (options, logger) {
function createGhStatus (options, logger, cb) {
githubClient.repos.createStatus({
owner: options.owner,
repo: options.repo,
Expand All @@ -100,9 +104,12 @@ function createGhStatus (options, logger) {
description: options.message
}, (err, res) => {
if (err) {
return logger.error(err, 'Error while updating Jenkins / GitHub PR status')
logger.error(err, 'Error while updating Jenkins / GitHub PR status')
cb(err)
return
}
logger.info('Jenkins / Github PR status updated')
cb(null)
})
}

Expand Down
14 changes: 8 additions & 6 deletions scripts/jenkins-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ module.exports = function (app) {
owner: 'nodejs',
repo,
logger: req.log
}, req.body)

res.status(201).end()
}, req.body, (err) => {
const statusCode = err !== null ? 500 : 201
res.status(statusCode).end()
})
})

app.post('/:repo/jenkins/end', (req, res) => {
Expand All @@ -75,8 +76,9 @@ module.exports = function (app) {
owner: 'nodejs',
repo,
logger: req.log
}, req.body)

res.status(201).end()
}, req.body, (err) => {
const statusCode = err !== null ? 500 : 201
res.status(statusCode).end()
})
})
}
12 changes: 8 additions & 4 deletions test/integration/push-jenkins-update.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ tap.test('Sends POST requests to https://api.github.com/repos/nodejs/node/status
.reply(201)

t.plan(1)
t.tearDown(() => prCommitsScope.done() && scope.done())

supertest(app)
.post('/node/jenkins/start')
.send(jenkinsPayload)
.expect(201)
.end((err, res) => {
prCommitsScope.done()
scope.done()
t.equal(err, null)
})
})
Expand All @@ -40,13 +41,14 @@ tap.test('Allows repository name to be provided with URL parameter when pushing
.reply(201)

t.plan(1)
t.tearDown(() => prCommitsScope.done() && scope.done())

supertest(app)
.post('/citgm/jenkins/start')
.send(jenkinsPayload)
.expect(201)
.end((err, res) => {
prCommitsScope.done()
scope.done()
t.equal(err, null)
})
})
Expand All @@ -61,13 +63,14 @@ tap.test('Allows repository name to be provided with URL parameter when pushing
.reply(201)

t.plan(1)
t.tearDown(() => prCommitsScope.done() && scope.done())

supertest(app)
.post('/citgm/jenkins/end')
.send(jenkinsPayload)
.expect(201)
.end((err, res) => {
prCommitsScope.done()
scope.done()
t.equal(err, null)
})
})
Expand All @@ -87,13 +90,14 @@ tap.test('Forwards payload provided in incoming POST to GitHub status API', (t)
.reply(201)

t.plan(1)
t.tearDown(() => prCommitsScope.done() && scope.done())

supertest(app)
.post('/node/jenkins/start')
.send(fixture)
.expect(201)
.end((err, res) => {
prCommitsScope.done()
scope.done()
t.equal(err, null)
})
})
Expand Down