This commit is contained in:
@@ -91,12 +91,16 @@ export class WoodpeckerService {
|
||||
function normalizeRepo(repo: WoodpeckerRepo, pipeline = getPipeline(repo), baseUrl = '') {
|
||||
const createdAt = getPipelineTime(pipeline);
|
||||
const repository = getString(repo.full_name) || getString(repo.fullName) || joinRepoName(repo) || getString(repo.name) || '-';
|
||||
const commitSha = getCommitSha(pipeline);
|
||||
const durationSeconds = getPipelineDurationSeconds(pipeline);
|
||||
|
||||
return {
|
||||
id: `${getString(repo.id) || repository}-${getString(pipeline.id) || getString(pipeline.number) || createdAt}`,
|
||||
repository,
|
||||
message: getString(pipeline.message) || getString(pipeline.title) || getString(pipeline.event) || '-',
|
||||
branch: getString(pipeline.branch) || '-',
|
||||
commitSha,
|
||||
durationSeconds,
|
||||
status: getString(pipeline.status) || '-',
|
||||
createdAt,
|
||||
ciUrl: baseUrl || null,
|
||||
@@ -121,6 +125,32 @@ function getPipelineTime(pipeline: WoodpeckerPipeline) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
function getCommitSha(pipeline: WoodpeckerPipeline) {
|
||||
return getString(pipeline.commit)
|
||||
|| getString(pipeline.commit_sha)
|
||||
|| getString(pipeline.sha)
|
||||
|| getString(pipeline.after)
|
||||
|| getString(pipeline.refspec);
|
||||
}
|
||||
|
||||
function getPipelineDurationSeconds(pipeline: WoodpeckerPipeline) {
|
||||
const startedAt = getPipelineTimestamp(pipeline.started ?? pipeline.started_at ?? pipeline.created ?? pipeline.created_at);
|
||||
const finishedAt = getPipelineTimestamp(pipeline.finished ?? pipeline.finished_at ?? pipeline.updated ?? pipeline.updated_at);
|
||||
if (!startedAt || !finishedAt || finishedAt < startedAt) return null;
|
||||
return Math.max(0, Math.round((finishedAt - startedAt) / 1000));
|
||||
}
|
||||
|
||||
function getPipelineTimestamp(value: unknown) {
|
||||
if (typeof value === 'number') return value > 10_000_000_000 ? value : value * 1000;
|
||||
if (typeof value === 'string') {
|
||||
const numeric = Number(value);
|
||||
if (Number.isFinite(numeric) && numeric > 0) return numeric > 10_000_000_000 ? numeric : numeric * 1000;
|
||||
const parsed = Date.parse(value);
|
||||
return Number.isFinite(parsed) ? parsed : 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function joinRepoName(repo: WoodpeckerRepo) {
|
||||
const owner = getString(repo.owner);
|
||||
const name = getString(repo.name);
|
||||
|
||||
Reference in New Issue
Block a user