Files
board-viewer/src/reader.ts
vitya 469ff112cc feat(polish): close all 6 review nitpicks in one sweep
closes board-viewer-polish

- M1 src/parser.ts: comment explaining why **Status:** text field is intentionally
  ignored (emoji is canonical, prevents future-reader head-scratch)
- M2 src/render.ts + tests: clamp future ISO to '0m' (server clock drift safety)
  + inline comment + test
- M3 .tasks/board-viewer-gitea-reader.md: decisions-log clarifying orphan
  per-task files are out of scope by design (STATUS.md = index of record)
- M4 static/board.{js,css} + src/render.ts: filter rebuilt to query records
  (not DOM badge text); 5 status-filter pill buttons in header with active
  toggle state; smoke-verified blocked filter
- M5 deploy/Dockerfile.build: HEALTHCHECK (file fresher than 2×tick) and
  stderr redirect for failures with timestamp
- M6 src/reader.ts: parallelize getLatestCommitIso per-repo via Promise.all
  (preserves block order)

49 tests pass (was 43 pre-polish), typecheck clean, smoke against real Gitea
returns 81 records from 4 repos.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 15:46:47 +03:00

63 lines
1.7 KiB
TypeScript

import type { GiteaClient } from './gitea.ts';
import { parseStatus, type Status, type StatusEmoji } from './parser.ts';
export interface RepoRef {
owner: string;
repo: string;
}
export interface TaskRecord {
slug: string;
project: string;
project_owner: string;
status: Status;
status_emoji: StatusEmoji;
title: string;
where_stopped: string | null;
next_action: string | null;
blocker: string | null;
branch: string | null;
last_commit_iso: string | null;
raw_url: string;
}
export async function readBoard(
client: GiteaClient,
repos: ReadonlyArray<RepoRef>,
): Promise<TaskRecord[]> {
const records: TaskRecord[] = [];
for (const { owner, repo } of repos) {
const status = await client.getFile(owner, repo, '.tasks/STATUS.md');
if (status === null) continue;
const blocks = parseStatus(status);
// Parallel fan-out for per-task commit-iso fetches. Preserves block order
// because Promise.all resolves arrays positionally.
const isoList = await Promise.all(
blocks.map((b) => client.getLatestCommitIso(owner, repo, `.tasks/${b.slug}.md`)),
);
for (let i = 0; i < blocks.length; i++) {
const block = blocks[i]!;
const taskPath = `.tasks/${block.slug}.md`;
records.push({
slug: block.slug,
project: repo,
project_owner: owner,
status: block.status,
status_emoji: block.status_emoji,
title: block.title,
where_stopped: block.where_stopped,
next_action: block.next_action,
blocker: block.blocker,
branch: block.branch,
last_commit_iso: isoList[i]!,
raw_url: client.rawUrl(owner, repo, taskPath),
});
}
}
return records;
}