fix: render pac history times from yaml timezone
This commit is contained in:
@@ -50,6 +50,9 @@ interface PacConfig {
|
||||
targetId: string;
|
||||
consumerId: string;
|
||||
};
|
||||
display: {
|
||||
timeZone: string;
|
||||
};
|
||||
release: {
|
||||
version: string;
|
||||
manifestUrl: string;
|
||||
@@ -192,6 +195,7 @@ function readPacConfig(): PacConfig {
|
||||
const root = readYamlRecord<Record<string, unknown>>(configFile, "platform-infra-pipelines-as-code");
|
||||
const release = y.objectField(root, "release", "");
|
||||
const gitea = y.objectField(root, "gitea", "");
|
||||
const display = y.objectField(root, "display", "");
|
||||
const admin = y.objectField(gitea, "admin", "gitea");
|
||||
const webhook = y.objectField(gitea, "webhook", "gitea");
|
||||
const repositories = root.repositories === undefined
|
||||
@@ -214,6 +218,9 @@ function readPacConfig(): PacConfig {
|
||||
targetId: y.stringField(defaults, "targetId", "defaults"),
|
||||
consumerId: typeof defaults.consumerId === "string" && defaults.consumerId.length > 0 ? defaults.consumerId : consumers[0]?.id ?? "default",
|
||||
},
|
||||
display: {
|
||||
timeZone: y.stringField(display, "timeZone", "display"),
|
||||
},
|
||||
release: {
|
||||
version: y.stringField(release, "version", "release"),
|
||||
manifestUrl: urlField(release, "manifestUrl", "release"),
|
||||
@@ -313,6 +320,7 @@ function validateConfig(config: PacConfig): void {
|
||||
if (repository.namespace !== consumer.namespace) throw new Error(`${configLabel}.consumers.${consumer.id}.namespace must match repository namespace`);
|
||||
}
|
||||
if (!config.gitea.webhook.events.includes("push")) throw new Error(`${configLabel}.gitea.webhook.events must include push`);
|
||||
validateTimeZone(config.display.timeZone, `${configLabel}.display.timeZone`);
|
||||
}
|
||||
|
||||
function resolveTarget(config: PacConfig, targetId: string | null): PacTarget {
|
||||
@@ -426,6 +434,7 @@ async function history(config: UniDeskConfig, options: HistoryOptions): Promise<
|
||||
path: configLabel,
|
||||
source: "Gitea Repository CR + Tekton PipelineRun/TaskRun live objects; no UniDesk-owned history store is written.",
|
||||
limitPerConsumer: options.limit,
|
||||
displayTimeZone: pac.display.timeZone,
|
||||
valuesPrinted: false,
|
||||
},
|
||||
consumers: selectedConsumers.map((consumer) => consumer.id),
|
||||
@@ -497,6 +506,7 @@ function remoteScript(action: "apply" | "status" | "history" | "webhook-test", p
|
||||
UNIDESK_PAC_HISTORY_LIMIT: "limit" in options ? String(options.limit) : "5",
|
||||
UNIDESK_PAC_HISTORY_ID: "detailId" in options && options.detailId !== null ? options.detailId : "",
|
||||
UNIDESK_PAC_HISTORY_CONSUMERS_B64: Buffer.from(JSON.stringify(historyConsumers.map((item) => historyConsumerConfig(pac, item))), "utf8").toString("base64"),
|
||||
UNIDESK_PAC_DISPLAY_TIME_ZONE: pac.display.timeZone,
|
||||
UNIDESK_PAC_ARGO_NAMESPACE: consumer.argoNamespace,
|
||||
UNIDESK_PAC_ARGO_APPLICATION: consumer.argoApplication,
|
||||
UNIDESK_PAC_PART_OF: pacPartOf(consumer.id),
|
||||
@@ -642,6 +652,7 @@ function configSummary(pac: PacConfig, consumer: PacConsumer, repository: PacRep
|
||||
metadata: pac.metadata,
|
||||
release: pac.release,
|
||||
gitea: { configRef: pac.gitea.configRef, internalBaseUrl: pac.gitea.internalBaseUrl, webhookBranch: pac.gitea.webhook.branch },
|
||||
display: pac.display,
|
||||
repositories: pac.repositories.map(repositorySummary),
|
||||
consumers: pac.consumers,
|
||||
repository: repositorySummary(repository),
|
||||
@@ -657,6 +668,7 @@ function compactConfigSummary(pac: PacConfig, consumer: PacConsumer, repository:
|
||||
repository: repository.name,
|
||||
providerType: repository.providerType,
|
||||
sourceUrl: repository.cloneUrl,
|
||||
displayTimeZone: pac.display.timeZone,
|
||||
consumer: `${consumer.node}/${consumer.lane}`,
|
||||
consumerId: consumer.id,
|
||||
pipeline: consumer.pipeline,
|
||||
@@ -775,14 +787,15 @@ function renderHistory(result: Record<string, unknown>): RenderedCliResult {
|
||||
const rows = arrayRecords(result.rows);
|
||||
const config = record(result.config);
|
||||
const detailId = stringValue(result.detailId);
|
||||
const timeHeader = `TIME(${stringValue(config.displayTimeZone)})`;
|
||||
const lines = [
|
||||
"PLATFORM-INFRA PIPELINES-AS-CODE HISTORY",
|
||||
`DATA: ${stringValue(config.source)}`,
|
||||
`ROWS: ${stringValue(rows.length)} LIMIT_PER_CONSUMER: ${stringValue(config.limitPerConsumer)}`,
|
||||
"",
|
||||
"TRIGGERS",
|
||||
...(rows.length === 0 ? ["-"] : table(["TIME", "CONSUMER", "REPO", "STATUS", "DUR_S", "COMMIT", "ENV_REUSE", "ID"], rows.map((row) => [
|
||||
isoShort(stringValue(row.triggeredAt)),
|
||||
...(rows.length === 0 ? ["-"] : table([timeHeader, "CONSUMER", "REPO", "STATUS", "DUR_S", "COMMIT", "ENV_REUSE", "ID"], rows.map((row) => [
|
||||
stringValue(row.displayTime) === "-" ? isoShort(stringValue(row.triggeredAt)) : stringValue(row.displayTime),
|
||||
stringValue(row.consumer),
|
||||
stringValue(row.repo),
|
||||
statusText(row),
|
||||
@@ -920,6 +933,14 @@ function urlField(obj: Record<string, unknown>, key: string, path: string): stri
|
||||
return value.replace(/\/+$/u, "");
|
||||
}
|
||||
|
||||
function validateTimeZone(value: string, path: string): void {
|
||||
try {
|
||||
new Intl.DateTimeFormat("en-US", { timeZone: value }).format(new Date(0));
|
||||
} catch (error) {
|
||||
throw new Error(`${path} must be a valid IANA time zone: ${(error as Error).message}`);
|
||||
}
|
||||
}
|
||||
|
||||
function stringRecord(obj: Record<string, unknown>, path: string): Record<string, string> {
|
||||
const out: Record<string, string> = {};
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
@@ -1001,8 +1022,8 @@ function renderHistoryDetail(row: Record<string, unknown>): string[] {
|
||||
["pipeline", stringValue(row.pipeline)],
|
||||
["branch", stringValue(row.branch)],
|
||||
["commit", stringValue(row.commit)],
|
||||
["started", stringValue(row.startTime)],
|
||||
["completed", stringValue(row.completionTime)],
|
||||
["started", stringValue(row.displayStartTime) === "-" ? stringValue(row.startTime) : stringValue(row.displayStartTime)],
|
||||
["completed", stringValue(row.displayCompletionTime) === "-" ? stringValue(row.completionTime) : stringValue(row.displayCompletionTime)],
|
||||
["taskRuns", stringValue(taskRuns.count)],
|
||||
["longestTask", stringValue(longest.name)],
|
||||
["longestTaskDurationS", stringValue(longest.durationSeconds)],
|
||||
|
||||
Reference in New Issue
Block a user