Skip to content

Commit 54a2666

Browse files
committed
fix: Use remote address not VCS
1 parent 3d9e84a commit 54a2666

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/ci_providers/provider_jenkinsci.js

Lines changed: 4 additions & 2 deletions
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.JENKINS_URL
35
}
@@ -47,8 +49,8 @@ function _getSHA(inputs) {
4749
}
4850

4951
function _getSlug(inputs) {
50-
const { args, envs } = inputs
51-
return args.slug || envs.VCS_SLUG || ''
52+
const { args } = inputs
53+
return args.slug || parseSlugFromRemoteAddr('') || ''
5254
}
5355

5456
function getServiceParams(inputs) {

test/providers/provider_jenkinsci.test.js

Lines changed: 29 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 providerJenkinsci = require('../../src/ci_providers//provider_jenkinsci')
45

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

84+
it('can get the slug from git config', () => {
85+
const inputs = {
86+
args: {},
87+
envs: {
88+
BUILD_NUMBER: 1,
89+
BUILD_URL: 'https://example.jenkins.com',
90+
CHANGE_ID: 2,
91+
GIT_BRANCH: 'main',
92+
GIT_COMMIT: 'testingsha',
93+
JENKINS_URL: 'https://example.com',
94+
},
95+
}
96+
const spawnSync = td.replace(childProcess, 'spawnSync')
97+
td.when(
98+
spawnSync('git', [
99+
'config',
100+
'--get',
101+
'remote.origin.url',
102+
'||',
103+
'echo',
104+
"''",
105+
]),
106+
).thenReturn({ stdout: 'https://github.com/testOrg/testRepo.git' })
107+
108+
const params = providerJenkinsci.getServiceParams(inputs)
109+
expect(params.slug).toBe('testOrg/testRepo')
110+
})
111+
83112
it('gets correct params for overrides', () => {
84113
const inputs = {
85114
args: {

0 commit comments

Comments
 (0)