Skip to content
Open
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
12 changes: 9 additions & 3 deletions lib/push-jenkins-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ export function pushStarted (options, build, cb) {
if (build.status === 'pending') {
switch (build.identifier) {
case 'node-test-pull-request':
createPrComment(Object.assign({ issue_number: pr }, options), `CI: ${build.url}`)
postCiComment(options, pr, `CI: ${build.url}`)
break

case 'node-test-commit-v8-linux':
createPrComment(Object.assign({ issue_number: pr }, options), `V8 CI: ${build.url}`)
postCiComment(options, pr, `V8 CI: ${build.url}`)
break

case 'node-test-pull-request-lite-pipeline':
createPrComment(Object.assign({ issue_number: pr }, options), `Lite-CI: ${build.url}`)
postCiComment(options, pr, `Lite-CI: ${build.url}`)
break

default:
Expand Down Expand Up @@ -70,6 +70,12 @@ export function pushEnded (options, build, cb) {
})
}

function postCiComment (options, pr, body) {
// posting the CI link is best effort: createPrComment() has already logged any error,
// and letting it surface as an unhandled rejection would terminate the bot process
createPrComment(Object.assign({ issue_number: pr }, options), body).catch(() => {})
}

function findPrInRef (gitRef) {
// refs/pull/12345/head
return parseInt(gitRef.split('/')[2], 10)
Expand Down
26 changes: 25 additions & 1 deletion test/unit/push-jenkins-update.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'node:test'

import { findLatestCommitInPr } from '../../lib/push-jenkins-update.js'
import { findLatestCommitInPr, pushStarted } from '../../lib/push-jenkins-update.js'

import fetchMock from 'fetch-mock'
import readFixture from '../read-fixture.js'
Expand Down Expand Up @@ -65,3 +65,27 @@ test('findLatestCommitInPr: paginates results when more than 100 commits in a PR
thirdPageScope.callHistory.called()
fourthPageScope.callHistory.called()
})

test('pushStarted: updates the commit status even when posting the CI comment fails', (t, done) => {
const build = readFixture('jenkins-test-pull-request-success-payload.json')
build.status = 'pending'
const logger = { info: () => {}, error: () => {}, debug: () => {}, child: function () { return this } }

fetchMock.mockGlobal()

const commentUrl = 'https://api.github.com/repos/nodejs/node/issues/12345/comments'
fetchMock.route({ url: commentUrl, method: 'POST' }, 500)
fetchMock.route('https://api.github.com/repos/nodejs/node/pulls/12345/commits', readFixture('pr-commits.json'))
const statusUrl = 'https://api.github.com/repos/nodejs/node/statuses/8a5fec2a6bade91e544a30314d7cf21f8a200de1'
fetchMock.route({ url: statusUrl, method: 'POST' }, 201)

t.plan(3)

pushStarted({ owner: 'nodejs', repo: 'node', logger }, build, (err) => {
t.assert.strictEqual(err, undefined)
t.assert.strictEqual(fetchMock.callHistory.called(commentUrl), true)
t.assert.strictEqual(fetchMock.callHistory.called(statusUrl), true)
// give a rejected comment promise the chance to surface as an unhandled rejection
setImmediate(done)
})
})