import { BaseResource } from '@gitbeaker/requester-utils'; import { RequestHelper, endpoint } from '../infrastructure'; import type { AsStream, GitlabAPIResponse, MappedOmit, PaginationRequestOptions, ShowExpanded, Sudo, } from '../infrastructure'; import type { CommitDiffSchema, CommitSchema, CondensedCommitSchema } from './Commits'; export type ArchiveType = 'tar.gz' | 'tar.bz2' | 'tbz' | 'tbz2' | 'tb2' | 'bz2' | 'tar' | 'zip'; export interface RepositoryChangelogSchema extends Record { notes: string; } export interface RepositoryCompareSchema extends Record { commit: MappedOmit; commits?: MappedOmit[]; diffs?: CommitDiffSchema[]; compare_timeout: boolean; compare_same_ref: boolean; } export interface RepositoryContributorSchema extends Record { name: string; email: string; commits: number; additions: number; deletions: number; } export interface RepositoryTreeSchema extends Record { id: string; name: string; type: string; path: string; mode: string; } export interface RepositoryBlobSchema extends Record { size: number; encoding: string; content: string; sha: string; } export type AllRepositoryTreesOptions = { pageToken?: string; path?: string; recursive?: boolean; ref?: string; }; export type EditChangelogOptions = { branch?: string; configFile?: string; date?: string; file?: string; from?: string; message?: string; to?: string; trailer?: string; }; export type ShowChangelogOptions = { configFile?: string; date?: string; from?: string; to?: string; trailer?: string; }; export class Repositories extends BaseResource { allContributors( projectId: string | number, options?: { orderBy?: string; sort?: string } & Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/repository/contributors`, options, ); } allRepositoryTrees( projectId: string | number, options?: AllRepositoryTreesOptions & PaginationRequestOptions<'keyset'> & Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/repository/tree`, options, ); } compare( projectId: string | number, from: string, to: string, options?: { fromProjectId?: string | number; straight?: boolean } & Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/repository/compare`, { from, to, ...options, }, ); } editChangelog( projectId: string | number, version: string, options?: EditChangelogOptions & Sudo & ShowExpanded, ): Promise> { return RequestHelper.post()( this, endpoint`projects/${projectId}/repository/changelog`, { ...options, version }, ); } mergeBase( projectId: string | number, refs: string[], options?: Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/repository/merge_base`, { ...options, refs, }, ); } showArchive( projectId: string | number, options: { fileType?: ArchiveType; sha?: string; path?: string; asStream: true } & Sudo & ShowExpanded, ): Promise>; showArchive( projectId: string | number, options?: { fileType?: ArchiveType; sha?: string; path?: string; asStream?: boolean } & Sudo & ShowExpanded, ): Promise>; showArchive( projectId: string | number, { fileType = 'tar.gz', ...options }: { fileType?: ArchiveType; sha?: string; path?: string } & AsStream & ShowExpanded & Sudo = {} as { fileType: ArchiveType }, ): Promise { return RequestHelper.get()( this, endpoint`projects/${projectId}/repository/archive.${fileType}`, options as { sha?: string; path?: string } & AsStream & ShowExpanded & Sudo, ); } showBlob( projectId: string | number, sha: string, options?: Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/repository/blobs/${sha}`, options, ); } showBlobRaw( projectId: string | number, sha: string, options?: Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/repository/blobs/${sha}/raw`, options, ); } showChangelog( projectId: string | number, version: string, options?: ShowChangelogOptions & Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/repository/changelog`, { ...options, version }, ); } }