Skip to content

Commit

Permalink
Simplified fixtures and deleted lots of code
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipj committed May 9, 2016
1 parent 6bfdafa commit 954e44a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 65 deletions.
41 changes: 3 additions & 38 deletions lib/push-jenkins-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,11 @@

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+)/

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')
} else if (matchedGhStatus) {
createGhStatus(matchedGhStatus.state, matchedGhStatus.message)
} else {
console.error(`! ${prInfoStr(options)} Unknown Jenkins build result '${build.result}'`)
}
createGhStatus(build.status, build.message)
}

function createGhStatusFn (options) {
Expand All @@ -60,19 +31,13 @@ function createGhStatusFn (options) {
}

function extendWithBuildData (options, build) {
const lastChangeSet = build.changeSet.items[0]

return Object.assign({
sha: lastChangeSet.commitId,
sha: build.commit,
url: build.url,
context: jobNameToStatusCtx(build.fullDisplayName)
context: build.identifier
}, options)
}

function jobNameToStatusCtx (displayName) {
return rxDisplayName.exec(displayName)[1]
}

function prInfoStr (options) {
return `${options.owner}/${options.repoName}`
}
Expand Down
13 changes: 4 additions & 9 deletions test/_fixtures/error-payload.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
{
"fullDisplayName": "node-test-commit-arm #3087",
"result": "FAILURE",
"changeSet": {
"items": [
{
"commitId": "7190bd23810f0880d95605bf6f785224a345d477"
}
]
},
"identifier": "test/arm",
"status": "failure",
"message": "tests failed",
"commit": "8a5fec2a6bade91e544a30314d7cf21f8a200de1",
"url": "https://ci.nodejs.org/job/node-test-commit-arm/3087/"
}
13 changes: 4 additions & 9 deletions test/_fixtures/pending-payload.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
{
"fullDisplayName": "node-test-commit-linux #3176",
"result": null,
"changeSet": {
"items": [
{
"commitId": "7190bd23810f0880d95605bf6f785224a345d477"
}
]
},
"identifier": "test/linux",
"status": "pending",
"message": "checking for errors",
"commit": "8a5fec2a6bade91e544a30314d7cf21f8a200de1",
"url": "https://ci.nodejs.org/job/node-test-commit-linux/3176/"
}
13 changes: 4 additions & 9 deletions test/_fixtures/success-payload.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
{
"fullDisplayName": "node-test-commit-osx #3157",
"result": "SUCCESS",
"changeSet": {
"items": [
{
"commitId": "7190bd23810f0880d95605bf6f785224a345d477"
}
]
},
"identifier": "test/osx",
"status": "success",
"message": "tests passed",
"commit": "8a5fec2a6bade91e544a30314d7cf21f8a200de1",
"url": "https://ci.nodejs.org/job/node-test-commit-osx/3157/"
}

0 comments on commit 954e44a

Please sign in to comment.