Skip to content

Commit cfb2ac4

Browse files
committed
fix: Add default Teamcity slug
1 parent e9cfaf5 commit cfb2ac4

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

src/ci_providers/provider_teamcity.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const { parseSlugFromRemoteAddr } = require('../helpers/git')
2+
13
function detect(envs) {
24
return !!envs.TEAMCITY_VERSION
35
}
@@ -29,7 +31,7 @@ function _getSHA(inputs) {
2931

3032
function _getSlug(inputs) {
3133
const { args } = inputs
32-
return args.slug || ''
34+
return args.slug || parseSlugFromRemoteAddr('') || ''
3335
}
3436

3537
function _getBuild(inputs) {

test/providers/provider_teamcity.test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const td = require('testdouble')
2+
const childProcess = require('child_process')
23

34
const providerTeamCity = require('../../src/ci_providers/provider_teamcity')
45

@@ -51,6 +52,47 @@ describe('TeamCity Params', () => {
5152
service: 'teamcity',
5253
slug: '',
5354
}
55+
const spawnSync = td.replace(childProcess, 'spawnSync')
56+
td.when(
57+
spawnSync('git', [
58+
'config',
59+
'--get',
60+
'remote.origin.url',
61+
]),
62+
).thenReturn({ stdout: '' })
63+
const params = providerTeamCity.getServiceParams(inputs)
64+
expect(params).toMatchObject(expected)
65+
})
66+
67+
it('gets correct params and remote slug', () => {
68+
const inputs = {
69+
args: {},
70+
envs: {
71+
CI: true,
72+
TEAMCITY_VERSION: true,
73+
BRANCH_NAME: 'main',
74+
BUILD_VCS_NUMBER: 'testingsha',
75+
BUILD_NUMBER: 1,
76+
},
77+
}
78+
const expected = {
79+
branch: 'main',
80+
build: 1,
81+
buildURL: '',
82+
commit: 'testingsha',
83+
job: '',
84+
pr: '',
85+
service: 'teamcity',
86+
slug: 'testOrg/testRepo',
87+
}
88+
const spawnSync = td.replace(childProcess, 'spawnSync')
89+
td.when(
90+
spawnSync('git', [
91+
'config',
92+
'--get',
93+
'remote.origin.url',
94+
]),
95+
).thenReturn({ stdout: 'https://github.com/testOrg/testRepo.git' })
5496
const params = providerTeamCity.getServiceParams(inputs)
5597
expect(params).toMatchObject(expected)
5698
})
@@ -72,6 +114,14 @@ describe('TeamCity Params', () => {
72114
BUILD_NUMBER: 1,
73115
},
74116
}
117+
const spawnSync = td.replace(childProcess, 'spawnSync')
118+
td.when(
119+
spawnSync('git', [
120+
'config',
121+
'--get',
122+
'remote.origin.url',
123+
]),
124+
).thenReturn({ stdout: '' })
75125
const expected = {
76126
branch: 'branch',
77127
build: 3,

0 commit comments

Comments
 (0)