-
-
Notifications
You must be signed in to change notification settings - Fork 301
/
Copy pathJobArtifacts.ts
84 lines (71 loc) · 2.58 KB
/
JobArtifacts.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
import { BaseResource } from '@gitbeaker/requester-utils';
import { RequestHelper, endpoint } from '../infrastructure';
import type { GitlabAPIResponse, ShowExpanded, Sudo } from '../infrastructure';
import type { JobSchema } from './Jobs';
function generateDownloadPathForJob(
projectId: string | number,
jobId: number,
artifactPath?: string,
) {
let url = endpoint`projects/${projectId}/jobs/${jobId}/artifacts`;
if (artifactPath) url += `/${artifactPath}`;
return url;
}
function generateDownloadPath(projectId: string | number, ref: string, artifactPath?: string) {
let url = endpoint`projects/${projectId}/jobs/artifacts/${ref}`;
if (artifactPath) {
url += endpoint`/raw/${artifactPath}`;
} else {
url += endpoint`/download`;
}
return url;
}
export class JobArtifacts<C extends boolean = false> extends BaseResource<C> {
downloadArchive<E extends boolean = false>(
projectId: string | number,
{
jobId,
artifactPath,
ref,
...options
}: (
| { jobId: number; artifactPath?: undefined; job?: undefined; ref?: undefined }
| { jobId: number; artifactPath: string; job?: undefined; ref?: undefined }
| { ref: string; job: string; jobId?: undefined; artifactPath?: undefined }
| { ref: string; job: string; artifactPath: string; jobId?: undefined }
) & { jobToken?: string } & Sudo &
ShowExpanded<E> = {} as any,
): Promise<GitlabAPIResponse<Blob, void, E, void>> {
let url: string;
if (jobId) url = generateDownloadPathForJob(projectId, jobId, artifactPath);
else if (options?.job && ref) url = generateDownloadPath(projectId, ref, artifactPath);
else
throw new Error(
'Missing one of the required parameters. See typing documentation for available arguments.',
);
return RequestHelper.get<Blob>()(this, url, options);
}
keep<E extends boolean = false>(
projectId: string | number,
jobId: number,
options?: Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<JobSchema, C, E, void>> {
return RequestHelper.post<JobSchema>()(
this,
endpoint`projects/${projectId}/jobs/${jobId}/artifacts/keep`,
options,
);
}
remove<E extends boolean = false>(
projectId: string | number,
{ jobId, ...options }: { jobId?: number } & Sudo & ShowExpanded<E> = {},
): Promise<GitlabAPIResponse<void, C, E, void>> {
let url: string;
if (jobId) {
url = endpoint`projects/${projectId}/jobs/${jobId}/artifacts`;
} else {
url = endpoint`projects/${projectId}/artifacts`;
}
return RequestHelper.del()(this, url, options);
}
}