Skip to content

Commit 34bc976

Browse files
committed
fix: codebuild args
1 parent 8895a01 commit 34bc976

File tree

2 files changed

+55
-13
lines changed

2 files changed

+55
-13
lines changed

src/ci_providers/provider_codebuild.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ function _getBuildURL(inputs) {
1414

1515
function _getBranch(inputs) {
1616
const { args, envs } = inputs
17-
return args.branch || envs.CODEBUILD_WEBHOOK_HEAD_REF
18-
? envs.CODEBUILD_WEBHOOK_HEAD_REF.replace(/^refs\/heads\//, '')
19-
: ''
17+
return (
18+
args.branch ||
19+
(envs.CODEBUILD_WEBHOOK_HEAD_REF
20+
? envs.CODEBUILD_WEBHOOK_HEAD_REF.replace(/^refs\/heads\//, '')
21+
: '')
22+
)
2023
}
2124

2225
function _getJob(envs) {
@@ -25,11 +28,13 @@ function _getJob(envs) {
2528

2629
function _getPR(inputs) {
2730
const { args, envs } = inputs
28-
return args.pr ||
31+
return (
32+
args.pr ||
2933
(envs.CODEBUILD_WEBHOOK_HEAD_REF &&
30-
envs.CODEBUILD_SOURCE_VERSION.startsWith('pr/'))
31-
? envs.CODEBUILD_SOURCE_VERSION.replace(/^pr\//, '')
32-
: ''
34+
envs.CODEBUILD_SOURCE_VERSION.startsWith('pr/')
35+
? envs.CODEBUILD_SOURCE_VERSION.replace(/^pr\//, '')
36+
: '')
37+
)
3338
}
3439

3540
function _getService() {
@@ -47,12 +52,15 @@ function _getSHA(inputs) {
4752

4853
function _getSlug(inputs) {
4954
const { args, envs } = inputs
50-
return args.slug || envs.CODEBUILD_SOURCE_REPO_URL
51-
? envs.CODEBUILD_SOURCE_REPO_URL.replace(/^.*github.com\//, '').replace(
52-
/\.git$/,
53-
'',
54-
)
55-
: ''
55+
return (
56+
args.slug ||
57+
(envs.CODEBUILD_SOURCE_REPO_URL
58+
? envs.CODEBUILD_SOURCE_REPO_URL.replace(/^.*github.com\//, '').replace(
59+
/\.git$/,
60+
'',
61+
)
62+
: '')
63+
)
5664
}
5765

5866
function getServiceParams(inputs) {

test/providers/provider_codebuild.test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,38 @@ describe('CodeBuild Params', () => {
5656
const params = providerCodeBuild.getServiceParams(inputs)
5757
expect(params).toMatchObject(expected)
5858
})
59+
60+
it('gets correct params for overrides', () => {
61+
const inputs = {
62+
args: {
63+
branch: 'branch',
64+
build: 3,
65+
pr: '7',
66+
sha: 'testsha',
67+
slug: 'testOrg/testRepo',
68+
},
69+
envs: {
70+
CI: true,
71+
CODEBUILD_CI: true,
72+
CODEBUILD_WEBHOOK_HEAD_REF: 'refs/heads/master',
73+
CODEBUILD_RESOLVED_SOURCE_VERSION: 'testingsha',
74+
CODEBUILD_BUILD_ID: 2,
75+
CODEBUILD_SOURCE_VERSION: 'pr/1',
76+
CODEBUILD_SOURCE_REPO_URL: 'https://github.com/repo.git',
77+
},
78+
}
79+
const expected = {
80+
branch: 'branch',
81+
build: 3,
82+
buildURL: '',
83+
commit: 'testsha',
84+
job: 2,
85+
pr: '7',
86+
service: 'codebuild',
87+
slug: 'testOrg/testRepo',
88+
}
89+
90+
const params = providerCodeBuild.getServiceParams(inputs)
91+
expect(params).toMatchObject(expected)
92+
})
5993
})

0 commit comments

Comments
 (0)