This repository was 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
Expand file tree
/
Copy pathprovider_local.ts
More file actions
101 lines (89 loc) · 2.38 KB
/
provider_local.ts
File metadata and controls
101 lines (89 loc) · 2.38 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
import { parseSlug } from '../helpers/git'
import { isProgramInstalled, runExternalProgram } from '../helpers/util'
import { IServiceParams, UploaderInputs } from '../types'
// This provider requires git to be installed
export function detect(): boolean {
return isProgramInstalled('git')
}
function _getBuild(inputs: UploaderInputs): string {
const { args } = inputs
return args.build || ''
}
function _getBuildURL(): string {
return ''
}
function _getBranch(inputs: UploaderInputs): string {
const { args, environment: envs } = inputs
const branch = args.branch || envs.GIT_BRANCH || envs.BRANCH_NAME || ''
if (branch !== '') {
return branch
}
try {
const branchName = runExternalProgram('git', ['rev-parse', '--abbrev-ref', 'HEAD'])
return branchName
} catch (error) {
throw new Error(
`There was an error getting the branch name from git: ${error}`,
)
}
}
function _getJob(): string {
return ''
}
function _getPR(inputs: UploaderInputs): string {
const { args } = inputs
return args.pr || ''
}
// This is the value that gets passed to the codasove uploader
function _getService(): string {
return ''
}
// This is the name that gets printed
export function getServiceName(): string {
return 'Local'
}
function _getSHA(inputs: UploaderInputs) {
const { args, environment: envs } = inputs
const sha = args.sha || envs.GIT_COMMIT || ''
if (sha !== '') {
return sha
}
try {
const sha = runExternalProgram('git', ['rev-parse', 'HEAD'])
return sha
} catch (error) {
throw new Error(`There was an error getting the commit SHA from git: ${error}`)
}
}
function _getSlug(inputs: UploaderInputs): string {
const { args } = inputs
if (args.slug) {
return args.slug
}
try {
const slug = runExternalProgram('git', ['config', '--get', 'remote.origin.url'])
return parseSlug(slug)
} catch (error) {
throw new Error(`There was an error getting the slug from git: ${error}`)
}
}
export function getServiceParams(inputs: UploaderInputs): IServiceParams {
return {
branch: _getBranch(inputs),
build: _getBuild(inputs),
buildURL: _getBuildURL(),
commit: _getSHA(inputs),
job: _getJob(),
pr: _getPR(inputs),
service: _getService(),
slug: _getSlug(inputs),
}
}
export function getEnvVarNames(): string[] {
return [
'BRANCH_NAME',
'CI',
'GIT_BRANCH',
'GIT_COMMIT',
]
}