-
-
Notifications
You must be signed in to change notification settings - Fork 297
/
Migrations.ts
112 lines (101 loc) · 3.11 KB
/
Migrations.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
import { BaseResource } from '@gitbeaker/requester-utils';
import { RequestHelper, endpoint } from '../infrastructure';
import type {
GitlabAPIResponse,
PaginationRequestOptions,
PaginationTypes,
ShowExpanded,
Sudo,
} from '../infrastructure';
export type MigrationStatus = 'created' | 'started' | 'finished' | 'failed';
export interface MigrationEntityFailure {
pipeline_class: string;
pipeline_step: string;
exception_class: string;
correlation_id_value: string;
created_at: string;
}
export interface MigrationEntitySchema extends Record<string, unknown> {
id: number;
bulk_import_id: number;
status: string;
source_full_path: string;
destination_name: string;
destination_namespace: string;
parent_id?: number;
namespace_id: number;
project_id?: string | number;
created_at: string;
updated_at: string;
failures?: MigrationEntityFailure[];
}
export interface MigrationStatusSchema extends Record<string, unknown> {
id: number;
status: string;
source_type: string;
created_at: string;
updated_at: string;
}
export type MigrationEntityOptions = {
sourceType: string;
sourceFullPath: string;
destinationSlug: string;
destinationNamespace: string;
};
export class Migrations<C extends boolean = false> extends BaseResource<C> {
all<E extends boolean = false, P extends PaginationTypes = 'offset'>(
options?: {
status?: MigrationStatus;
} & PaginationRequestOptions<P> &
Sudo &
ShowExpanded<E>,
): Promise<GitlabAPIResponse<MigrationStatusSchema[], C, E, P>> {
return RequestHelper.get<MigrationStatusSchema[]>()(this, 'bulk_imports', options);
}
create<E extends boolean = false>(
configuration: { url: string; access_token: string },
entities: MigrationEntityOptions[],
options?: Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<MigrationStatusSchema, C, E, void>> {
return RequestHelper.post<MigrationStatusSchema>()(this, 'bulk_imports', {
configuration,
entities,
...options,
});
}
allEntities<E extends boolean = false>({
bulkImportId,
...options
}: {
status?: MigrationStatus;
bulkImportId?: number;
} & PaginationRequestOptions<'offset'> &
Sudo &
ShowExpanded<E> = {}): Promise<GitlabAPIResponse<MigrationEntitySchema[], C, E, 'offset'>> {
const url = bulkImportId
? endpoint`bulk_imports/${bulkImportId}/entities`
: 'bulk_imports/entities';
return RequestHelper.get<MigrationEntitySchema[]>()(this, url, options);
}
show<E extends boolean = false>(
bulkImportId: number,
options?: Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<MigrationStatusSchema, C, E, void>> {
return RequestHelper.get<MigrationStatusSchema>()(
this,
`bulk_imports/${bulkImportId}`,
options,
);
}
showEntity<E extends boolean = false>(
bulkImportId: number,
entitityId: number,
options?: Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<MigrationEntitySchema, C, E, void>> {
return RequestHelper.get<MigrationEntitySchema>()(
this,
`bulk_imports/${bulkImportId}/entities/${entitityId}`,
options,
);
}
}