Skip to content

Commit

Permalink
Merge pull request #232 from codecov/fix-teamcity-slug
Browse files Browse the repository at this point in the history
fix: Add default Teamcity slug
  • Loading branch information
thomasrockhu authored Jul 22, 2021
2 parents 5ea4a34 + cfb2ac4 commit 2daa7d4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ci_providers/provider_teamcity.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { parseSlugFromRemoteAddr } = require('../helpers/git')

function detect(envs) {
return !!envs.TEAMCITY_VERSION
}
Expand Down Expand Up @@ -29,7 +31,7 @@ function _getSHA(inputs) {

function _getSlug(inputs) {
const { args } = inputs
return args.slug || ''
return args.slug || parseSlugFromRemoteAddr('') || ''
}

function _getBuild(inputs) {
Expand Down
50 changes: 50 additions & 0 deletions test/providers/provider_teamcity.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const td = require('testdouble')
const childProcess = require('child_process')

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

Expand Down Expand Up @@ -51,6 +52,47 @@ describe('TeamCity Params', () => {
service: 'teamcity',
slug: '',
}
const spawnSync = td.replace(childProcess, 'spawnSync')
td.when(
spawnSync('git', [
'config',
'--get',
'remote.origin.url',
]),
).thenReturn({ stdout: '' })
const params = providerTeamCity.getServiceParams(inputs)
expect(params).toMatchObject(expected)
})

it('gets correct params and remote slug', () => {
const inputs = {
args: {},
envs: {
CI: true,
TEAMCITY_VERSION: true,
BRANCH_NAME: 'main',
BUILD_VCS_NUMBER: 'testingsha',
BUILD_NUMBER: 1,
},
}
const expected = {
branch: 'main',
build: 1,
buildURL: '',
commit: 'testingsha',
job: '',
pr: '',
service: 'teamcity',
slug: 'testOrg/testRepo',
}
const spawnSync = td.replace(childProcess, 'spawnSync')
td.when(
spawnSync('git', [
'config',
'--get',
'remote.origin.url',
]),
).thenReturn({ stdout: 'https://github.com/testOrg/testRepo.git' })
const params = providerTeamCity.getServiceParams(inputs)
expect(params).toMatchObject(expected)
})
Expand All @@ -72,6 +114,14 @@ describe('TeamCity Params', () => {
BUILD_NUMBER: 1,
},
}
const spawnSync = td.replace(childProcess, 'spawnSync')
td.when(
spawnSync('git', [
'config',
'--get',
'remote.origin.url',
]),
).thenReturn({ stdout: '' })
const expected = {
branch: 'branch',
build: 3,
Expand Down

0 comments on commit 2daa7d4

Please sign in to comment.