import { BaseResource } from '@gitbeaker/requester-utils'; import { RequestHelper, endpoint } from '../infrastructure'; import type { GitlabAPIResponse, OneOf, ShowExpanded } from '../infrastructure'; function url({ projectId, groupId, }: { projectId?: string | number; groupId?: string | number } = {}): string { if (projectId) return endpoint`/projects/${projectId}/packages/debian`; if (groupId) return endpoint`/groups/${groupId}/-/packages/debian`; throw new Error( 'Missing required argument. Please supply a projectId or a groupId in the options parameter', ); } export class Debian extends BaseResource { downloadBinaryFileIndex( distribution: string, component: string, architecture: string, { projectId, groupId, ...options }: OneOf<{ projectId: string | number; groupId: string | number }> & ShowExpanded, ): Promise> { const prefix = url({ projectId, groupId, }); return RequestHelper.get()( this, `${prefix}/dists/${distribution}/${component}/binary-${architecture}/Packages`, options as ShowExpanded, ); } downloadDistributionReleaseFile( distribution: string, { projectId, groupId, ...options }: OneOf<{ projectId: string | number; groupId: string | number }> & ShowExpanded, ): Promise> { const prefix = url({ projectId, groupId, }); return RequestHelper.get()( this, `${prefix}/dists/${distribution}/Release`, options as ShowExpanded, ); } downloadSignedDistributionReleaseFile( distribution: string, { projectId, groupId, ...options }: OneOf<{ projectId: string | number; groupId: string | number }> & ShowExpanded, ): Promise> { const prefix = url({ projectId, groupId, }); return RequestHelper.get()( this, `${prefix}/dists/${distribution}/InRelease`, options as ShowExpanded, ); } downloadReleaseFileSignature( distribution: string, { projectId, groupId, ...options }: OneOf<{ projectId: string | number; groupId: string | number }> & ShowExpanded, ): Promise> { const prefix = url({ projectId, groupId, }); return RequestHelper.get()( this, `${prefix}/dists/${distribution}/Release.gpg`, options as ShowExpanded, ); } downloadPackageFile( projectId: string | number, distribution: string, letter: string, packageName: string, packageVersion: string, filename: string, options?: ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/packages/debian/pool/${distribution}/${letter}/${packageName}/${packageVersion}/${filename}`, options, ); } uploadPackageFile( projectId: string | number, packageFile: { content: Blob; filename: string }, options?: ShowExpanded, ): Promise> { return RequestHelper.put()( this, endpoint`projects/${projectId}/packages/debian/${packageFile.filename}`, { isForm: true, ...options, file: [packageFile.content, packageFile.filename], }, ); } }