import { BaseResource } from '@gitbeaker/requester-utils'; import { RequestHelper, endpoint } from '../infrastructure'; import type { BaseRequestOptions, GitlabAPIResponse, MappedOmit, PaginationRequestOptions, PaginationTypes, ShowExpanded, Sudo, } from '../infrastructure'; import type { SimpleProjectSchema } from './Projects'; import type { CondensedCommitSchema } from './Commits'; import type { RunnerSchema } from './Runners'; import type { ExpandedUserSchema, SimpleUserSchema } from './Users'; import type { PipelineSchema } from './Pipelines'; export type JobScope = | 'created' | 'pending' | 'running' | 'failed' | 'success' | 'canceled' | 'skipped' | 'manual' | 'waiting_for_resource'; export interface ArtifactSchema extends Record { file_type: string; size: number; filename: string; file_format?: string; } export interface CondensedJobSchema extends Record { id: number; name: string; stage: string; project_id: string | number; project_name: string; } export interface JobSchema extends Record { id: number; name: string; stage: string; status: string; ref: string; tag: boolean; coverage?: string; allow_failure: boolean; created_at: string; started_at?: string; finished_at?: string; failure_reason?: string; erased_at?: string; duration?: number; user: ExpandedUserSchema; commit: CondensedCommitSchema; pipeline: PipelineSchema; web_url: string; artifacts: ArtifactSchema[]; queued_duration: number; artifacts_file: { filename: string; size: number; }; runner: RunnerSchema; artifacts_expire_at?: string; tag_list?: string[]; project?: { ci_job_token_scope_enabled?: boolean; }; } export interface BridgeSchema extends Record { commit: CondensedCommitSchema; coverage?: string; allow_failure: boolean; created_at: string; started_at: string; finished_at: string; erased_at?: string; duration: number; queued_duration: number; id: number; name: string; pipeline: MappedOmit; ref: string; stage: string; status: string; tag: boolean; web_url: string; user: ExpandedUserSchema; downstream_pipeline: MappedOmit; } export interface AllowedAgentSchema extends Record { id: number; config_project: MappedOmit; } export interface JobKubernetesAgentsSchema extends Record { allowed_agents: AllowedAgentSchema[]; job: CondensedJobSchema; pipeline: PipelineSchema; project: MappedOmit; user: SimpleUserSchema; } export interface JobVariableAttributeOption extends Record { key: string; value: string; } export class Jobs extends BaseResource { all( projectId: string | number, { pipelineId, ...options }: { pipelineId?: number; scope?: JobScope | JobScope[]; includeRetried?: boolean; } & BaseRequestOptions & PaginationRequestOptions

= {} as any, ): Promise> { const url = pipelineId ? endpoint`projects/${projectId}/pipelines/${pipelineId}/jobs` : endpoint`projects/${projectId}/jobs`; return RequestHelper.get()(this, url, options); } allPipelineBridges( projectId: string | number, pipelineId: number, options?: { scope?: JobScope | JobScope[] } & Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/pipelines/${pipelineId}/bridges`, options, ); } cancel( projectId: string | number, jobId: number, options?: Sudo & ShowExpanded, ): Promise> { return RequestHelper.post()( this, endpoint`projects/${projectId}/jobs/${jobId}/cancel`, options, ); } erase( projectId: string | number, jobId: number, options?: Sudo & ShowExpanded, ): Promise> { return RequestHelper.post()( this, endpoint`projects/${projectId}/jobs/${jobId}/erase`, options, ); } play( projectId: string | number, jobId: number, options?: { jobVariablesAttributes: JobVariableAttributeOption[] } & Sudo & ShowExpanded, ): Promise> { return RequestHelper.post()( this, endpoint`projects/${projectId}/jobs/${jobId}/play`, options, ); } retry( projectId: string | number, jobId: number, options?: Sudo & ShowExpanded, ): Promise> { return RequestHelper.post()( this, endpoint`projects/${projectId}/jobs/${jobId}/retry`, options, ); } show( projectId: string | number, jobId: number, options?: Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/jobs/${jobId}`, options, ); } showConnectedJob( options?: Sudo & ShowExpanded, ): Promise> { if (!this.headers['job-token']) throw new Error('Missing required header "job-token"'); return RequestHelper.get()(this, 'job', options); } showConnectedJobK8Agents( options?: Sudo & ShowExpanded, ): Promise> { if (!this.headers['job-token']) throw new Error('Missing required header "job-token"'); return RequestHelper.get()(this, 'job/allowed_agents', options); } showLog( projectId: string | number, jobId: number, options?: Sudo & ShowExpanded, ): Promise> { return RequestHelper.get()( this, endpoint`projects/${projectId}/jobs/${jobId}/trace`, options, ); } }