feat(gitea): add domain model classes, helpers, and refactor GiteaClient internals; expand README with usage and docs
This commit is contained in:
118
ts/gitea.classes.actionrunjob.ts
Normal file
118
ts/gitea.classes.actionrunjob.ts
Normal file
@@ -0,0 +1,118 @@
|
||||
import type { GiteaClient } from './gitea.classes.giteaclient.js';
|
||||
import type { IGiteaActionRunJob, IGiteaActionRunJobStep } from './gitea.interfaces.js';
|
||||
import { computeDuration, resolveGiteaStatus } from './gitea.helpers.js';
|
||||
|
||||
export class GiteaActionRunJobStep {
|
||||
public readonly name: string;
|
||||
public readonly number: number;
|
||||
public readonly status: string;
|
||||
public readonly conclusion: string;
|
||||
public readonly resolvedStatus: string;
|
||||
public readonly startedAt: string;
|
||||
public readonly completedAt: string;
|
||||
public readonly duration: number;
|
||||
|
||||
constructor(raw: IGiteaActionRunJobStep) {
|
||||
this.name = raw.name || '';
|
||||
this.number = raw.number || 0;
|
||||
this.status = raw.status || '';
|
||||
this.conclusion = raw.conclusion || '';
|
||||
this.resolvedStatus = resolveGiteaStatus(this.status, this.conclusion);
|
||||
this.startedAt = raw.started_at || '';
|
||||
this.completedAt = raw.completed_at || '';
|
||||
this.duration = computeDuration(this.startedAt, this.completedAt);
|
||||
}
|
||||
|
||||
toJSON(): IGiteaActionRunJobStep {
|
||||
return {
|
||||
name: this.name,
|
||||
number: this.number,
|
||||
status: this.status,
|
||||
conclusion: this.conclusion,
|
||||
started_at: this.startedAt,
|
||||
completed_at: this.completedAt,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export class GiteaActionRunJob {
|
||||
// Raw data
|
||||
public readonly id: number;
|
||||
public readonly runId: number;
|
||||
public readonly name: string;
|
||||
public readonly workflowName: string;
|
||||
public readonly headBranch: string;
|
||||
public readonly headSha: string;
|
||||
public readonly status: string;
|
||||
public readonly conclusion: string;
|
||||
public readonly htmlUrl: string;
|
||||
public readonly startedAt: string;
|
||||
public readonly completedAt: string;
|
||||
public readonly labels: string[];
|
||||
public readonly runnerId: number;
|
||||
public readonly runnerName: string;
|
||||
public readonly steps: GiteaActionRunJobStep[];
|
||||
|
||||
// Computed
|
||||
public readonly resolvedStatus: string;
|
||||
public readonly duration: number;
|
||||
|
||||
/** @internal */
|
||||
constructor(
|
||||
private client: GiteaClient,
|
||||
private ownerRepo: string,
|
||||
raw: IGiteaActionRunJob,
|
||||
) {
|
||||
this.id = raw.id;
|
||||
this.runId = raw.run_id || 0;
|
||||
this.name = raw.name || '';
|
||||
this.workflowName = raw.workflow_name || '';
|
||||
this.headBranch = raw.head_branch || '';
|
||||
this.headSha = raw.head_sha || '';
|
||||
this.status = raw.status || '';
|
||||
this.conclusion = raw.conclusion || '';
|
||||
this.htmlUrl = raw.html_url || '';
|
||||
this.startedAt = raw.started_at || '';
|
||||
this.completedAt = raw.completed_at || '';
|
||||
this.labels = raw.labels || [];
|
||||
this.runnerId = raw.runner_id || 0;
|
||||
this.runnerName = raw.runner_name || '';
|
||||
this.steps = (raw.steps || []).map(s => new GiteaActionRunJobStep(s));
|
||||
|
||||
// Computed
|
||||
this.resolvedStatus = resolveGiteaStatus(this.status, this.conclusion);
|
||||
this.duration = computeDuration(this.startedAt, this.completedAt);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Log
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async getLog(): Promise<string> {
|
||||
return this.client.requestGetJobLog(this.ownerRepo, this.id);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Serialization
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
toJSON(): IGiteaActionRunJob {
|
||||
return {
|
||||
id: this.id,
|
||||
run_id: this.runId,
|
||||
name: this.name,
|
||||
workflow_name: this.workflowName,
|
||||
head_branch: this.headBranch,
|
||||
head_sha: this.headSha,
|
||||
status: this.status,
|
||||
conclusion: this.conclusion,
|
||||
html_url: this.htmlUrl,
|
||||
started_at: this.startedAt,
|
||||
completed_at: this.completedAt,
|
||||
steps: this.steps.map(s => s.toJSON()),
|
||||
labels: this.labels,
|
||||
runner_id: this.runnerId,
|
||||
runner_name: this.runnerName,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user