Skip to content

Commit 91a9015

Browse files
committed
adding cirrus ci provider
1 parent bc58377 commit 91a9015

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed

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: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
})

0 commit comments

Comments
 (0)