import { BaseResource } from '@gitbeaker/requester-utils'; import { RequestHelper, endpoint } from '../infrastructure'; import type { AsStream, GitlabAPIResponse, ShowExpanded, Sudo } from '../infrastructure'; export interface ExportStatusSchema extends Record { 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 { 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 extends BaseResource { download( projectId: string | number, options: { asStream: true } & Sudo & ShowExpanded, ): Promise>; download( projectId: string | number, options?: { asStream?: boolean } & Sudo & ShowExpanded, ): Promise>; download( projectId: string | number, options?: AsStream & ShowExpanded & Sudo, ): Promise { return RequestHelper.get()( this, endpoint`projects/${projectId}/export/download`, options, ); } import( file: { content: Blob; filename: string }, path: string, options?: { name?: string; namespace?: number | string; overrideParams?: Record; overwrite?: boolean; } & Sudo & ShowExpanded, ): Promise> { return RequestHelper.post()(this, 'projects/import', { isForm: true, ...options, file: [file.content, file.filename], path, }); } importRemote( url: string, path: string, options?: { name?: number; namespace?: number | string; overrideParams?: Record; overwrite?: boolean; } & Sudo & ShowExpanded, ): Promise> { return RequestHelper.post()(this, 'projects/remote-import', { ...options, path, url, }); } importRemoteS3( accessKeyId: string, bucketName: string, fileKey: string, path: string, region: string, secretAccessKey: string, options?: { name?: number; namespace?: number | string } & Sudo & ShowExpanded, ): Promise> { return RequestHelper.post()(this, 'projects/remote-import', { ...options, accessKeyId, bucketName, fileKey, path, region, secretAccessKey, }); } showExportStatus( projectId: string | number, options?: Sudo & ShowExpanded, ) { return RequestHelper.get()( this, endpoint`projects/${projectId}/export`, options, ); } showImportStatus( projectId: string | number, options?: Sudo & ShowExpanded, ) { return RequestHelper.get()( this, endpoint`projects/${projectId}/import`, options, ); } scheduleExport( projectId: string | number, uploadConfig: { url: string; http_method?: string; }, options?: { description?: string } & Sudo & ShowExpanded, ): Promise> { return RequestHelper.post<{ message: string }>()(this, endpoint`projects/${projectId}/export`, { ...options, upload: uploadConfig, }); } }