From b35c486ae9bbf7842ea7fe82757cae25e7473dc2 Mon Sep 17 00:00:00 2001 From: chyoo Date: Thu, 9 Jul 2026 10:23:37 +0900 Subject: [PATCH] show common app pipeline sha and duration --- src/woodpecker/woodpecker.service.ts | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/woodpecker/woodpecker.service.ts b/src/woodpecker/woodpecker.service.ts index 5ea3a20..e83478d 100644 --- a/src/woodpecker/woodpecker.service.ts +++ b/src/woodpecker/woodpecker.service.ts @@ -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);