-
-
Notifications
You must be signed in to change notification settings - Fork 297
/
ProjectImportExports.ts
157 lines (145 loc) · 4.23 KB
/
ProjectImportExports.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import { BaseResource } from '@gitbeaker/requester-utils';
import { RequestHelper, endpoint } from '../infrastructure';
import type { AsStream, GitlabAPIResponse, ShowExpanded, Sudo } from '../infrastructure';
export interface ExportStatusSchema extends Record<string, unknown> {
id: number;
description: string;
name: string;
name_with_namespace: string;
path: string;
path_with_namespace: string;
created_at: string;
export_status: string;
_links: {
api_url: string;
web_url: string;
};
}
export interface FailedRelationSchema {
id: number;
created_at: string;
exception_class: string;
exception_message: string;
source: string;
relation_name: string;
}
export interface ImportStatusSchema extends Record<string, unknown> {
id: number;
description: string;
name: string;
name_with_namespace: string;
path: string;
path_with_namespace: string;
created_at: string;
import_status: string;
correlation_id: string;
failed_relations?: FailedRelationSchema[];
import_error?: string;
}
export class ProjectImportExports<C extends boolean = false> extends BaseResource<C> {
download<E extends boolean = false>(
projectId: string | number,
options: { asStream: true } & Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<ReadableStream, void, E, void>>;
download<E extends boolean = false>(
projectId: string | number,
options?: { asStream?: boolean } & Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<Blob, void, E, void>>;
download<E extends boolean = false>(
projectId: string | number,
options?: AsStream & ShowExpanded<E> & Sudo,
): Promise<any> {
return RequestHelper.get<Blob | ReadableStream>()(
this,
endpoint`projects/${projectId}/export/download`,
options,
);
}
import<E extends boolean = false>(
file: { content: Blob; filename: string },
path: string,
options?: {
name?: string;
namespace?: number | string;
overrideParams?: Record<string, unknown>;
overwrite?: boolean;
} & Sudo &
ShowExpanded<E>,
): Promise<GitlabAPIResponse<ImportStatusSchema, C, E, void>> {
return RequestHelper.post<ImportStatusSchema>()(this, 'projects/import', {
isForm: true,
...options,
file: [file.content, file.filename],
path,
});
}
importRemote<E extends boolean = false>(
url: string,
path: string,
options?: {
name?: number;
namespace?: number | string;
overrideParams?: Record<string, unknown>;
overwrite?: boolean;
} & Sudo &
ShowExpanded<E>,
): Promise<GitlabAPIResponse<ImportStatusSchema, C, E, void>> {
return RequestHelper.post<ImportStatusSchema>()(this, 'projects/remote-import', {
...options,
path,
url,
});
}
importRemoteS3<E extends boolean = false>(
accessKeyId: string,
bucketName: string,
fileKey: string,
path: string,
region: string,
secretAccessKey: string,
options?: { name?: number; namespace?: number | string } & Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<ImportStatusSchema, C, E, void>> {
return RequestHelper.post<ImportStatusSchema>()(this, 'projects/remote-import', {
...options,
accessKeyId,
bucketName,
fileKey,
path,
region,
secretAccessKey,
});
}
showExportStatus<E extends boolean = false>(
projectId: string | number,
options?: Sudo & ShowExpanded<E>,
) {
return RequestHelper.get<ExportStatusSchema>()(
this,
endpoint`projects/${projectId}/export`,
options,
);
}
showImportStatus<E extends boolean = false>(
projectId: string | number,
options?: Sudo & ShowExpanded<E>,
) {
return RequestHelper.get<ImportStatusSchema>()(
this,
endpoint`projects/${projectId}/import`,
options,
);
}
scheduleExport<E extends boolean = false>(
projectId: string | number,
uploadConfig: {
url: string;
http_method?: string;
},
options?: { description?: string } & Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<{ message: string }, C, E, void>> {
return RequestHelper.post<{ message: string }>()(this, endpoint`projects/${projectId}/export`, {
...options,
upload: uploadConfig,
});
}
}