-
Notifications
You must be signed in to change notification settings - Fork 55
/
utils.ts
53 lines (42 loc) · 1.64 KB
/
utils.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
import {lstatSync} from 'fs'
import {getCommonAppBaseURL} from '../../helpers/app'
import {SpanTags} from '../../helpers/interfaces'
import {CI_JOB_URL, CI_PIPELINE_URL, GIT_BRANCH, GIT_REPOSITORY_URL, GIT_SHA} from '../../helpers/tags'
export const getBaseUrl = () => {
const site = process.env.DATADOG_SITE || process.env.DD_SITE || 'datadoghq.com'
const subdomain = process.env.DD_SUBDOMAIN || ''
return getCommonAppBaseURL(site, subdomain)
}
export const getTestRunsUrl = (spanTags: SpanTags): string => {
if (!spanTags[CI_PIPELINE_URL] && !spanTags[CI_JOB_URL]) {
return ''
}
let query = ''
if (spanTags[CI_JOB_URL]) {
query += ` @ci.job.url:"${spanTags[CI_JOB_URL]}"`
} else if (spanTags[CI_PIPELINE_URL]) {
query += ` @ci.pipeline.url:"${spanTags[CI_PIPELINE_URL]}"`
}
return `${getBaseUrl()}ci/test-runs?query=${encodeURIComponent(query)}`
}
export const getTestCommitRedirectURL = (spanTags: SpanTags, service?: string, env?: string): string => {
if (!spanTags[GIT_REPOSITORY_URL] || !spanTags[GIT_BRANCH] || !spanTags[GIT_SHA] || !service) {
return ''
}
const encodedRepoUrl = encodeURIComponent(`${spanTags[GIT_REPOSITORY_URL]}`)
const encodedService = encodeURIComponent(service)
const encodedBranch = encodeURIComponent(`${spanTags[GIT_BRANCH]}`)
const commitSha = `${spanTags[GIT_SHA]}`
let url = `${getBaseUrl()}ci/redirect/tests/${encodedRepoUrl}/-/${encodedService}/-/${encodedBranch}/-/${commitSha}`
if (env) {
url += `?env=${encodeURIComponent(env)}`
}
return url
}
export const isFile = (path: string) => {
try {
return lstatSync(path).isFile()
} catch (e) {
return false
}
}