Skip to content

Commit

Permalink
Updating Container Registry API
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalrymple committed Dec 17, 2021
1 parent fb40f7d commit f8d3a43
Showing 1 changed file with 52 additions and 12 deletions.
64 changes: 52 additions & 12 deletions packages/core/src/resources/ContainerRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { BaseResource } from '@gitbeaker/requester-utils';
import { RequestHelper, PaginatedRequestOptions, Sudo, endpoint } from '../infrastructure';
import {
endpoint,
PaginatedRequestOptions,
RequestHelper,
Sudo,
ShowExpanded,
GitlabAPIResponse,
} from '../infrastructure';

export interface RegistryRepositoryTagSchema extends Record<string, unknown> {
name: string;
Expand All @@ -12,6 +19,11 @@ export interface RegistryRepositoryTagSchema extends Record<string, unknown> {
total_size: number;
}

export type CondensedRegistryRepositoryTagSchema = Pick<
RegistryRepositoryTagSchema,
'name' | 'path' | 'location'
>;

export interface RegistryRepositorySchema extends Record<string, unknown> {
id: number;
name: string;
Expand All @@ -25,60 +37,83 @@ export interface RegistryRepositorySchema extends Record<string, unknown> {
}

export class ContainerRegistry<C extends boolean = false> extends BaseResource<C> {
projectRepositories(projectId: string | number, options?: PaginatedRequestOptions) {
projectRepositories<E extends boolean = false, P extends 'keyset' | 'offset' = 'keyset'>(
projectId: string | number,
options?: PaginatedRequestOptions<E, P>,
) {
return RequestHelper.get<Omit<RegistryRepositorySchema, 'tags' | 'tags_count'>[]>()(
this,
endpoint`projects/${projectId}/registry/repositories`,
options,
);
}

groupRepositories(projectId: string | number, options?: PaginatedRequestOptions) {
groupRepositories<E extends boolean = false, P extends 'keyset' | 'offset' = 'keyset'>(
projectId: string | number,
options?: PaginatedRequestOptions<E, P>,
) {
return RequestHelper.get<Omit<RegistryRepositorySchema, 'tags' | 'tags_count'>[]>()(
this,
endpoint`groups/${projectId}/registry/repositories`,
options,
);
}

showRepository(projectId: string | number, repositoryId: number, options?: Sudo) {
showRepository<E extends boolean = false>(
projectId: string | number,
repositoryId: number,
options?: Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<RegistryRepositorySchema, C, E, void>> {
return RequestHelper.get<RegistryRepositorySchema>()(
this,
endpoint`projects/${projectId}/registry/repositories/${repositoryId}`,
options,
);
}

tags(projectId: string | number, repositoryId: number, options?: PaginatedRequestOptions) {
return RequestHelper.get<Pick<RegistryRepositoryTagSchema, 'name' | 'path' | 'location'>[]>()(
tags<E extends boolean = false, P extends 'keyset' | 'offset' = 'keyset'>(
projectId: string | number,
repositoryId: number,
options?: PaginatedRequestOptions<E, P>,
): Promise<GitlabAPIResponse<CondensedRegistryRepositoryTagSchema[], C, E, P>> {
return RequestHelper.get<CondensedRegistryRepositoryTagSchema[]>()(
this,
endpoint`projects/${projectId}/registry/repositories/${repositoryId}/tags`,
options,
);
}

removeRepository(projectId: string | number, repositoryId: number, options?: Sudo) {
removeRepository<E extends boolean = false>(
projectId: string | number,
repositoryId: number,
options?: Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<void, C, E, void>> {
return RequestHelper.del()(
this,
endpoint`projects/${projectId}/registry/repositories/${repositoryId}`,
options,
);
}

removeTag(projectId: string | number, repositoryId: number, tagName: string, options?: Sudo) {
removeTag<E extends boolean = false>(
projectId: string | number,
repositoryId: number,
tagName: string,
options?: Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<void, C, E, void>> {
return RequestHelper.del()(
this,
endpoint`projects/${projectId}/registry/repositories/${repositoryId}/tags/${tagName}`,
options,
);
}

removeTags(
removeTags<E extends boolean = false>(
projectId: string | number,
repositoryId: number,
nameRegexDelete: string,
options?: Sudo & { nameRegexKeep: string; keepN: string; olderThan: string },
) {
options?: Sudo & { nameRegexKeep: string; keepN: string; olderThan: string } & ShowExpanded<E>,
): Promise<GitlabAPIResponse<void, C, E, void>> {
return RequestHelper.del()(
this,
endpoint`projects/${projectId}/registry/repositories/${repositoryId}/tags`,
Expand All @@ -89,7 +124,12 @@ export class ContainerRegistry<C extends boolean = false> extends BaseResource<C
);
}

showTag(projectId: string | number, repositoryId: number, tagName: string, options?: Sudo) {
showTag<E extends boolean = false>(
projectId: string | number,
repositoryId: number,
tagName: string,
options?: Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<RegistryRepositoryTagSchema, C, E, void>> {
return RequestHelper.get<RegistryRepositoryTagSchema>()(
this,
endpoint`projects/${projectId}/registry/repositories/${repositoryId}/tags/${tagName}`,
Expand Down

0 comments on commit f8d3a43

Please sign in to comment.