import { BaseResource } from '@gitbeaker/requester-utils'; import { RequestHelper, endpoint } from '../infrastructure'; import type { GitlabAPIResponse, ShowExpanded, Sudo } from '../infrastructure'; import type { CommitSchema } from './Commits'; export interface RepositoryFileExpandedSchema extends Record { file_name: string; file_path: string; size: number; encoding: string; content: string; content_sha256: string; ref: string; blob_id: string; commit_id: string; last_commit_id: string; } export interface RepositoryFileBlameSchema extends Record { commit: CommitSchema; lines?: string[]; } export interface RepositoryFileSchema extends Record { file_path: string; branch: string; } export type CreateRepositoryFileOptions = { authorEmail?: string; authorName?: string; encoding?: string; executeFilemode?: boolean; startBranch?: string; }; export type EditRepositoryFileOptions = { authorEmail?: string; authorName?: string; encoding?: string; executeFilemode?: boolean; startBranch?: string; lastCommitId?: string; }; export type RemoveRepositoryFileOptions = { authorEmail?: string; authorName?: string; startBranch?: string; lastCommitId?: string; }; export class RepositoryFiles extends BaseResource { allFileBlames( projectId: string | number, filePath: string, ref: string, options?: { range?: { start: number; end: number } } & Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/repository/files/${filePath}/blame`, { ref, ...options, }, ); } create( projectId: string | number, filePath: string, branch: string, content: string, commitMessage: string, options?: CreateRepositoryFileOptions & Sudo & ShowExpanded, ): Promise> { return RequestHelper.post()( this, endpoint`projects/${projectId}/repository/files/${filePath}`, { branch, content, commitMessage, ...options, }, ); } edit( projectId: string | number, filePath: string, branch: string, content: string, commitMessage: string, options?: EditRepositoryFileOptions & Sudo & ShowExpanded, ): Promise> { return RequestHelper.put()( this, endpoint`projects/${projectId}/repository/files/${filePath}`, { branch, content, commitMessage, ...options, }, ); } remove( projectId: string | number, filePath: string, branch: string, commitMessage: string, options?: RemoveRepositoryFileOptions & Sudo & ShowExpanded, ): Promise> { return RequestHelper.del()(this, endpoint`projects/${projectId}/repository/files/${filePath}`, { branch, commitMessage, ...options, }); } show( projectId: string | number, filePath: string, ref: string, options?: Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/repository/files/${filePath}`, { ref, ...options, }, ); } showRaw( projectId: string | number, filePath: string, ref: string, options?: { lfs?: boolean } & Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/repository/files/${filePath}/raw`, { ref, ...options, }, ); } }