Skip to content

Commit

Permalink
Merge pull request #231 from codecov/fix-local-no-git
Browse files Browse the repository at this point in the history
fix: Try to use args before git
  • Loading branch information
thomasrockhu authored Jul 22, 2021
2 parents 2daa7d4 + c946b02 commit 677c7ca
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/ci_providers/provider_local.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ function _getBuildURL(inputs) {

function _getBranch(inputs) {
const { args } = inputs
if (args.branch) {
return args.branch
}
try {
const branchName = childprocess
.spawnSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'])
.stdout.toString()
.trimRight()
return args.branch || branchName
return branchName
} catch (error) {
throw new Error(
`There was an error getting the branch name from git: ${error}`,
Expand Down Expand Up @@ -53,12 +56,15 @@ function getServiceName() {

function _getSHA(inputs) {
const { args } = inputs
if (args.sha) {
return args.sha
}
try {
const sha = childprocess
.spawnSync('git', ['rev-parse', 'HEAD'])
.stdout.toString()
.trimRight()
return args.sha || sha
return sha
} catch (error) {
throw new Error(
`There was an error getting the commit SHA from git: ${error}`,
Expand All @@ -68,12 +74,15 @@ function _getSHA(inputs) {

function _getSlug(inputs) {
const { args } = inputs
if (args.slug) {
return args.slug
}
try {
const slug = childprocess
.spawnSync('git', ['config', '--get', 'remote.origin.url'])
.stdout.toString()
.trimRight()
return args.slug || parseSlug(slug)
return parseSlug(slug)
} catch (error) {
throw new Error(`There was an error getting the slug from git: ${error}`)
}
Expand Down
24 changes: 24 additions & 0 deletions test/providers/provider_local.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,30 @@ describe('Local Params', () => {
})
})

it('returns on override args', () => {
const inputs = {
args: {
branch: 'main',
pr: '1',
sha: 'testingsha',
slug: 'owner/repo',
},
envs: {},
}
const expected = {
branch: 'main',
build: '',
buildURL: '',
commit: 'testingsha',
job: '',
pr: '1',
service: '',
slug: 'owner/repo',
}
const params = providerLocal.getServiceParams(inputs)
expect(params).toMatchObject(expected)
})

it('returns errors on git command failures', () => {
const inputs = {
args: {},
Expand Down

0 comments on commit 677c7ca

Please sign in to comment.