Skip to content

Commit 428c1a1

Browse files
Merge pull request #196 from eddiemoore/feature/provider-teamcity
Adding TeamCity provider
2 parents 245e57f + 1821182 commit 428c1a1

File tree

3 files changed

+158
-0
lines changed

3 files changed

+158
-0
lines changed

src/ci_providers/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const providerGitHubactions = require('./provider_githubactions')
99
const providerGitLabci = require('./provider_gitlabci')
1010
const providerJenkinsci = require('./provider_jenkinsci')
1111
const providerLocal = require('./provider_local')
12+
const providerTeamCity = require('./provider_teamcity')
1213
const providerTravisci = require('./provider_travisci')
1314
const providerWercker = require('./provider_wercker')
1415

@@ -24,6 +25,7 @@ const providers = [
2425
providerGitHubactions,
2526
providerGitLabci,
2627
providerJenkinsci,
28+
providerTeamCity,
2729
providerTravisci,
2830
providerWercker,
2931
providerLocal,

src/ci_providers/provider_teamcity.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
function detect(envs) {
2+
return !!envs.TEAMCITY_VERSION
3+
}
4+
5+
// eslint-disable-next-line no-unused-vars
6+
function _getBuildURL(inputs) {
7+
return ''
8+
}
9+
10+
// This is the value that gets passed to the Codecov uploader
11+
function _getService() {
12+
return 'teamcity'
13+
}
14+
15+
// This is the name that gets printed
16+
function getServiceName() {
17+
return 'TeamCity'
18+
}
19+
20+
function _getBranch(inputs) {
21+
const { args, envs } = inputs
22+
return args.branch || envs.BRANCH_NAME
23+
}
24+
25+
function _getSHA(inputs) {
26+
const { args, envs } = inputs
27+
return args.sha || envs.BUILD_VCS_NUMBER
28+
}
29+
30+
function _getSlug(inputs) {
31+
const { args } = inputs
32+
return args.slug || ''
33+
}
34+
35+
function _getBuild(inputs) {
36+
const { args, envs } = inputs
37+
return args.build || envs.BUILD_NUMBER || ''
38+
}
39+
40+
function _getPR(inputs) {
41+
const { args } = inputs
42+
return args.pr || ''
43+
}
44+
45+
// eslint-disable-next-line no-unused-vars
46+
function _getJob(envs) {
47+
return ''
48+
}
49+
50+
function getServiceParams(inputs) {
51+
return {
52+
branch: _getBranch(inputs),
53+
build: _getBuild(inputs),
54+
buildURL: _getBuildURL(inputs),
55+
commit: _getSHA(inputs),
56+
job: _getJob(inputs.envs),
57+
pr: _getPR(inputs),
58+
service: _getService(),
59+
slug: _getSlug(inputs),
60+
}
61+
}
62+
63+
module.exports = {
64+
detect,
65+
getServiceName,
66+
getServiceParams,
67+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
const td = require('testdouble')
2+
3+
const providerTeamCity = require('../../src/ci_providers/provider_teamcity')
4+
5+
describe('TeamCity Params', () => {
6+
afterEach(() => {
7+
td.reset()
8+
})
9+
10+
describe('detect()', () => {
11+
it('does not run without TeamCity env variable', () => {
12+
const inputs = {
13+
args: {},
14+
envs: {},
15+
}
16+
let detected = providerTeamCity.detect(inputs.envs)
17+
expect(detected).toBeFalsy()
18+
})
19+
20+
it('does run with TeamCity env variable', () => {
21+
const inputs = {
22+
args: {},
23+
envs: {
24+
CI: true,
25+
TEAMCITY_VERSION: true,
26+
},
27+
}
28+
const detected = providerTeamCity.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+
TEAMCITY_VERSION: true,
39+
BRANCH_NAME: 'main',
40+
BUILD_VCS_NUMBER: 'testingsha',
41+
BUILD_NUMBER: 1,
42+
},
43+
}
44+
const expected = {
45+
branch: 'main',
46+
build: 1,
47+
buildURL: '',
48+
commit: 'testingsha',
49+
job: '',
50+
pr: '',
51+
service: 'teamcity',
52+
slug: '',
53+
}
54+
const params = providerTeamCity.getServiceParams(inputs)
55+
expect(params).toMatchObject(expected)
56+
})
57+
58+
it('gets correct params for overrides', () => {
59+
const inputs = {
60+
args: {
61+
branch: 'branch',
62+
build: 3,
63+
pr: '2',
64+
sha: 'testsha',
65+
slug: 'testOrg/testRepo',
66+
},
67+
envs: {
68+
CI: true,
69+
TEAMCITY_VERSION: true,
70+
BRANCH_NAME: 'main',
71+
BUILD_VCS_NUMBER: 'testingsha',
72+
BUILD_NUMBER: 1,
73+
},
74+
}
75+
const expected = {
76+
branch: 'branch',
77+
build: 3,
78+
buildURL: '',
79+
commit: 'testsha',
80+
job: '',
81+
pr: '2',
82+
service: 'teamcity',
83+
slug: 'testOrg/testRepo',
84+
}
85+
86+
const params = providerTeamCity.getServiceParams(inputs)
87+
expect(params).toMatchObject(expected)
88+
})
89+
})

0 commit comments

Comments
 (0)