Public: anyone can read this; the crew can change it.

Follow upstream's "last checked" speaks the UI's one clock: `time()`, not a hand-rolled HH:MM UTC #16902

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/4016-follow-upstream-s-last-checked-speaks-th → main 0 commits fork

  • Merged. scout/4016-follow-upstream-s-last-checked-speaks-th was merged into main as 8fd7cde.

Review

Sign in to review this change.
4 files changed +27 −19
docs/ORIGINS.md +1 −1
@@ -873,7 +873,7 @@ environment — never in the URL, never in argv. Nothing is stored in the
873873 repository. A check's failure message is the remote's stderr with secrets
874874 redacted, shown to admins only.
875875
876 The About card says "Following <upstream> · last checked HH:MM · N behind",
876 The About card says "Following <upstream> · last checked 5m ago · N behind",
877877 to admins only. API, all admin-only (anyone else gets 404):
878878 `GET|PUT /api/v1/repos/:owner/:name/upstream` (PUT takes
879879 `{url, branch, enabled}`) and `POST …/upstream/check`.
src/actions/upstream_follow.ts −6
@@ -1041,12 +1041,6 @@ export function behindFor(
10411041 return level ? { checkedAt, text: "up to date", conflict: false, admin } : null;
10421042 }
10431043
1044 /** HH:MM, UTC. */
1045 export const clockWords = (iso: string): string => {
1046 const at = new Date(iso);
1047 return Number.isNaN(at.getTime()) ? "" : at.toISOString().slice(11, 16);
1048 };
1049
10501044 /** Where a following stands: what the last check read. */
10511045 export function standing(f: UpstreamFollow): string {
10521046 if (!f.enabled) return f.severedAt === null ? "off" : "severed";
src/web/pages/upstream-follow.ts +3 −12
@@ -10,7 +10,6 @@ import {
1010 checkedWords,
1111 checkLine,
1212 checkUpstreamNow,
13 clockWords,
1413 conflictWaitingWords,
1514 crewResolvesWords,
1615 FOLLOW_REFUSALS,
@@ -54,14 +53,6 @@ function backTo(form: Awaited<ReturnType<typeof readForm>> & object, fallback: s
5453 return typeof back === "string" && isLocalPath(back) ? back : fallback;
5554 }
5655
57 /** HH:MM in UTC, with the instant for machines and the title for people. */
58 function clock(iso: string): Html {
59 const at = new Date(iso);
60 if (Number.isNaN(at.getTime())) return html``;
61 const exact = `${at.toISOString().slice(0, 16).replace("T", " ")} UTC`;
62 return html`<time datetime="${at.toISOString()}" title="${exact}">${clockWords(iso)}</time>`;
63 }
64
6556 /** The About card's line, for admins; null for everyone else. */
6657 export function followingLine(ctx: Ctx, repo: Repo): Html | null {
6758 const follow = followShown(ctx.app, repo, ctx.auth.user);
@@ -89,7 +80,7 @@ export function followingLine(ctx: Ctx, repo: Repo): Html | null {
8980 ${icon("sync")} Following
9081 <a href="${follow.url}" rel="noreferrer noopener">${upstreamLabel(follow.url)}</a>
9182 <span class="mono">${follow.branch}</span>
92 ${follow.checkedAt === null ? null : html`· last checked ${clock(follow.checkedAt)}`}
83 ${follow.checkedAt === null ? null : html`· last checked ${time(follow.checkedAt)}`}
9384 · ${standing(follow)}
9485 </p>`;
9586 }
@@ -208,7 +199,7 @@ export function followUpstreamCard(ctx: Ctx, repo: Repo, choice: Html | null = n
208199 ${when(
209200 follow,
210201 (f) => html`<p class="hint" data-following-standing>${standing(f)}${
211 f.checkedAt === null ? "" : html` · last checked ${clock(f.checkedAt)}`
202 f.checkedAt === null ? "" : html` · last checked ${time(f.checkedAt)}`
212203 }${f.error === "" ? "" : html` · ${f.error}`} · ${f.opened} proposed so far</p>`,
213204 )}
214205 ${historyList(ctx, repo)}
@@ -306,7 +297,7 @@ function sourceLine(base: string, s: FollowSource): Html {
306297 lead: icon("sync"),
307298 title: html`<a href="${s.url}" rel="noreferrer noopener">${upstreamShort(s.url)}</a> <span class="mono">${s.branch}</span>`,
308299 meta: html`${stamp === undefined ? "" : `${stamp.account}@${stamp.host}`} · ${stand}${
309 s.checkedAt === null ? "" : html` · checked ${clock(s.checkedAt)}`
300 s.checkedAt === null ? "" : html` · checked ${time(s.checkedAt)}`
310301 }`,
311302 trail: html`<form method="post" action="${base}/settings/sources/${s.id}/remove" class="row-fields">
312303 ${btn("Remove", { size: "sm", variant: "outline", label: `Stop following ${upstreamShort(s.url)}` })}
test/upstream_follow.test.ts +23
@@ -27,6 +27,8 @@ import { getPull, listPulls } from "../src/core/pulls.ts";
2727 import { getRepoById, type Repo } from "../src/core/repos.ts";
2828 import { createUser, type User } from "../src/core/users.ts";
2929 import { checkDue, checkUpstream, mayCarryCredential } from "../src/actions/upstream_follow.ts";
30 import { followingLine } from "../src/web/pages/upstream-follow.ts";
31 import type { Ctx } from "../src/http/context.ts";
3032 import { createOrigin } from "../src/core/origins.ts";
3133 import { runGit } from "../src/git/env.ts";
3234 import { REMOTE_PROTOCOLS } from "../src/git/remote-env.ts";
@@ -148,6 +150,27 @@ describe("the follow row", () => {
148150 });
149151 });
150152
153 describe("the About line's clock", () => {
154 test("last checked is the UI's relative time with the exact instant in datetime", () => {
155 const at = new Date(Date.now() - 5 * 60_000).toISOString();
156 putFollow(app.db, { repoId: repo.id, url: "https://example.com/a/b.git", branch: "main", enabled: true, byId: alice.id, originId: "" });
157 noteCheck(app.db, repo.id, { at, tip: "abc", behind: 0, error: "", ahead: 0 });
158 const ctx: Ctx = {
159 app,
160 request: new Request("http://forge.test/"),
161 url: new URL("http://forge.test/"),
162 params: {},
163 auth: { user: alice, scope: undefined, via: "session" },
164 theme: undefined,
165 };
166 const line = followingLine(ctx, repo)?.toString() ?? "";
167 expect(line).toContain("last checked");
168 expect(line).toContain(`datetime="${at}"`);
169 expect(line).toMatch(/>\s*5m ago\s*</);
170 expect(line).not.toMatch(/\d\d:\d\d<\/time>/);
171 });
172 });
173
151174 describe("who hears of it", () => {
152175 test("a guest's events do not carry the URL; an admin's do", () => {
153176 const secret = "https://private.example.com/secret/repo.git";

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs