Skip to content

Commit 245e57f

Browse files
Merge pull request #195 from eddiemoore/feature/provider-wercker
Adding Wercker provider
2 parents 2bfb124 + cea6b77 commit 245e57f

File tree

3 files changed

+161
-0
lines changed

3 files changed

+161
-0
lines changed

src/ci_providers/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const providerGitLabci = require('./provider_gitlabci')
1010
const providerJenkinsci = require('./provider_jenkinsci')
1111
const providerLocal = require('./provider_local')
1212
const providerTravisci = require('./provider_travisci')
13+
const providerWercker = require('./provider_wercker')
1314

1415
// Please make sure provider_local is last
1516
const providers = [
@@ -24,6 +25,7 @@ const providers = [
2425
providerGitLabci,
2526
providerJenkinsci,
2627
providerTravisci,
28+
providerWercker,
2729
providerLocal,
2830
]
2931

src/ci_providers/provider_wercker.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
function detect(envs) {
2+
return envs.WERCKER_MAIN_PIPELINE_STARTED
3+
}
4+
5+
function _getBuild(inputs) {
6+
const { args, envs } = inputs
7+
return args.build || envs.WERCKER_MAIN_PIPELINE_STARTED
8+
}
9+
10+
function _getBuildURL(inputs) {
11+
const { envs } = inputs
12+
return envs.WERCKER_BUILD_URL || ''
13+
}
14+
15+
function _getBranch(inputs) {
16+
const { args, envs } = inputs
17+
18+
return args.branch || envs.WERCKER_GIT_BRANCH
19+
}
20+
21+
// eslint-disable-next-line no-unused-vars
22+
function _getJob(envs) {
23+
return ''
24+
}
25+
26+
function _getPR(inputs) {
27+
const { args } = inputs
28+
return args.pr || ''
29+
}
30+
31+
function _getService() {
32+
return 'wercker'
33+
}
34+
35+
function getServiceName() {
36+
return 'Wercker CI'
37+
}
38+
39+
function _getSHA(inputs) {
40+
const { args, envs } = inputs
41+
return args.sha || envs.WERCKER_GIT_COMMIT
42+
}
43+
44+
function _getSlug(inputs) {
45+
const { args, envs } = inputs
46+
return args.slug || `${envs.WERCKER_GIT_OWNER}/${envs.WERCKER_GIT_REPOSITORY}`
47+
}
48+
49+
function getServiceParams(inputs) {
50+
return {
51+
branch: _getBranch(inputs),
52+
build: _getBuild(inputs),
53+
buildURL: _getBuildURL(inputs),
54+
commit: _getSHA(inputs),
55+
job: _getJob(inputs.envs),
56+
pr: _getPR(inputs),
57+
service: _getService(),
58+
slug: _getSlug(inputs),
59+
}
60+
}
61+
62+
module.exports = {
63+
detect,
64+
getServiceName,
65+
getServiceParams,
66+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
const td = require('testdouble')
2+
3+
const providerWercker = require('../../src/ci_providers/provider_wercker')
4+
5+
describe('Wercker CI Params', () => {
6+
afterEach(() => {
7+
td.reset()
8+
})
9+
10+
describe('detect()', () => {
11+
it('does not run without Wercker CI env variable', () => {
12+
const inputs = {
13+
args: {},
14+
envs: {},
15+
}
16+
let detected = providerWercker.detect(inputs.envs)
17+
expect(detected).toBeFalsy()
18+
})
19+
20+
it('does run with Wercker CI env variable', () => {
21+
const inputs = {
22+
args: {},
23+
envs: {
24+
CI: true,
25+
WERCKER_MAIN_PIPELINE_STARTED: true,
26+
},
27+
}
28+
const detected = providerWercker.detect(inputs.envs)
29+
expect(detected).toBeTruthy()
30+
})
31+
})
32+
33+
it('gets correct params on push', () => {
34+
const inputs = {
35+
args: {},
36+
envs: {
37+
CI: true,
38+
WERCKER_MAIN_PIPELINE_STARTED: 1,
39+
WERCKER_GIT_BRANCH: 'main',
40+
WERCKER_GIT_COMMIT: 'testingsha',
41+
WERCKER_GIT_OWNER: 'testOrg',
42+
WERCKER_GIT_REPOSITORY: 'testRepo',
43+
WERCKER_BUILD_URL: 'https://example.com/build',
44+
},
45+
}
46+
const expected = {
47+
branch: 'main',
48+
build: 1,
49+
buildURL: 'https://example.com/build',
50+
commit: 'testingsha',
51+
job: '',
52+
pr: '',
53+
service: 'wercker',
54+
slug: 'testOrg/testRepo',
55+
}
56+
const params = providerWercker.getServiceParams(inputs)
57+
expect(params).toMatchObject(expected)
58+
})
59+
60+
it('gets correct params for overrides', () => {
61+
const inputs = {
62+
args: {
63+
branch: 'branch',
64+
build: 3,
65+
pr: '2',
66+
sha: 'testsha',
67+
slug: 'testOrg/testRepo',
68+
},
69+
envs: {
70+
CI: true,
71+
WERCKER_MAIN_PIPELINE_STARTED: 1,
72+
WERCKER_GIT_BRANCH: 'main',
73+
WERCKER_GIT_COMMIT: 'testingsha',
74+
WERCKER_GIT_OWNER: 'someone',
75+
WERCKER_GIT_REPOSITORY: 'somewhere',
76+
WERCKER_BUILD_URL: 'https://example.com/build',
77+
},
78+
}
79+
const expected = {
80+
branch: 'branch',
81+
build: 3,
82+
buildURL: 'https://example.com/build',
83+
commit: 'testsha',
84+
job: '',
85+
pr: '2',
86+
service: 'wercker',
87+
slug: 'testOrg/testRepo',
88+
}
89+
90+
const params = providerWercker.getServiceParams(inputs)
91+
expect(params).toMatchObject(expected)
92+
})
93+
})

0 commit comments

Comments
 (0)