Skip to content

Commit

Permalink
Merge pull request #220 from codecov/fix-jenkins-slug
Browse files Browse the repository at this point in the history
fix: Add default Jenkins slug
  • Loading branch information
thomasrockhu authored Jul 20, 2021
2 parents 2e3228a + f45dc7f commit 3e1beda
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 16 deletions.
4 changes: 3 additions & 1 deletion 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 @@ -48,7 +50,7 @@ function _getSHA(inputs) {

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

function getServiceParams(inputs) {
Expand Down
9 changes: 3 additions & 6 deletions src/helpers/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,13 @@ function parseSlug(slug) {
function parseSlugFromRemoteAddr(remoteAddr) {
let slug = ''
if (!remoteAddr) {
remoteAddr = childProcess
remoteAddr = (childProcess
.spawnSync('git', [
'config',
'--get',
'remote.origin.url',
'||',
'echo',
"''",
])
.stdout.toString()
]).stdout || '')
.toString()
.trimRight()
}
if (remoteAddr) {
Expand Down
17 changes: 8 additions & 9 deletions test/providers/provider_gitlabci.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ describe('GitLabCI Params', () => {
service: 'gitlab',
slug: '',
}
const spawnSync = td.replace(childProcess, 'spawnSync')
td.when(
spawnSync('git', [
'config',
'--get',
'remote.origin.url',
]),
).thenReturn({ stdout: '' })
const params = providerGitLabci.getServiceParams(inputs)
expect(params).toMatchObject(expected)
})
Expand Down Expand Up @@ -132,9 +140,6 @@ describe('GitLabCI Params', () => {
'config',
'--get',
'remote.origin.url',
'||',
'echo',
"''",
]),
).thenReturn({ stdout: 'https://gitlab.com/testOrg/testRepo.git' })

Expand All @@ -150,9 +155,6 @@ describe('GitLabCI Params', () => {
'config',
'--get',
'remote.origin.url',
'||',
'echo',
"''",
]),
).thenReturn({ stdout: 'git@gitlab.com:/' })

Expand All @@ -168,9 +170,6 @@ describe('GitLabCI Params', () => {
'config',
'--get',
'remote.origin.url',
'||',
'echo',
"''",
]),
).thenReturn({ stdout: '' })

Expand Down
34 changes: 34 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 @@ -76,10 +77,43 @@ describe('Jenkins CI Params', () => {
service: 'jenkins',
slug: '',
}
const spawnSync = td.replace(childProcess, 'spawnSync')
td.when(
spawnSync('git', [
'config',
'--get',
'remote.origin.url',
]),
).thenReturn({ stdout: '' })
const params = providerJenkinsci.getServiceParams(inputs)
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',
]),
).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 3e1beda

Please sign in to comment.