105 lines
3.4 KiB
TypeScript
105 lines
3.4 KiB
TypeScript
import type { GitLabClient } from './gitlab.classes.gitlabclient.js';
|
|
import type { IGitLabJob } from './gitlab.interfaces.js';
|
|
|
|
export class GitLabJob {
|
|
// Raw data
|
|
public readonly id: number;
|
|
public readonly name: string;
|
|
public readonly stage: string;
|
|
public readonly status: string;
|
|
public readonly ref: string;
|
|
public readonly tag: boolean;
|
|
public readonly webUrl: string;
|
|
public readonly createdAt: string;
|
|
public readonly startedAt: string;
|
|
public readonly finishedAt: string;
|
|
public readonly duration: number;
|
|
public readonly queuedDuration: number;
|
|
public readonly coverage: number;
|
|
public readonly allowFailure: boolean;
|
|
public readonly failureReason: string;
|
|
|
|
/** @internal */
|
|
constructor(
|
|
private client: GitLabClient,
|
|
private projectId: number | string,
|
|
raw: IGitLabJob,
|
|
) {
|
|
this.id = raw.id;
|
|
this.name = raw.name || '';
|
|
this.stage = raw.stage || '';
|
|
this.status = raw.status || '';
|
|
this.ref = raw.ref || '';
|
|
this.tag = raw.tag ?? false;
|
|
this.webUrl = raw.web_url || '';
|
|
this.createdAt = raw.created_at || '';
|
|
this.startedAt = raw.started_at || '';
|
|
this.finishedAt = raw.finished_at || '';
|
|
this.duration = raw.duration || 0;
|
|
this.queuedDuration = raw.queued_duration || 0;
|
|
this.coverage = raw.coverage || 0;
|
|
this.allowFailure = raw.allow_failure ?? false;
|
|
this.failureReason = raw.failure_reason || '';
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Log
|
|
// ---------------------------------------------------------------------------
|
|
|
|
async getLog(): Promise<string> {
|
|
return this.client.requestGetJobLog(this.projectId, this.id);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Actions
|
|
// ---------------------------------------------------------------------------
|
|
|
|
async retry(): Promise<GitLabJob> {
|
|
const raw = await this.client.requestRetryJob(this.projectId, this.id);
|
|
return new GitLabJob(this.client, this.projectId, raw);
|
|
}
|
|
|
|
async cancel(): Promise<GitLabJob> {
|
|
const raw = await this.client.requestCancelJob(this.projectId, this.id);
|
|
return new GitLabJob(this.client, this.projectId, raw);
|
|
}
|
|
|
|
async play(): Promise<GitLabJob> {
|
|
const raw = await this.client.requestPlayJob(this.projectId, this.id);
|
|
return new GitLabJob(this.client, this.projectId, raw);
|
|
}
|
|
|
|
async erase(): Promise<void> {
|
|
await this.client.requestEraseJob(this.projectId, this.id);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Serialization
|
|
// ---------------------------------------------------------------------------
|
|
|
|
toJSON(): IGitLabJob {
|
|
return {
|
|
id: this.id,
|
|
name: this.name,
|
|
stage: this.stage,
|
|
status: this.status,
|
|
ref: this.ref,
|
|
tag: this.tag,
|
|
web_url: this.webUrl,
|
|
created_at: this.createdAt,
|
|
started_at: this.startedAt,
|
|
finished_at: this.finishedAt,
|
|
duration: this.duration,
|
|
queued_duration: this.queuedDuration,
|
|
coverage: this.coverage,
|
|
allow_failure: this.allowFailure,
|
|
failure_reason: this.failureReason,
|
|
pipeline: { id: 0, project_id: 0, ref: '', sha: '', status: '' },
|
|
user: { id: 0, username: '', name: '', email: '', avatar_url: '', web_url: '', state: '' },
|
|
runner: { id: 0, description: '', active: false, is_shared: false },
|
|
artifacts: [],
|
|
artifacts_expire_at: '',
|
|
};
|
|
}
|
|
}
|