-
-
Notifications
You must be signed in to change notification settings - Fork 301
/
Copy pathPyPI.ts
65 lines (58 loc) · 2.14 KB
/
PyPI.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
import { BaseResource } from '@gitbeaker/requester-utils';
import { RequestHelper, endpoint } from '../infrastructure';
import type { GitlabAPIResponse, OneOf, ShowExpanded } from '../infrastructure';
export class PyPI<C extends boolean = false> extends BaseResource<C> {
downloadPackageFile<E extends boolean = false>(
sha: string,
fileIdentifier: string,
{
projectId,
groupId,
...options
}: OneOf<{ projectId: string | number; groupId: string | number }> &
ShowExpanded<E> = {} as any,
): Promise<GitlabAPIResponse<Blob, void, E, void>> {
let url: string;
if (projectId) {
url = endpoint`projects/${projectId}/packages/pypi/files/${sha}/${fileIdentifier}`;
} else if (groupId) {
url = endpoint`groups/${groupId}/packages/pypi/files/${sha}/${fileIdentifier}`;
} else {
throw new Error(
'Missing required argument. Please supply a projectId or a groupId in the options parameter',
);
}
return RequestHelper.get<Blob>()(this, url, options);
}
showPackageDescriptor<E extends boolean = false>(
packageName: string,
{
projectId,
groupId,
...options
}: OneOf<{ projectId: string | number; groupId: string | number }> & ShowExpanded<E>,
): Promise<GitlabAPIResponse<string, C, E, void>> {
let url: string;
if (projectId) {
url = endpoint`projects/${projectId}/packages/pypi/simple/${packageName}`;
} else if (groupId) {
url = endpoint`groups/${groupId}/packages/pypi/simple/${packageName}`;
} else {
throw new Error(
'Missing required argument. Please supply a projectId or a groupId in the options parameter',
);
}
return RequestHelper.get<string>()(this, url, options);
}
uploadPackageFile<E extends boolean = false>(
projectId: string | number,
packageFile: { content: Blob; filename: string },
options?: ShowExpanded<E>,
): Promise<GitlabAPIResponse<void, C, E, void>> {
return RequestHelper.put<void>()(this, endpoint`projects/${projectId}/packages/pypi`, {
...options,
isForm: true,
file: [packageFile.content, packageFile.filename],
});
}
}