-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proxy Jenkins build status to GitHub #35
Changes from 3 commits
15f4b71
55e7fcb
6bfdafa
783220e
77f3734
7760e69
f342a05
41a8208
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
'use strict' | ||
|
||
const githubClient = require('./github-client') | ||
|
||
const jenkinsToGhStatusMap = { | ||
'SUCCESS': { | ||
state: 'success', | ||
message: 'all tests passed' | ||
}, | ||
'FAILURE': { | ||
state: 'failure', | ||
message: 'build failure' | ||
}, | ||
'ABORTED': { | ||
state: 'error', | ||
message: 'build aborted' | ||
}, | ||
'UNSTABLE': { | ||
state: 'error', | ||
message: 'build unstable' | ||
} | ||
} | ||
|
||
const rxDisplayName = /node\-test\-commit\-(\w+)/ | ||
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
Sorry, something went wrong. |
||
|
||
function pushJenkinsUpdate (options, build) { | ||
const statusOpts = extendWithBuildData(options, build) | ||
const createGhStatus = createGhStatusFn(statusOpts) | ||
const isPending = build.result === null | ||
const matchedGhStatus = jenkinsToGhStatusMap[build.result] | ||
|
||
if (isPending) { | ||
createGhStatus('pending', 'build in progress') | ||
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
Sorry, something went wrong. |
||
} else if (matchedGhStatus) { | ||
createGhStatus(matchedGhStatus.state, matchedGhStatus.message) | ||
} else { | ||
console.error(`! ${prInfoStr(options)} Unknown Jenkins build result '${build.result}'`) | ||
} | ||
} | ||
|
||
function createGhStatusFn (options) { | ||
const prInfo = prInfoStr(options) | ||
|
||
return (state, message) => { | ||
githubClient.statuses.create({ | ||
user: options.owner, | ||
repo: options.repoName, | ||
sha: options.sha, | ||
target_url: options.url, | ||
context: options.context, | ||
state: state, | ||
description: message | ||
}, (err, res) => { | ||
if (err) { | ||
return console.error(`! ${prInfo} Error while updating Jenkins / GitHub PR status`, err) | ||
} | ||
console.log(`* ${prInfo} Jenkins / Github PR status updated to '${state}'`) | ||
}) | ||
} | ||
} | ||
|
||
function extendWithBuildData (options, build) { | ||
const lastChangeSet = build.changeSet.items[0] | ||
|
||
return Object.assign({ | ||
sha: lastChangeSet.commitId, | ||
url: build.url, | ||
context: jobNameToStatusCtx(build.fullDisplayName) | ||
}, options) | ||
} | ||
|
||
function jobNameToStatusCtx (displayName) { | ||
return rxDisplayName.exec(displayName)[1] | ||
} | ||
|
||
function prInfoStr (options) { | ||
return `${options.owner}/${options.repoName}` | ||
} | ||
|
||
module.exports = pushJenkinsUpdate |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict' | ||
|
||
const pushJenkinsUpdate = require('../lib/push-jenkins-update') | ||
|
||
module.exports = function (app) { | ||
app.post('/node/jenkins', (req, res) => { | ||
pushJenkinsUpdate({ | ||
owner: 'TestOrgPleaseIgnore', | ||
repoName: 'node' | ||
}, req.body) | ||
|
||
res.end() | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"fullDisplayName": "node-test-commit-arm #3087", | ||
This comment was marked as off-topic.
Sorry, something went wrong. |
||
"result": "FAILURE", | ||
This comment was marked as off-topic.
Sorry, something went wrong. |
||
"changeSet": { | ||
"items": [ | ||
{ | ||
"commitId": "7190bd23810f0880d95605bf6f785224a345d477" | ||
} | ||
] | ||
}, | ||
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
Sorry, something went wrong. |
||
"url": "https://ci.nodejs.org/job/node-test-commit-arm/3087/" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"fullDisplayName": "node-test-commit-linux #3176", | ||
"result": null, | ||
"changeSet": { | ||
"items": [ | ||
{ | ||
"commitId": "7190bd23810f0880d95605bf6f785224a345d477" | ||
} | ||
] | ||
}, | ||
"url": "https://ci.nodejs.org/job/node-test-commit-linux/3176/" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"fullDisplayName": "node-test-commit-osx #3157", | ||
"result": "SUCCESS", | ||
"changeSet": { | ||
"items": [ | ||
{ | ||
"commitId": "7190bd23810f0880d95605bf6f785224a345d477" | ||
} | ||
] | ||
}, | ||
"url": "https://ci.nodejs.org/job/node-test-commit-osx/3157/" | ||
} |
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
Sorry, something went wrong.