Skip to content

Commit aa33061

Browse files
committed
refactor: Standardizing the upload argument header
This was done to improve consistency between the two functions used to upload files to gitlab. BREAKING CHANGE: path argument is no longer required/available. Now, it follows a similar function header to Project.upload with an optional metadata argument Missing dependency dede
1 parent 184253e commit aa33061

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/services/ProjectImportExport.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import FormData from 'form-data';
2+
import randomstring from 'randomstring';
23
import { BaseService, RequestHelper, Sudo, BaseRequestOptions } from '../infrastructure';
3-
import { ProjectId } from '.';
4+
import { ProjectId, UploadMetadata } from '.';
45

56
class ProjectImportExport extends BaseService {
67
download(projectId: ProjectId, options?: Sudo) {
@@ -15,15 +16,17 @@ class ProjectImportExport extends BaseService {
1516
return RequestHelper.get(this, `projects/${pId}/export`, options);
1617
}
1718

18-
import(content: string, path: string) {
19+
import(content: string, { metadata, sudo }: { metadata?: UploadMetadata } & Sudo = {}) {
1920
const form = new FormData();
2021

21-
form.append('file', content, {
22-
filename: path,
22+
const defaultMetadata: UploadMetadata = {
23+
filename: randomstring.generate(8),
2324
contentType: 'application/octet-stream',
24-
});
25+
};
2526

26-
return RequestHelper.post(this, 'projects/import', form);
27+
form.append('file', content, Object.assign(defaultMetadata, metadata));
28+
29+
return RequestHelper.post(this, 'projects/import', { sudo, form });
2730
}
2831

2932
importStatus(projectId: ProjectId, options?: Sudo) {

0 commit comments

Comments
 (0)