fix: render pac history times from yaml timezone
This commit is contained in:
@@ -265,6 +265,17 @@ const cp = require('node:child_process');
|
||||
const limit = Math.max(1, Math.min(50, Number.parseInt(process.env.UNIDESK_PAC_HISTORY_LIMIT || '5', 10) || 5));
|
||||
const detailId = process.env.UNIDESK_PAC_HISTORY_ID || '';
|
||||
const consumers = JSON.parse(Buffer.from(process.env.UNIDESK_PAC_HISTORY_CONSUMERS_B64 || 'W10=', 'base64').toString('utf8'));
|
||||
const displayTimeZone = process.env.UNIDESK_PAC_DISPLAY_TIME_ZONE || 'UTC';
|
||||
const displayTimeFormatter = new Intl.DateTimeFormat('sv-SE', {
|
||||
timeZone: displayTimeZone,
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit',
|
||||
hour12: false,
|
||||
});
|
||||
|
||||
function kubectlJson(args, fallback) {
|
||||
try {
|
||||
@@ -293,6 +304,13 @@ function durationSeconds(start, done) {
|
||||
return Math.max(0, Math.round((doneMs - startMs) / 1000));
|
||||
}
|
||||
|
||||
function formatDisplayTime(value) {
|
||||
if (!value) return null;
|
||||
const date = new Date(value);
|
||||
if (!Number.isFinite(date.getTime())) return null;
|
||||
return displayTimeFormatter.format(date);
|
||||
}
|
||||
|
||||
function mapParams(params) {
|
||||
const out = {};
|
||||
for (const item of params || []) {
|
||||
@@ -435,6 +453,10 @@ function rowFor(consumer, item, taskRuns) {
|
||||
triggeredAt: item.metadata?.creationTimestamp || item.status?.startTime || null,
|
||||
startTime: item.status?.startTime || null,
|
||||
completionTime: item.status?.completionTime || null,
|
||||
displayTime: formatDisplayTime(item.metadata?.creationTimestamp || item.status?.startTime || null),
|
||||
displayStartTime: formatDisplayTime(item.status?.startTime || null),
|
||||
displayCompletionTime: formatDisplayTime(item.status?.completionTime || null),
|
||||
displayTimeZone,
|
||||
durationSeconds: durationSeconds(item.status?.startTime || item.metadata?.creationTimestamp, item.status?.completionTime),
|
||||
status: c.status || null,
|
||||
reason: c.reason || null,
|
||||
@@ -650,7 +672,7 @@ history_action() {
|
||||
history=$(history_rows)
|
||||
rows=$(printf '%s' "$history" | node -e 'const fs=require("fs"); const h=JSON.parse(fs.readFileSync(0,"utf8")||"{}"); process.stdout.write(JSON.stringify(h.rows||[]));')
|
||||
consumers=$(printf '%s' "$history" | node -e 'const fs=require("fs"); const h=JSON.parse(fs.readFileSync(0,"utf8")||"{}"); process.stdout.write(JSON.stringify(h.consumers||[]));')
|
||||
printf '{"ok":%s,"crdPresent":%s,"controllerReady":"%s","repositoryCondition":"%s","repository":{"name":"%s","repo":"%s/%s","url":"%s"},"consumer":"%s","consumerRows":%s,"rows":%s,"webhooks":%s,"source":"gitea-pac-tekton-live","historyStore":"none","valuesPrinted":false}\n' \
|
||||
printf '{"ok":%s,"crdPresent":%s,"controllerReady":"%s","repositoryCondition":"%s","repository":{"name":"%s","repo":"%s/%s","url":"%s"},"consumer":"%s","display":{"timeZone":"%s"},"consumerRows":%s,"rows":%s,"webhooks":%s,"source":"gitea-pac-tekton-live","historyStore":"none","valuesPrinted":false}\n' \
|
||||
"$( [ -n "$crd" ] && [ "$controller_ready" != "0/0" ] && echo true || echo false )" \
|
||||
"$( [ -n "$crd" ] && echo true || echo false )" \
|
||||
"$(json_string "$controller_ready")" \
|
||||
@@ -660,6 +682,7 @@ history_action() {
|
||||
"$(json_string "$UNIDESK_PAC_GITEA_REPO")" \
|
||||
"$(json_string "$UNIDESK_PAC_REPOSITORY_URL")" \
|
||||
"$(json_string "$UNIDESK_PAC_CONSUMER_ID")" \
|
||||
"$(json_string "$UNIDESK_PAC_DISPLAY_TIME_ZONE")" \
|
||||
"$consumers" "$rows" "$hooks"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user