Skip to content

Commit 2bfb124

Browse files
Merge pull request #193 from eddiemoore/feature/provider-cirrus
Adding Cirrus CI provider
2 parents bc58377 + cca0a9d commit 2bfb124

File tree

3 files changed

+159
-0
lines changed

3 files changed

+159
-0
lines changed

src/ci_providers/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const providerAzurepipelines = require('./provider_azurepipelines')
33
const providerBitbucket = require('./provider_bitbucket')
44
const providerBuildkite = require('./provider_buildkite')
55
const providerCircleci = require('./provider_circleci')
6+
const providerCirrus = require('./provider_cirrus')
67
const providerDrone = require('./provider_drone')
78
const providerGitHubactions = require('./provider_githubactions')
89
const providerGitLabci = require('./provider_gitlabci')
@@ -17,6 +18,7 @@ const providers = [
1718
providerBitbucket,
1819
providerBuildkite,
1920
providerCircleci,
21+
providerCirrus,
2022
providerDrone,
2123
providerGitHubactions,
2224
providerGitLabci,

src/ci_providers/provider_cirrus.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
function detect(envs) {
2+
return !!envs.CIRRUS_CI
3+
}
4+
5+
function _getBuild(inputs) {
6+
const { args, envs } = inputs
7+
return args.build || envs.CIRRUS_BUILD_ID
8+
}
9+
10+
// eslint-disable-next-line no-unused-vars
11+
function _getBuildURL(inputs) {
12+
return ''
13+
}
14+
15+
function _getBranch(inputs) {
16+
const { args, envs } = inputs
17+
return args.branch || envs.CIRRUS_BRANCH
18+
}
19+
20+
function _getJob(envs) {
21+
return envs.CIRRUS_TASK_ID || ''
22+
}
23+
24+
function _getPR(inputs) {
25+
const { args, envs } = inputs
26+
return args.pr || envs.CIRRUS_PR
27+
}
28+
29+
function _getService() {
30+
return 'cirrus-ci'
31+
}
32+
33+
function getServiceName() {
34+
return 'Cirrus CI'
35+
}
36+
37+
function _getSHA(inputs) {
38+
const { args, envs } = inputs
39+
return args.sha || envs.CIRRUS_CHANGE_IN_REPO
40+
}
41+
42+
function _getSlug(inputs) {
43+
const { args, envs } = inputs
44+
return args.slug || envs.CIRRUS_REPO_FULL_NAME
45+
}
46+
47+
function getServiceParams(inputs) {
48+
return {
49+
branch: _getBranch(inputs),
50+
build: _getBuild(inputs),
51+
buildURL: _getBuildURL(inputs),
52+
commit: _getSHA(inputs),
53+
job: _getJob(inputs.envs),
54+
pr: _getPR(inputs),
55+
service: _getService(),
56+
slug: _getSlug(inputs),
57+
}
58+
}
59+
60+
module.exports = {
61+
detect,
62+
getServiceName,
63+
getServiceParams,
64+
}
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 providerCirrus = require('../../src/ci_providers/provider_cirrus')
4+
5+
describe('Cirrus Params', () => {
6+
afterEach(() => {
7+
td.reset()
8+
})
9+
10+
describe('detect()', () => {
11+
it('does not run without Cirrus env variable', () => {
12+
const inputs = {
13+
args: {},
14+
envs: {},
15+
}
16+
const detected = providerCirrus.detect(inputs.envs)
17+
expect(detected).toBeFalsy()
18+
})
19+
20+
it('does run with Cirrus env variable', () => {
21+
const inputs = {
22+
args: {},
23+
envs: {
24+
CI: true,
25+
CIRRUS_CI: true,
26+
},
27+
}
28+
const detected = providerCirrus.detect(inputs.envs)
29+
expect(detected).toBeTruthy()
30+
})
31+
})
32+
33+
it('gets correct params', () => {
34+
const inputs = {
35+
args: {},
36+
envs: {
37+
CI: true,
38+
CIRRUS_CI: true,
39+
CIRRUS_BRANCH: 'master',
40+
CIRRUS_CHANGE_IN_REPO: 'testingsha',
41+
CIRRUS_BUILD_ID: 2,
42+
CIRRUS_PR: 1,
43+
CIRRUS_REPO_FULL_NAME: 'https:/example.com/repo',
44+
},
45+
}
46+
const expected = {
47+
branch: 'master',
48+
build: 2,
49+
buildURL: '',
50+
commit: 'testingsha',
51+
job: '',
52+
pr: 1,
53+
service: 'cirrus-ci',
54+
slug: 'https:/example.com/repo',
55+
}
56+
const params = providerCirrus.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+
CIRRUS_CI: true,
72+
CIRRUS_BRANCH: 'master',
73+
CIRRUS_CHANGE_IN_REPO: 'testingsha',
74+
CIRRUS_BUILD_ID: 2,
75+
CIRRUS_PR: 1,
76+
CIRRUS_REPO_FULL_NAME: 'https:/example.com/repo',
77+
},
78+
}
79+
const expected = {
80+
branch: 'branch',
81+
build: 3,
82+
buildURL: '',
83+
commit: 'testsha',
84+
job: '',
85+
pr: '2',
86+
service: 'cirrus-ci',
87+
slug: 'testOrg/testRepo',
88+
}
89+
90+
const params = providerCirrus.getServiceParams(inputs)
91+
expect(params).toMatchObject(expected)
92+
})
93+
})

0 commit comments

Comments
 (0)