forked from DataDog/datadog-ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterfaces.ts
90 lines (81 loc) · 2.34 KB
/
interfaces.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
89
90
import fs from 'fs'
import {MultipartPayload, MultipartValue} from '../../helpers/upload'
export class Sourcemap {
public gitData?: GitData
public minifiedFilePath: string
public minifiedPathPrefix?: string
public minifiedUrl: string
public relativePath: string
public sourcemapPath: string
constructor(
minifiedFilePath: string,
minifiedUrl: string,
sourcemapPath: string,
relativePath: string,
minifiedPathPrefix?: string
) {
this.minifiedFilePath = minifiedFilePath
this.minifiedPathPrefix = minifiedPathPrefix
this.minifiedUrl = minifiedUrl
this.relativePath = relativePath
this.sourcemapPath = sourcemapPath
}
public addRepositoryData(gitData: GitData) {
this.gitData = gitData
}
public asMultipartPayload(
cliVersion: string,
service: string,
version: string,
projectPath: string
): MultipartPayload {
const content = new Map<string, MultipartValue>([
['event', this.getMetadataPayload(cliVersion, service, version, projectPath)],
['source_map', {value: fs.createReadStream(this.sourcemapPath), options: {filename: 'source_map'}}],
['minified_file', {value: fs.createReadStream(this.minifiedFilePath), options: {filename: 'minified_file'}}],
])
if (this.gitData !== undefined && this.gitData.gitRepositoryPayload !== undefined) {
content.set('repository', {
options: {
contentType: 'application/json',
filename: 'repository',
},
value: this.gitData.gitRepositoryPayload,
})
}
return {
content,
}
}
private getMetadataPayload(
cliVersion: string,
service: string,
version: string,
projectPath: string
): MultipartValue {
const metadata: {[k: string]: any} = {
cli_version: cliVersion,
minified_url: this.minifiedUrl,
project_path: projectPath,
service,
type: 'js_sourcemap',
version,
}
if (this.gitData !== undefined) {
metadata.git_repository_url = this.gitData.gitRepositoryURL
metadata.git_commit_sha = this.gitData.gitCommitSha
}
return {
options: {
contentType: 'application/json',
filename: 'event',
},
value: JSON.stringify(metadata),
}
}
}
export interface GitData {
gitCommitSha: string
gitRepositoryPayload?: string
gitRepositoryURL: string
}