From cfb2ac43b0354b1ca4582c5d39892df62528785f Mon Sep 17 00:00:00 2001 From: Tom Hu Date: Wed, 21 Jul 2021 14:26:41 -0700 Subject: [PATCH] fix: Add default Teamcity slug --- src/ci_providers/provider_teamcity.js | 4 +- test/providers/provider_teamcity.test.js | 50 ++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/ci_providers/provider_teamcity.js b/src/ci_providers/provider_teamcity.js index 036db72ba..828f7503d 100644 --- a/src/ci_providers/provider_teamcity.js +++ b/src/ci_providers/provider_teamcity.js @@ -1,3 +1,5 @@ +const { parseSlugFromRemoteAddr } = require('../helpers/git') + function detect(envs) { return !!envs.TEAMCITY_VERSION } @@ -29,7 +31,7 @@ function _getSHA(inputs) { function _getSlug(inputs) { const { args } = inputs - return args.slug || '' + return args.slug || parseSlugFromRemoteAddr('') || '' } function _getBuild(inputs) { diff --git a/test/providers/provider_teamcity.test.js b/test/providers/provider_teamcity.test.js index c8ca7ddff..9362fc8bc 100644 --- a/test/providers/provider_teamcity.test.js +++ b/test/providers/provider_teamcity.test.js @@ -1,4 +1,5 @@ const td = require('testdouble') +const childProcess = require('child_process') const providerTeamCity = require('../../src/ci_providers/provider_teamcity') @@ -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) }) @@ -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,