Skip to content

Commit

Permalink
fix: Use remote address not VCS
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasrockhu committed Jul 19, 2021
1 parent 3d9e84a commit 54a2666
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/ci_providers/provider_jenkinsci.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.JENKINS_URL
}
Expand Down Expand Up @@ -47,8 +49,8 @@ function _getSHA(inputs) {
}

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

function getServiceParams(inputs) {
Expand Down
29 changes: 29 additions & 0 deletions test/providers/provider_jenkinsci.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 providerJenkinsci = require('../../src/ci_providers//provider_jenkinsci')

Expand Down Expand Up @@ -80,6 +81,34 @@ describe('Jenkins CI Params', () => {
expect(params).toMatchObject(expected)
})

it('can get the slug from git config', () => {
const inputs = {
args: {},
envs: {
BUILD_NUMBER: 1,
BUILD_URL: 'https://example.jenkins.com',
CHANGE_ID: 2,
GIT_BRANCH: 'main',
GIT_COMMIT: 'testingsha',
JENKINS_URL: 'https://example.com',
},
}
const spawnSync = td.replace(childProcess, 'spawnSync')
td.when(
spawnSync('git', [
'config',
'--get',
'remote.origin.url',
'||',

This comment has been minimized.

Copy link
@RA80533

RA80533 Jul 20, 2021

Contributor

Lines 102 to 104 are invalid arguments. Git is receiving the arguments rather than the shell which is what would typically interpret those.

'echo',
"''",
]),
).thenReturn({ stdout: 'https://github.com/testOrg/testRepo.git' })

const params = providerJenkinsci.getServiceParams(inputs)
expect(params.slug).toBe('testOrg/testRepo')
})

it('gets correct params for overrides', () => {
const inputs = {
args: {
Expand Down

0 comments on commit 54a2666

Please sign in to comment.