import { BaseResource } from '@gitbeaker/requester-utils'; import { RequestHelper, endpoint } from '../infrastructure'; import type { GitlabAPIResponse, MappedOmit, PaginationRequestOptions, PaginationTypes, ShowExpanded, Sudo, } from '../infrastructure'; import type { SimpleUserSchema } from './Users'; import type { MergeRequestSchema } from './MergeRequests'; import type { DiscussionNoteSchema, DiscussionSchema } from '../templates/ResourceDiscussions'; import type { CommitablePipelineStatus } from './Pipelines'; export interface CommitAction { /** The action to perform */ action: 'create' | 'delete' | 'move' | 'update' | 'chmod'; /** Full path to the file. Ex. lib/class.rb */ filePath: string; /** Original full path to the file being moved.Ex.lib / class1.rb */ previousPath?: string; /** File content, required for all except delete. Optional for move */ content?: string; /** text or base64. text is default. */ encoding?: string; /** Last known file commit id. Will be only considered in update, move and delete actions. */ lastCommitId?: string; /** When true/false enables/disables the execute flag on the file. Only considered for chmod action. */ execute_filemode?: boolean; } // Response structures export interface CommitStatsSchema extends Record { additions: number; deletions: number; total: number; } export interface CondensedCommitSchema extends Record { id: string; short_id: string; message: string; title: string; author_email: string; author_name: string; created_at: string; } export interface CommitSchema extends CondensedCommitSchema { parent_ids?: string[]; message: string; authored_date?: string; committer_name?: string; committer_email?: string; committed_date?: string; web_url: string; } export interface ExpandedCommitSchema extends CommitSchema { last_pipeline: { id: number; ref: string; sha: string; status: string; }; stats: CommitStatsSchema; status: string; } export interface GPGSignatureSchema extends Record { signature_type: 'PGP'; verification_status: 'verified' | 'unverified'; gpg_key_id: number; gpg_key_primary_keyid: string; gpg_key_user_name: string; gpg_key_user_email: string; gpg_key_subkey_id?: number; commit_source: string; } export interface X509SignatureSchema extends Record { signature_type: 'X509'; verification_status: 'verified' | 'unverified'; x509_certificate: { id: number; subject: string; subject_key_identifier: string; email: string; serial_number: string; certificate_status: string; x509_issuer: { id: number; subject: string; subject_key_identifier: string; crl_url: string; }; }; commit_source: string; } export interface MissingSignatureSchema extends Record { message: string; } export type CommitSignatureSchema = | GPGSignatureSchema | X509SignatureSchema | MissingSignatureSchema; export interface CondensedCommitCommentSchema extends Record { note: string; author: MappedOmit; } export interface CommitCommentSchema extends CondensedCommitCommentSchema { line_type: 'new' | 'old'; path: string; line: number; } export interface CommitDiffSchema extends Record { diff: string; new_path: string; old_path: string; a_mode?: string; b_mode: string; new_file: boolean; renamed_file: boolean; deleted_file: boolean; } export interface CommitStatusSchema extends Record { status: CommitablePipelineStatus; created_at: string; started_at?: string; name: string; allow_failure: boolean; author: MappedOmit; description?: string; sha: string; target_url: string; finished_at?: string; id: number; ref: string; } export interface CommitReferenceSchema extends Record { type: 'branch' | 'tag' | 'all'; name: string; } export interface CommitSequenceSchema extends Record { count: number; } export interface CommitDiscussionNoteSchema extends MappedOmit { confidential?: boolean; commands_changes: Record; } export interface CommitDiscussionSchema extends Record { id: string; individual_note: boolean; notes?: CommitDiscussionNoteSchema[]; } export type AllCommitsOptions = { refName?: string; since?: string; until?: string; path?: string; author?: string; all?: boolean; withStats?: boolean; firstParent?: boolean; order?: string; trailers?: boolean; }; export type CreateCommitOptions = { startBranch?: string; startSha?: string; startProject?: number | string; actions?: CommitAction[]; authorEmail?: string; authorName?: string; stats?: boolean; force?: boolean; }; export type EditPipelineStatusOptions = { ref?: string; name?: string; context?: string; targetUrl?: string; description?: string; coverage?: number; pipelineId?: number; }; export class Commits extends BaseResource { all( projectId: string | number, options: AllCommitsOptions & PaginationRequestOptions

& Sudo & ShowExpanded & { withStats: true }, ): Promise>; all( projectId: string | number, options: AllCommitsOptions & PaginationRequestOptions

& Sudo & ShowExpanded & { trailers: true }, ): Promise })[], C, E, P>>; all( projectId: string | number, options: AllCommitsOptions & PaginationRequestOptions

& Sudo & ShowExpanded & { withStats: true; trailers: true }, ): Promise< GitlabAPIResponse< (CommitSchema & { trailers: Record; stats: CommitStatsSchema })[], C, E, P > >; all( projectId: string | number, options?: AllCommitsOptions & PaginationRequestOptions

& Sudo & ShowExpanded, ): Promise>; all( projectId: string | number, options?: AllCommitsOptions & PaginationRequestOptions

& Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/repository/commits`, options, ); } allComments( projectId: string | number, sha: string, options?: Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/repository/commits/${sha}/comments`, options, ); } allDiscussions( projectId: string | number, sha: string, options?: Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/repository/commits/${sha}/discussions`, options, ); } allMergeRequests( projectId: string | number, sha: string, options?: PaginationRequestOptions

& Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/repository/commits/${sha}/merge_requests`, options, ); } allReferences( projectId: string | number, sha: string, options?: { type?: string } & PaginationRequestOptions

& Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/repository/commits/${sha}/refs`, options, ); } allStatuses( projectId: string | number, sha: string, options?: { ref?: string; stage?: string; name?: string; all?: boolean } & Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/repository/commits/${sha}/statuses`, options, ); } cherryPick( projectId: string | number, sha: string, branch: string, options?: { dryRun?: boolean; message?: string } & Sudo & ShowExpanded, ): Promise> { return RequestHelper.post()( this, endpoint`projects/${projectId}/repository/commits/${sha}/cherry_pick`, { branch, ...options, }, ); } create( projectId: string | number, branch: string, message: string, actions: CommitAction[] = [], options: CreateCommitOptions & Sudo & ShowExpanded = {}, ): Promise> { return RequestHelper.post()( this, endpoint`projects/${projectId}/repository/commits`, { branch, commitMessage: message, actions, ...options, }, ); } createComment( projectId: string | number, sha: string, note: string, options?: { path?: string; line?: number; lineType?: string } & Sudo & ShowExpanded, ): Promise> { return RequestHelper.post()( this, endpoint`projects/${projectId}/repository/commits/${sha}/comments`, { note, ...options, }, ); } editStatus( projectId: string | number, sha: string, state: CommitablePipelineStatus, options?: EditPipelineStatusOptions & Sudo & ShowExpanded, ): Promise> { return RequestHelper.post()( this, endpoint`projects/${projectId}/statuses/${sha}`, { state, ...options, }, ); } revert( projectId: string | number, sha: string, branch: string, options?: { dryRun?: boolean } & Sudo & ShowExpanded, ): Promise> { return RequestHelper.post()( this, endpoint`projects/${projectId}/repository/commits/${sha}/revert`, { ...options, branch, }, ); } show( projectId: string | number, sha: string, options?: { stats?: boolean } & Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/repository/commits/${sha}`, options, ); } showDiff( projectId: string | number, sha: string, options?: PaginationRequestOptions

& Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/repository/commits/${sha}/diff`, options, ); } showGPGSignature( projectId: string | number, sha: string, options?: Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/repository/commits/${sha}/signature`, options, ); } showSequence( projectId: string | number, sha: string, options?: { firstParent?: boolean } & Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/repository/commits/${sha}/sequence`, options, ); } }