fix: find hwlab pac runs in status
This commit is contained in:
@@ -220,10 +220,46 @@ pipeline_rows() {
|
||||
const fs = require('node:fs');
|
||||
const input = fs.readFileSync(process.argv[2], 'utf8') || '{"items":[]}';
|
||||
const data = input ? JSON.parse(input) : { items: [] };
|
||||
function firstString(...values) {
|
||||
for (const value of values) {
|
||||
if (typeof value === 'string' && value.length > 0) return value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function cond(item) {
|
||||
const c = (item.status?.conditions || []).find((x) => x.type === 'Succeeded') || {};
|
||||
return { status: c.status || '', reason: c.reason || '' };
|
||||
}
|
||||
function mapParams(params) {
|
||||
const out = {};
|
||||
for (const item of params || []) {
|
||||
if (!item || typeof item.name !== 'string') continue;
|
||||
if (typeof item.value === 'string') out[item.name] = item.value;
|
||||
else if (item.value !== undefined && item.value !== null) out[item.name] = JSON.stringify(item.value);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
function extractCommit(item, params) {
|
||||
const labels = item.metadata?.labels || {};
|
||||
const annotations = item.metadata?.annotations || {};
|
||||
return firstString(
|
||||
labels['pipelinesascode.tekton.dev/sha'],
|
||||
labels['pipelinesascode.tekton.dev/commit'],
|
||||
labels['agentrun.pikastech.local/source-commit'],
|
||||
labels['unidesk.ai/source-commit'],
|
||||
labels['hwlab.pikastech.local/source-commit'],
|
||||
annotations['pipelinesascode.tekton.dev/sha'],
|
||||
annotations['pipelinesascode.tekton.dev/commit'],
|
||||
annotations['unidesk.ai/source-commit'],
|
||||
params.revision,
|
||||
params.source_revision,
|
||||
params.sourceCommit,
|
||||
params.source_commit,
|
||||
params.git_sha,
|
||||
params.sha,
|
||||
params.commit
|
||||
);
|
||||
}
|
||||
function durationSeconds(item) {
|
||||
const start = item.status?.startTime;
|
||||
const done = item.status?.completionTime;
|
||||
@@ -231,17 +267,20 @@ function durationSeconds(item) {
|
||||
return Math.max(0, Math.round(((done ? Date.parse(done) : Date.now()) - Date.parse(start)) / 1000));
|
||||
}
|
||||
const prefix = process.env.UNIDESK_PAC_PIPELINE_RUN_PREFIX;
|
||||
const repository = process.env.UNIDESK_PAC_REPOSITORY_NAME;
|
||||
const pipeline = process.env.UNIDESK_PAC_PIPELINE_NAME;
|
||||
const rows = (data.items || [])
|
||||
.filter((item) => {
|
||||
const labels = item.metadata?.labels || {};
|
||||
return item.metadata?.name?.startsWith(prefix)
|
||||
&& labels['pipelinesascode.tekton.dev/repository'] === repository;
|
||||
const name = item.metadata?.name || '';
|
||||
return name.startsWith(prefix)
|
||||
|| labels['tekton.dev/pipeline'] === pipeline
|
||||
|| labels['tekton.dev/pipelineName'] === pipeline;
|
||||
})
|
||||
.sort((a, b) => Date.parse(b.metadata?.creationTimestamp || 0) - Date.parse(a.metadata?.creationTimestamp || 0))
|
||||
.slice(0, 8)
|
||||
.map((item) => {
|
||||
const c = cond(item);
|
||||
const params = mapParams(item.spec?.params);
|
||||
return {
|
||||
name: item.metadata.name,
|
||||
status: c.status,
|
||||
@@ -250,7 +289,7 @@ const rows = (data.items || [])
|
||||
startTime: item.status?.startTime || null,
|
||||
completionTime: item.status?.completionTime || null,
|
||||
durationSeconds: durationSeconds(item),
|
||||
sourceCommit: item.metadata.labels?.['pipelinesascode.tekton.dev/sha'] || item.metadata.labels?.['agentrun.pikastech.local/source-commit'] || item.metadata.labels?.['unidesk.ai/source-commit'] || item.metadata.labels?.['hwlab.pikastech.local/source-commit'] || null,
|
||||
sourceCommit: extractCommit(item, params),
|
||||
};
|
||||
});
|
||||
process.stdout.write(JSON.stringify(rows));
|
||||
|
||||
Reference in New Issue
Block a user