This repository was archived by the owner on Feb 19, 2020. It is now read-only.
forked from codecov/sourcegraph-codecov
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathsettings.ts
More file actions
60 lines (54 loc) · 1.79 KB
/
settings.ts
File metadata and controls
60 lines (54 loc) · 1.79 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
/**
* The resolved and normalized settings for this extension, the result of calling resolveSettings on a raw settings
* value.
*
* See the configuration JSON Schema in extension.json for the canonical documentation on these properties.
*/
export interface Settings {
['codecov.showCoverage']: boolean
['codecov.decorations.lineCoverage']: boolean
['codecov.decorations.lineHitCounts']: boolean
['codecov.endpoints']: Endpoint[]
}
/** Returns a copy of the extension settings with values normalized and defaults applied. */
export function resolveSettings(raw: Partial<Settings>): Settings {
return {
['codecov.showCoverage']: raw['codecov.showCoverage'] !== false,
['codecov.decorations.lineCoverage']: !!raw[
'codecov.decorations.lineCoverage'
],
['codecov.decorations.lineHitCounts']: !!raw[
'codecov.decorations.lineHitCounts'
],
['codecov.endpoints']: [resolveEndpoint(raw['codecov.endpoints'])]
}
}
export interface Endpoint {
url?: string
token?: string
service?: string
}
const CODECOV_IO_URL = 'https://codecov.io'
/**
* Returns the configured endpoint with values normalized and defaults applied.
*
* @todo support more than 1 endpoint
*/
export function resolveEndpoint(
endpoints?: Readonly<Endpoint[]>
): Readonly<Endpoint> {
if (!endpoints || endpoints.length === 0) {
return { url: CODECOV_IO_URL }
}
return {
url: endpoints[0].url
? urlWithOnlyProtocolAndHost(endpoints[0].url)
: CODECOV_IO_URL,
token: endpoints[0].token || undefined,
service: endpoints[0].service || undefined
}
}
function urlWithOnlyProtocolAndHost(urlStr: string): string {
const url = new URL(urlStr)
return `${url.protocol}//${url.host}`
}