Skip to content

Commit 677c7ca

Browse files
authored
Merge pull request #231 from codecov/fix-local-no-git
fix: Try to use args before git
2 parents 2daa7d4 + c946b02 commit 677c7ca

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

src/ci_providers/provider_local.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ function _getBuildURL(inputs) {
1717

1818
function _getBranch(inputs) {
1919
const { args } = inputs
20+
if (args.branch) {
21+
return args.branch
22+
}
2023
try {
2124
const branchName = childprocess
2225
.spawnSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'])
2326
.stdout.toString()
2427
.trimRight()
25-
return args.branch || branchName
28+
return branchName
2629
} catch (error) {
2730
throw new Error(
2831
`There was an error getting the branch name from git: ${error}`,
@@ -53,12 +56,15 @@ function getServiceName() {
5356

5457
function _getSHA(inputs) {
5558
const { args } = inputs
59+
if (args.sha) {
60+
return args.sha
61+
}
5662
try {
5763
const sha = childprocess
5864
.spawnSync('git', ['rev-parse', 'HEAD'])
5965
.stdout.toString()
6066
.trimRight()
61-
return args.sha || sha
67+
return sha
6268
} catch (error) {
6369
throw new Error(
6470
`There was an error getting the commit SHA from git: ${error}`,
@@ -68,12 +74,15 @@ function _getSHA(inputs) {
6874

6975
function _getSlug(inputs) {
7076
const { args } = inputs
77+
if (args.slug) {
78+
return args.slug
79+
}
7180
try {
7281
const slug = childprocess
7382
.spawnSync('git', ['config', '--get', 'remote.origin.url'])
7483
.stdout.toString()
7584
.trimRight()
76-
return args.slug || parseSlug(slug)
85+
return parseSlug(slug)
7786
} catch (error) {
7887
throw new Error(`There was an error getting the slug from git: ${error}`)
7988
}

test/providers/provider_local.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,30 @@ describe('Local Params', () => {
3232
})
3333
})
3434

35+
it('returns on override args', () => {
36+
const inputs = {
37+
args: {
38+
branch: 'main',
39+
pr: '1',
40+
sha: 'testingsha',
41+
slug: 'owner/repo',
42+
},
43+
envs: {},
44+
}
45+
const expected = {
46+
branch: 'main',
47+
build: '',
48+
buildURL: '',
49+
commit: 'testingsha',
50+
job: '',
51+
pr: '1',
52+
service: '',
53+
slug: 'owner/repo',
54+
}
55+
const params = providerLocal.getServiceParams(inputs)
56+
expect(params).toMatchObject(expected)
57+
})
58+
3559
it('returns errors on git command failures', () => {
3660
const inputs = {
3761
args: {},

0 commit comments

Comments
 (0)