123 lines
4.2 KiB
TypeScript
123 lines
4.2 KiB
TypeScript
import type { GitLabClient } from './gitlab.classes.gitlabclient.js';
|
|
import type { IGitLabPipeline, IJobListOptions } from './gitlab.interfaces.js';
|
|
import { GitLabJob } from './gitlab.classes.job.js';
|
|
import { GitLabPipelineVariable } from './gitlab.classes.variable.js';
|
|
import { GitLabTestReport } from './gitlab.classes.testreport.js';
|
|
import { autoPaginate } from './gitlab.helpers.js';
|
|
|
|
export class GitLabPipeline {
|
|
// Raw data
|
|
public readonly id: number;
|
|
public readonly iid: number;
|
|
public readonly projectId: number;
|
|
public readonly status: string;
|
|
public readonly ref: string;
|
|
public readonly sha: string;
|
|
public readonly webUrl: string;
|
|
public readonly duration: number;
|
|
public readonly queuedDuration: number;
|
|
public readonly createdAt: string;
|
|
public readonly updatedAt: string;
|
|
public readonly startedAt: string;
|
|
public readonly finishedAt: string;
|
|
public readonly source: string;
|
|
public readonly tag: boolean;
|
|
|
|
/** @internal */
|
|
constructor(
|
|
private client: GitLabClient,
|
|
raw: IGitLabPipeline,
|
|
) {
|
|
this.id = raw.id;
|
|
this.iid = raw.iid || 0;
|
|
this.projectId = raw.project_id || 0;
|
|
this.status = raw.status || '';
|
|
this.ref = raw.ref || '';
|
|
this.sha = raw.sha || '';
|
|
this.webUrl = raw.web_url || '';
|
|
this.duration = raw.duration || 0;
|
|
this.queuedDuration = raw.queued_duration || 0;
|
|
this.createdAt = raw.created_at || '';
|
|
this.updatedAt = raw.updated_at || '';
|
|
this.startedAt = raw.started_at || '';
|
|
this.finishedAt = raw.finished_at || '';
|
|
this.source = raw.source || '';
|
|
this.tag = raw.tag ?? false;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Jobs
|
|
// ---------------------------------------------------------------------------
|
|
|
|
async getJobs(opts?: IJobListOptions): Promise<GitLabJob[]> {
|
|
return autoPaginate(
|
|
(page, perPage) => this.client.requestGetPipelineJobs(this.projectId, this.id, { ...opts, page, perPage }),
|
|
opts,
|
|
).then(jobs => jobs.map(j => new GitLabJob(this.client, this.projectId, j)));
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Variables & Test Report
|
|
// ---------------------------------------------------------------------------
|
|
|
|
async getVariables(): Promise<GitLabPipelineVariable[]> {
|
|
const vars = await this.client.requestGetPipelineVariables(this.projectId, this.id);
|
|
return vars.map(v => new GitLabPipelineVariable(v));
|
|
}
|
|
|
|
async getTestReport(): Promise<GitLabTestReport> {
|
|
const raw = await this.client.requestGetPipelineTestReport(this.projectId, this.id);
|
|
return new GitLabTestReport(raw);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Actions
|
|
// ---------------------------------------------------------------------------
|
|
|
|
async retry(): Promise<GitLabPipeline> {
|
|
const raw = await this.client.requestRetryPipeline(this.projectId, this.id);
|
|
return new GitLabPipeline(this.client, raw);
|
|
}
|
|
|
|
async cancel(): Promise<GitLabPipeline> {
|
|
const raw = await this.client.requestCancelPipeline(this.projectId, this.id);
|
|
return new GitLabPipeline(this.client, raw);
|
|
}
|
|
|
|
async delete(): Promise<void> {
|
|
await this.client.requestDeletePipeline(this.projectId, this.id);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Serialization
|
|
// ---------------------------------------------------------------------------
|
|
|
|
toJSON(): IGitLabPipeline {
|
|
return {
|
|
id: this.id,
|
|
iid: this.iid,
|
|
project_id: this.projectId,
|
|
status: this.status,
|
|
ref: this.ref,
|
|
sha: this.sha,
|
|
before_sha: '',
|
|
tag: this.tag,
|
|
web_url: this.webUrl,
|
|
duration: this.duration,
|
|
queued_duration: this.queuedDuration,
|
|
created_at: this.createdAt,
|
|
updated_at: this.updatedAt,
|
|
started_at: this.startedAt,
|
|
finished_at: this.finishedAt,
|
|
source: this.source,
|
|
coverage: '',
|
|
user: { id: 0, username: '', name: '', email: '', avatar_url: '', web_url: '', state: '' },
|
|
detailed_status: {
|
|
icon: '', text: '', label: '', group: '', tooltip: '',
|
|
has_details: false, details_path: '', favicon: '',
|
|
},
|
|
yaml_errors: '',
|
|
};
|
|
}
|
|
}
|