mirror of
https://github.com/jdalrymple/gitbeaker.git
synced 2026-02-01 16:47:23 +00:00
* Dependency and Configuration updates * CHANGELOG and README updates * Added support for camel case and snake case response types in the request helper and base service * Added support for the Dockerfile Templates API * Added support for the Issue Note Award Emojis API * Removed redundant Group Projects service * Updated types for a variety of services * Added type updates and removed protect and unprotect endpoints from the Branches API * Added type updates and signature endpoint to the Commits API * Added type updates and edit support to the Deployments API * Added type updates and a showRepository function to the Container Registry API * Added type updates and updated the service support to include create, edit, show and remove for the Feature Flags API * Added type updates and support for the removal of geonodes with the Geo Nodes API * Renamed UserKeys to UserSSHKeys and added type updates for the User SSH Keys API * Added type updates for the License Templates API and renamed the export to fix the spelling error * Added type updates and support for the transfer projects endpoint for the Groups API * Added type updates and removed removed events endpoint on the Projects API * Added type updates and modified the create function to require a resource name in the Todos API
190 lines
5.3 KiB
TypeScript
190 lines
5.3 KiB
TypeScript
import { BaseService } from '@gitbeaker/requester-utils';
|
|
import {
|
|
BaseRequestOptions,
|
|
PaginatedRequestOptions,
|
|
RequestHelper,
|
|
Sudo,
|
|
} from '../infrastructure';
|
|
import { CommitSchema } from './Commits';
|
|
import { RunnerSchema } from './Runners';
|
|
import { UserSchema } from './Users';
|
|
import { PipelineSchema } from './Pipelines';
|
|
|
|
export type JobScope =
|
|
| 'created'
|
|
| 'pending'
|
|
| 'running'
|
|
| 'failed'
|
|
| 'success'
|
|
| 'canceled'
|
|
| 'skipped'
|
|
| 'manual';
|
|
|
|
export interface ArtifactSchema extends Record<string, unknown> {
|
|
file_type: string;
|
|
size: number;
|
|
filename: string;
|
|
file_format?: string;
|
|
}
|
|
|
|
export interface JobSchema extends Record<string, unknown> {
|
|
id: number;
|
|
status: string;
|
|
stage: string;
|
|
name: string;
|
|
ref: string;
|
|
tag: boolean;
|
|
coverage?: string;
|
|
allow_failure: boolean;
|
|
created_at: Date;
|
|
started_at?: Date;
|
|
finished_at?: Date;
|
|
duration?: number;
|
|
user: UserSchema;
|
|
commit: CommitSchema;
|
|
pipeline: PipelineSchema;
|
|
web_url: string;
|
|
artifacts: ArtifactSchema[];
|
|
runner: RunnerSchema;
|
|
artifacts_expire_at?: Date;
|
|
tag_list?: string[];
|
|
}
|
|
|
|
export class Jobs<C extends boolean = false> extends BaseService<C> {
|
|
all(projectId: string | number, options?: PaginatedRequestOptions) {
|
|
const pId = encodeURIComponent(projectId);
|
|
|
|
return RequestHelper.get<JobSchema[]>()(this, `projects/${pId}/jobs`, options);
|
|
}
|
|
|
|
cancel(projectId: string | number, jobId: number, options?: Sudo) {
|
|
const [pId, jId] = [projectId, jobId].map(encodeURIComponent);
|
|
|
|
return RequestHelper.post<JobSchema>()(this, `projects/${pId}/jobs/${jId}/cancel`, options);
|
|
}
|
|
|
|
// TODO move
|
|
downloadSingleArtifactFile(
|
|
projectId: string | number,
|
|
jobId: number,
|
|
artifactPath: string,
|
|
{ stream = false, ...options }: { stream?: boolean } & BaseRequestOptions = {},
|
|
) {
|
|
const [pId, jId] = [projectId, jobId].map(encodeURIComponent);
|
|
|
|
if (stream) {
|
|
return RequestHelper.stream(
|
|
this,
|
|
`projects/${pId}/jobs/${jId}/artifacts/${artifactPath}`,
|
|
options,
|
|
);
|
|
}
|
|
return RequestHelper.get()(
|
|
this,
|
|
`projects/${pId}/jobs/${jId}/artifacts/${artifactPath}`,
|
|
options,
|
|
);
|
|
}
|
|
|
|
// TODO move
|
|
downloadSingleArtifactFileFromRef(
|
|
projectId: string | number,
|
|
ref: string,
|
|
artifactPath: string,
|
|
jobName: string,
|
|
{ stream = false, ...options }: { stream?: boolean } & BaseRequestOptions = {},
|
|
) {
|
|
const [pId, rId, name] = [projectId, ref, jobName].map(encodeURIComponent);
|
|
|
|
if (stream) {
|
|
return RequestHelper.stream(
|
|
this,
|
|
`projects/${pId}/jobs/artifacts/${rId}/raw/${artifactPath}?job=${name}`,
|
|
options,
|
|
);
|
|
}
|
|
return RequestHelper.get()(
|
|
this,
|
|
`projects/${pId}/jobs/artifacts/${rId}/raw/${artifactPath}?job=${name}`,
|
|
options,
|
|
);
|
|
}
|
|
|
|
// TODO move
|
|
downloadLatestArtifactFile(
|
|
projectId: string | number,
|
|
ref: string,
|
|
jobName: string,
|
|
{ stream = false, ...options }: { stream?: boolean } & BaseRequestOptions = {},
|
|
) {
|
|
const [pId, rId, name] = [projectId, ref, jobName].map(encodeURIComponent);
|
|
|
|
if (stream) {
|
|
return RequestHelper.stream(
|
|
this,
|
|
`projects/${pId}/jobs/artifacts/${rId}/download?job=${name}`,
|
|
options,
|
|
);
|
|
}
|
|
return RequestHelper.get()(
|
|
this,
|
|
`projects/${pId}/jobs/artifacts/${rId}/download?job=${name}`,
|
|
options,
|
|
);
|
|
}
|
|
|
|
downloadTraceFile(projectId: string | number, jobId: number, options?: Sudo) {
|
|
const [pId, jId] = [projectId, jobId].map(encodeURIComponent);
|
|
|
|
return RequestHelper.get()(this, `projects/${pId}/jobs/${jId}/trace`, options);
|
|
}
|
|
|
|
erase(projectId: string | number, jobId: number, options?: Sudo) {
|
|
const [pId, jId] = [projectId, jobId].map(encodeURIComponent);
|
|
|
|
return RequestHelper.post<JobSchema>()(this, `projects/${pId}/jobs/${jId}/erase`, options);
|
|
}
|
|
|
|
// TODO move
|
|
eraseArtifacts(projectId: string | number, jobId: number, options?: Sudo) {
|
|
const [pId, jId] = [projectId, jobId].map(encodeURIComponent);
|
|
|
|
return RequestHelper.del()(this, `projects/${pId}/jobs/${jId}/artifacts`, options);
|
|
}
|
|
|
|
// TODO move
|
|
keepArtifacts(projectId: string | number, jobId: number, options?: Sudo) {
|
|
const [pId, jId] = [projectId, jobId].map(encodeURIComponent);
|
|
|
|
return RequestHelper.post()(this, `projects/${pId}/jobs/${jId}/artifacts/keep`, options);
|
|
}
|
|
|
|
play(projectId: string | number, jobId: number, options?: Sudo) {
|
|
const [pId, jId] = [projectId, jobId].map(encodeURIComponent);
|
|
|
|
return RequestHelper.post<JobSchema>()(this, `projects/${pId}/jobs/${jId}/play`, options);
|
|
}
|
|
|
|
retry(projectId: string | number, jobId: number, options?: Sudo) {
|
|
const [pId, jId] = [projectId, jobId].map(encodeURIComponent);
|
|
|
|
return RequestHelper.post<JobSchema>()(this, `projects/${pId}/jobs/${jId}/retry`, options);
|
|
}
|
|
|
|
show(projectId: string | number, jobId: number, options?: Sudo) {
|
|
const [pId, jId] = [projectId, jobId].map(encodeURIComponent);
|
|
|
|
return RequestHelper.get<JobSchema>()(this, `projects/${pId}/jobs/${jId}`, options);
|
|
}
|
|
|
|
showPipelineJobs(
|
|
projectId: string | number,
|
|
pipelineId: number,
|
|
options?: { scope?: JobScope } & Sudo,
|
|
) {
|
|
const [pId, ppId] = [projectId, pipelineId].map(encodeURIComponent);
|
|
|
|
return RequestHelper.get<JobSchema>()(this, `projects/${pId}/pipelines/${ppId}/jobs`, options);
|
|
}
|
|
}
|