This repository has been archived by the owner on Sep 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider_codebuild.ts
88 lines (76 loc) · 2.23 KB
/
provider_codebuild.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { IServiceParams, UploaderEnvs, UploaderInputs } from '../types'
export function detect(envs: UploaderEnvs): boolean {
return Boolean(envs.CODEBUILD_CI)
}
function _getBuild(inputs: UploaderInputs): string {
const { args, environment: envs } = inputs
return args.build || envs.CODEBUILD_BUILD_ID || ''
}
function _getBuildURL(): string {
return ''
}
function _getBranch(inputs: UploaderInputs): string {
const { args, environment: envs } = inputs
return (
args.branch ||
(envs.CODEBUILD_WEBHOOK_HEAD_REF
? envs.CODEBUILD_WEBHOOK_HEAD_REF.replace(/^refs\/heads\//, '')
: '')
)
}
function _getJob(envs: UploaderEnvs): string {
return envs.CODEBUILD_BUILD_ID || ''
}
function _getPR(inputs: UploaderInputs): string {
const { args, environment: envs } = inputs
return (
args.pr ||
(envs.CODEBUILD_SOURCE_VERSION &&
envs.CODEBUILD_SOURCE_VERSION.startsWith('pr/')
? envs.CODEBUILD_SOURCE_VERSION.replace(/^pr\//, '')
: ''
))
}
function _getService(): string {
return 'codebuild'
}
export function getServiceName(): string {
return 'AWS CodeBuild'
}
function _getSHA(inputs: UploaderInputs): string {
const { args, environment: envs } = inputs
return args.sha || envs.CODEBUILD_RESOLVED_SOURCE_VERSION || ''
}
function _getSlug(inputs: UploaderInputs): string {
const { args, environment: envs } = inputs
if (args.slug !== '') return args.slug
return (
(envs.CODEBUILD_SOURCE_REPO_URL
? envs.CODEBUILD_SOURCE_REPO_URL.toString()
.replace(/^.*github.com\//, '') // lgtm [js/incomplete-hostname-regexp] - We want this to match all subdomains.
.replace(/\.git$/, '')
: '')
)
}
export function getServiceParams(inputs: UploaderInputs): IServiceParams {
return {
branch: _getBranch(inputs),
build: _getBuild(inputs),
buildURL: _getBuildURL(),
commit: _getSHA(inputs),
job: _getJob(inputs.environment),
pr: _getPR(inputs),
service: _getService(),
slug: _getSlug(inputs),
}
}
export function getEnvVarNames(): string[] {
return [
'CODEBUILD_BUILD_ID',
'CODEBUILD_CI',
'CODEBUILD_RESOLVED_SOURCE_VERSION',
'CODEBUILD_SOURCE_REPO_URL',
'CODEBUILD_SOURCE_VERSION',
'CODEBUILD_WEBHOOK_HEAD_REF',
]
}