Skip to content

Commit a9d7e5a

Browse files
Merge pull request #670 from codecov/feature/bitrise-provider
feat: add bitrise provider
2 parents 6c2c486 + f02e1cf commit a9d7e5a

File tree

3 files changed

+253
-0
lines changed

3 files changed

+253
-0
lines changed

src/ci_providers/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { IProvider } from '../types'
33
import * as providerAppveyorci from './provider_appveyorci'
44
import * as providerAzurepipelines from './provider_azurepipelines'
55
import * as providerBitbucket from './provider_bitbucket'
6+
import * as providerBitrise from './provider_bitrise'
67
import * as providerBuildkite from './provider_buildkite'
78
import * as providerCircleci from './provider_circleci'
89
import * as providerCirrus from './provider_cirrus'
@@ -23,6 +24,7 @@ const providerList: IProvider[] = [
2324
providerAppveyorci,
2425
providerAzurepipelines,
2526
providerBitbucket,
27+
providerBitrise,
2628
providerBuildkite,
2729
providerCircleci,
2830
providerCirrus,
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { IServiceParams, UploaderEnvs, UploaderInputs } from '../types'
2+
3+
import { parseSlugFromRemoteAddr } from '../helpers/git'
4+
5+
export function detect(envs: UploaderEnvs): boolean {
6+
return Boolean(envs.CI) && Boolean(envs.BITRISE_IO)
7+
}
8+
9+
function _getBuild(inputs: UploaderInputs): string {
10+
const { args, environment: envs } = inputs
11+
return args.build || envs.BITRISE_BUILD_NUMBER || ''
12+
}
13+
14+
function _getBuildURL(inputs: UploaderInputs): string {
15+
const { environment: envs } = inputs
16+
return envs.BITRISE_BUILD_URL || ''
17+
}
18+
19+
function _getBranch(inputs: UploaderInputs): string {
20+
const { args, environment: envs } = inputs
21+
return args.branch || envs.BITRISE_GIT_BRANCH || ''
22+
}
23+
24+
function _getJob() {
25+
return ''
26+
}
27+
28+
function _getPR(inputs: UploaderInputs): string {
29+
const { args, environment: envs } = inputs
30+
return args.pr || envs.BITRISE_PULL_REQUEST || ''
31+
}
32+
33+
function _getService(): string {
34+
return 'bitrise'
35+
}
36+
37+
export function getServiceName(): string {
38+
return 'Bitrise CI'
39+
}
40+
41+
function _getSHA(inputs: UploaderInputs): string {
42+
const { args, environment: envs } = inputs
43+
return args.sha || envs.GIT_CLONE_COMMIT_HASH || ''
44+
}
45+
46+
function _getSlug(inputs: UploaderInputs): string {
47+
const { args } = inputs
48+
return args.slug || parseSlugFromRemoteAddr('') || ''
49+
}
50+
51+
export function getServiceParams(inputs: UploaderInputs): IServiceParams {
52+
return {
53+
branch: _getBranch(inputs),
54+
build: _getBuild(inputs),
55+
buildURL: _getBuildURL(inputs),
56+
commit: _getSHA(inputs),
57+
job: _getJob(),
58+
pr: _getPR(inputs),
59+
service: _getService(),
60+
slug: _getSlug(inputs),
61+
}
62+
}
63+
64+
export function getEnvVarNames(): string[] {
65+
return [
66+
'BITRISE_BUILD_NUMBER',
67+
'BITRISE_BUILD_URL',
68+
'BITRISE_GIT_BRANCH',
69+
'BITRISE_IO',
70+
'BITRISE_PULL_REQUEST',
71+
'CI',
72+
'GIT_CLONE_COMMIT_HASH',
73+
]
74+
}
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
import td from 'testdouble'
2+
import childProcess from 'child_process'
3+
import { IServiceParams, UploaderInputs } from '../../src/types'
4+
import { createEmptyArgs } from '../test_helpers'
5+
6+
import * as providerBitrise from '../../src/ci_providers//provider_bitrise'
7+
8+
describe('Bitrise Params', () => {
9+
afterEach(() => {
10+
td.reset()
11+
})
12+
13+
describe('detect()', () => {
14+
it('does not run without Bitrise env variable', () => {
15+
const inputs: UploaderInputs = {
16+
args: { ...createEmptyArgs() },
17+
environment: {},
18+
}
19+
const detected = providerBitrise.detect(inputs.environment)
20+
expect(detected).toBeFalsy()
21+
})
22+
23+
it('does not run with only CI env variable', () => {
24+
const inputs: UploaderInputs= {
25+
args: { ...createEmptyArgs() },
26+
environment: {
27+
CI: 'true',
28+
},
29+
}
30+
const detected = providerBitrise.detect(inputs.environment)
31+
expect(detected).toBeFalsy()
32+
})
33+
34+
it('runs with Bitrise env variables', () => {
35+
const inputs: UploaderInputs= {
36+
args: { ...createEmptyArgs() },
37+
environment: {
38+
BITRISE_IO: 'true',
39+
CI: 'true',
40+
},
41+
}
42+
const detected = providerBitrise.detect(inputs.environment)
43+
expect(detected).toBeTruthy()
44+
})
45+
})
46+
47+
// This should test that the provider outputs proper default values
48+
it('gets the correct params on no env variables', () => {
49+
const inputs: UploaderInputs = {
50+
args: { ...createEmptyArgs() },
51+
environment: {
52+
BITRISE_IO: 'true',
53+
CI: 'true',
54+
},
55+
}
56+
const expected: IServiceParams = {
57+
branch: '',
58+
build: '',
59+
buildURL: '',
60+
commit: '',
61+
job: '',
62+
pr: '',
63+
service: 'bitrise',
64+
slug: '',
65+
}
66+
const spawnSync = td.replace(childProcess, 'spawnSync')
67+
td.when(
68+
spawnSync('git', ['config', '--get', 'remote.origin.url']),
69+
).thenReturn({ stdout: '' })
70+
71+
const params = providerBitrise.getServiceParams(inputs)
72+
expect(params).toMatchObject(expected)
73+
})
74+
75+
// This should test that the provider outputs proper parameters when a push event is created
76+
it('gets the correct params on push', () => {
77+
const inputs: UploaderInputs = {
78+
args: { ...createEmptyArgs() },
79+
environment: {
80+
BITRISE_BUILD_NUMBER: '2',
81+
BITRISE_BUILD_URL: 'https://bitrise.com/testOrg/testRepo/2',
82+
BITRISE_GIT_BRANCH: 'main',
83+
BITRISE_IO: 'true',
84+
CI: 'true',
85+
GIT_CLONE_COMMIT_HASH: 'testingSha',
86+
},
87+
}
88+
const expected: IServiceParams = {
89+
branch: 'main',
90+
build: '2',
91+
buildURL: 'https://bitrise.com/testOrg/testRepo/2',
92+
commit: 'testingSha',
93+
job: '',
94+
pr: '',
95+
service: 'bitrise',
96+
slug: 'testOrg/testRepo',
97+
}
98+
const spawnSync = td.replace(childProcess, 'spawnSync')
99+
td.when(
100+
spawnSync('git', ['config', '--get', 'remote.origin.url']),
101+
).thenReturn({ stdout: 'https://github.com/testOrg/testRepo.git' })
102+
const params = providerBitrise.getServiceParams(inputs)
103+
expect(params).toMatchObject(expected)
104+
})
105+
106+
it('gets the correct params on pr', () => {
107+
const inputs: UploaderInputs = {
108+
args: { ...createEmptyArgs() },
109+
environment: {
110+
BITRISE_BUILD_NUMBER: '2',
111+
BITRISE_BUILD_URL: 'https://bitrise.com/testOrg/testRepo/2',
112+
BITRISE_GIT_BRANCH: 'main',
113+
BITRISE_IO: 'true',
114+
BITRISE_PULL_REQUEST: '3',
115+
CI: 'true',
116+
GIT_CLONE_COMMIT_HASH: 'testingSha',
117+
},
118+
}
119+
const expected: IServiceParams = {
120+
branch: 'main',
121+
build: '2',
122+
buildURL: 'https://bitrise.com/testOrg/testRepo/2',
123+
commit: 'testingSha',
124+
job: '',
125+
pr: '3',
126+
service: 'bitrise',
127+
slug: 'testOrg/testRepo',
128+
}
129+
const spawnSync = td.replace(childProcess, 'spawnSync')
130+
td.when(
131+
spawnSync('git', ['config', '--get', 'remote.origin.url']),
132+
).thenReturn({ stdout: 'https://github.com/testOrg/testRepo.git' })
133+
const params = providerBitrise.getServiceParams(inputs)
134+
expect(params).toMatchObject(expected)
135+
})
136+
137+
// This should test that the provider outputs proper parameters when given overrides
138+
it('gets the correct params on overrides', () => {
139+
const inputs: UploaderInputs = {
140+
args: {
141+
...createEmptyArgs(),
142+
...{
143+
branch: 'test',
144+
build: '10',
145+
pr: '11',
146+
sha: 'otherTestingSha',
147+
slug: 'neworg/newRepo',
148+
},
149+
},
150+
environment: {
151+
BITRISE_BUILD_NUMBER: '2',
152+
BITRISE_BUILD_URL: 'https://bitrise.com/testOrg/testRepo/2',
153+
BITRISE_GIT_BRANCH: 'main',
154+
BITRISE_IO: 'true',
155+
BITRISE_PULL_REQUEST: '3',
156+
CI: 'true',
157+
GIT_CLONE_COMMIT_HASH: 'testingSha',
158+
},
159+
}
160+
const expected: IServiceParams = {
161+
branch: 'test',
162+
build: '10',
163+
buildURL: 'https://bitrise.com/testOrg/testRepo/2',
164+
commit: 'otherTestingSha',
165+
job: '',
166+
pr: '11',
167+
service: 'bitrise',
168+
slug: 'neworg/newRepo',
169+
}
170+
const spawnSync = td.replace(childProcess, 'spawnSync')
171+
td.when(
172+
spawnSync('git', ['config', '--get', 'remote.origin.url']),
173+
).thenReturn({ stdout: 'https://github.com/testOrg/testRepo.git' })
174+
const params = providerBitrise.getServiceParams(inputs)
175+
expect(params).toMatchObject(expected)
176+
})
177+
})

0 commit comments

Comments
 (0)