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

A connected forge shows Gitea's cup on imported repository pages, search results and the terminal #14341

opened this in answer to

Check · Review · Land · Live — No review yet. Next: reviewer, no review yet.

Ready to land

scout/forge:scout/14302-a-connected-forge-shows-gitea-s-cup-on-i → main 2 commits fork

Review

Sign in to review this change.
12 files changed +101 −15
src/core/repos.ts +6 −1
@@ -53,6 +53,8 @@ const log = createLog("repos");
5353 export interface RepoOrigin {
5454 readonly originId: string;
5555 readonly kind: "github" | "forgejo" | "gitea";
56 /** `forge` for another forge, which speaks Gitea's API; see `Origin.software`. */
57 readonly software: string;
5658 /** `owner/name` on the origin. */
5759 readonly fullName: string;
5860 readonly htmlUrl: string;
@@ -227,6 +229,7 @@ interface RepoRow {
227229 archived_at: string | null;
228230 origin_id: string | null;
229231 origin_kind: "github" | "forgejo" | "gitea" | null;
232 origin_software: string | null;
230233 origin_full_name: string | null;
231234 origin_html_url: string | null;
232235 last_fetch_at: string | null;
@@ -237,7 +240,8 @@ interface RepoRow {
237240 // LEFT JOIN, because the origin may have been disconnected out from under a
238241 // mirror — the repo survives, the link does not.
239242 const SELECT = `
240 SELECT repo.*, user.username AS owner_name, origin.kind AS origin_kind
243 SELECT repo.*, user.username AS owner_name, origin.kind AS origin_kind,
244 origin.software AS origin_software
241245 FROM repo JOIN user ON user.id = repo.owner_id
242246 LEFT JOIN origin ON origin.id = repo.origin_id`;
243247
@@ -277,6 +281,7 @@ function toRepo(row: RepoRow): Repo {
277281 ? {
278282 originId: row.origin_id,
279283 kind: row.origin_kind,
284 software: row.origin_software ?? "",
280285 fullName: row.origin_full_name ?? "",
281286 htmlUrl: row.origin_html_url ?? "",
282287 lastFetchAt: row.last_fetch_at,
src/core/search.ts +4 −1
@@ -111,6 +111,7 @@ export type RepoHit =
111111 readonly source: "origin";
112112 readonly originId: string;
113113 readonly originKind: string;
114 readonly originSoftware: string;
114115 readonly fullName: string;
115116 readonly description: string;
116117 readonly private: boolean;
@@ -309,6 +310,7 @@ function describedRepos(
309310 interface OriginRepoHitRow {
310311 origin_id: string;
311312 origin_kind: string;
313 origin_software: string;
312314 full_name: string;
313315 description: string;
314316 private: number;
@@ -334,7 +336,7 @@ export function searchOriginRepos(
334336 const like = `%${likeEscape(query.trim())}%`;
335337 const rows = db
336338 .query<OriginRepoHitRow, [string, string, number]>(
337 `SELECT origin_repo.origin_id, origin.kind AS origin_kind,
339 `SELECT origin_repo.origin_id, origin.kind AS origin_kind, origin.software AS origin_software,
338340 origin_repo.full_name, origin_repo.description,
339341 origin_repo.private, origin_repo.html_url,
340342 origin_repo.open_issues, origin_repo.open_pulls,
@@ -357,6 +359,7 @@ export function searchOriginRepos(
357359 source: "origin" as const,
358360 originId: row.origin_id,
359361 originKind: row.origin_kind,
362 originSoftware: row.origin_software,
360363 fullName: row.full_name,
361364 description: row.description,
362365 private: row.private === 1,
src/tui/screens/connections.ts +2 −1
@@ -14,6 +14,7 @@ import { binding } from "../app/keys.ts";
1414 import { style } from "../term/style.ts";
1515 import { truncate } from "../term/width.ts";
1616 import type { Session } from "../session.ts";
17 import { icon, originMark } from "../ui/icons.ts";
1718 import { fill, len, split } from "../ui/layout.ts";
1819 import { ListState, confirmScreen, drawList, later, promptScreen } from "./common.ts";
1920 import type { PaletteEntry } from "./entries.ts";
@@ -53,7 +54,7 @@ export function connectionsScreen(f: Session, ctx: Ctx): Screen {
5354 all.map((o) => {
5455 const k = n.get(o.id)?.count ?? 0;
5556 return {
56 title: `${host(o.webUrl)} · ${o.login}`,
57 title: `${icon(originMark(o), ctx.icons)} ${host(o.webUrl)} · ${o.login}`,
5758 ...(o.lastError !== "" || writesPaused(f.app, o.id) !== undefined ? { tone: "danger" as const } : {}),
5859 secondary: `${o.software === "forge" ? "another forge · " : ""}${o.readOnly ? "read-only · " : ""}${k} repositor${k === 1 ? "y" : "ies"} · ${day(o.lastSyncAt)}`,
5960 meta: o.lastError !== "" ? o.lastError : writesPaused(f.app, o.id) !== undefined ? "writes paused" : o.authKind === "oauth" ? "OAuth" : "token",
src/tui/ui/icons.ts +12
@@ -55,6 +55,8 @@ export type IconName =
5555 | "origin"
5656 | "github"
5757 | "forgejo"
58 | "gitea"
59 | "anvil"
5860 | "gitlab"
5961 // marks
6062 | "warning"
@@ -110,6 +112,8 @@ const ICONS: Readonly<Record<IconName, Pair>> = {
110112 origin: { plain: G.chevron, nerd: "\u{f484}" }, // nf-oct-globe
111113 github: { plain: G.diamond, nerd: "\u{f408}" }, // nf-oct-mark_github
112114 forgejo: { plain: G.diamond, nerd: "\u{e910}" }, // nf-dev-forgejo
115 gitea: { plain: G.diamond, nerd: "\u{f0176}" }, // nf-md-coffee: the cup
116 anvil: { plain: G.diamond, nerd: "\u{f0ab5}" }, // nf-md-anvil
113117 gitlab: { plain: G.diamond, nerd: "\u{f296}" }, // nf-fa-gitlab
114118 warning: { plain: G.up, nerd: "\u{f421}" }, // nf-oct-alert
115119 check: { plain: G.check, nerd: "\u{f42e}" }, // nf-oct-check
@@ -132,6 +136,14 @@ export function icon(name: IconName, set: IconSet): string {
132136 return set === "nerd" ? pair.nerd : pair.plain;
133137 }
134138
139 /** The mark an origin wears: another forge speaks Gitea's API, so `software` decides the anvil. */
140 export function originMark(origin: {
141 readonly kind: "github" | "forgejo" | "gitea";
142 readonly software?: string;
143 }): IconName {
144 return origin.software === "forge" ? "anvil" : origin.kind;
145 }
146
135147 /** Every name in the table — what a settings preview iterates. */
136148 export function iconNames(): IconName[] {
137149 return Object.keys(ICONS) as IconName[];
src/web/pages/browse.ts +1 −1
@@ -300,7 +300,7 @@ function summaryRow(
300300
301301 /** The mark an imported author wears on this scope. */
302302 function scopeGlyph(scope: RepoScope): IconName {
303 return scope.origin ? originIcon(scope.origin) : (scope.repo?.origin?.kind ?? "globe");
303 return scope.origin ? originIcon(scope.origin) : (scope.repo?.origin ? originIcon(scope.repo.origin) : "globe");
304304 }
305305
306306 /** A `ListQuery` as the source's own query shape. */
src/web/pages/commits.ts +6 −1
@@ -10,6 +10,7 @@
1010 * list can do neither, so the live browse pages by cursor and says so.
1111 */
1212
13 import { originIcon } from "./origins.ts";
1314 import { immutableWhenAddressed } from "../../http/addressed.ts";
1415 import { checkOfCommit, verdictsOfCommits } from "../../actions/runs.ts";
1516 import type { CommitCheck } from "../../checks/commit_check.ts";
@@ -165,7 +166,11 @@ export function renderCommit(
165166 ${commit.login
166167 ? originTag(
167168 commit.login,
168 scope.origin?.kind ?? scope.repo?.origin?.kind ?? "globe",
169 scope.origin
170 ? originIcon(scope.origin)
171 : scope.repo?.origin
172 ? originIcon(scope.repo.origin)
173 : "globe",
169174 )
170175 : avatar(commit.author)}
171176 <span>${commit.author} committed ${time(commit.date)}</span>
src/web/pages/search.ts +6 −7
@@ -10,6 +10,7 @@
1010 * that was never meant to be confirmed.
1111 */
1212
13 import { originIcon } from "./origins.ts";
1314 import { ARCHIVE_DETAIL, RESTORE_DETAIL, archiveTitle, restoreTitle } from "../../core/archive-words.ts";
1415 import { cappedQuery, echoed, queryTooLong, QUERY_TRIMMED_NOTE } from "../../core/query_limit.ts";
1516 import { returnTo, withReturn } from "../return_to.ts";
@@ -166,13 +167,11 @@ function repoHitRow(ctx: Ctx, apps: Apps, hit: RepoHit): Html {
166167 href: browseBase(hit.originId, hit.fullName),
167168 nav: true,
168169 lead: icon(
169 hit.originKind === "github"
170 ? "github"
171 : hit.originKind === "forgejo"
172 ? "forgejo"
173 : hit.originKind === "gitea"
174 ? "gitea"
175 : "globe",
170 hit.originKind === "github" ||
171 hit.originKind === "forgejo" ||
172 hit.originKind === "gitea"
173 ? originIcon({ kind: hit.originKind, software: hit.originSoftware })
174 : "globe",
176175 ),
177176 title: hit.fullName,
178177 titleAttr: hit.fullName,
src/web/pages/thread.ts +2 −1
@@ -8,6 +8,7 @@
88 * is what makes a long thread skimmable.
99 */
1010
11 import { originIcon } from "./origins.ts";
1112 import { TELL_LIMIT_WORDS, TELL_TEXT_MAX } from "../../actions/tell_from.ts";
1213 import { returnTo, withReturn } from "../return_to.ts";
1314 import { mayView } from "../../core/sealed.ts";
@@ -111,7 +112,7 @@ export function originError(error: string): string | undefined {
111112
112113 /** The origin's mark, when this repo has one. */
113114 export function originGlyph(repo: Repo): Glyph {
114 return repo.origin?.kind ?? "globe";
115 return repo.origin ? originIcon(repo.origin) : "globe";
115116 }
116117
117118 /** An issue number from a URL segment: digits only, and never a leading zero. */
src/web/scope.ts +2 −1
@@ -43,6 +43,7 @@ import { localSource } from "../view/local.ts";
4343 import { html, when, type Html } from "./html.ts";
4444 import { repoSteps } from "./repo_steps.ts";
4545 import { icon, type IconName } from "./icons.ts";
46 import { originIcon } from "./pages/origins.ts";
4647 import type { PaletteItem } from "./layout.ts";
4748 import { time, timeAgo } from "./ui.ts";
4849
@@ -354,7 +355,7 @@ function placesFor(ctx: Ctx, scope: RepoScope): Place[] {
354355 label: hostOf(scope.origin.webUrl),
355356 state: "reading",
356357 glyph: "●",
357 icon: scope.origin.kind,
358 icon: originIcon(scope.origin),
358359 ...(scope.originUrl === ""
359360 ? {}
360361 : { href: scope.originUrl, external: true }),
test/origins-page-shape.test.ts +51 −1
@@ -4,7 +4,10 @@ import { mkdtempSync, rmSync } from "node:fs";
44 import { tmpdir } from "node:os";
55 import { join } from "node:path";
66 import { createApp, type App } from "../src/app.ts";
7 import { createRepo } from "../src/core/repos.ts";
7 import { createRepo, getRepo } from "../src/core/repos.ts";
8 import { originGlyph } from "../src/web/pages/thread.ts";
9 import { searchOriginRepos } from "../src/core/search.ts";
10 import { rememberOriginRepo } from "../src/core/origins.ts";
811 import { createOrigin, linkRepoToOrigin } from "../src/core/origins.ts";
912 import { createUser, getUserByName } from "../src/core/users.ts";
1013 import { serve, type Servers } from "../src/http/server.ts";
@@ -183,3 +186,50 @@ test("an origin's after slot is a full-width block under the row, so it fits a 3
183186 expect(rule).toContain("min-width: 0");
184187 expect(rule).toContain("overflow-wrap: anywhere");
185188 });
189
190 test("a mirror from another forge carries software to its page query, search and the thread glyph", async () => {
191 const alice = getUserByName(app.db, "alice")!;
192 const o = createOrigin(app.db, root, {
193 userId: alice.id,
194 kind: "gitea",
195 apiUrl: "https://anvil.example.org/api/v1",
196 webUrl: "https://anvil.example.org",
197 login: "anvil",
198 token: "t0ken",
199 software: "forge",
200 });
201 if (!o.ok) throw new Error("origin");
202 const repo = await createRepo(app.db, root, { ownerId: alice.id, name: "anvil-mirror" });
203 if (!repo.ok) throw new Error("repo");
204 linkRepoToOrigin(app.db, repo.value.id, {
205 originId: o.value.id,
206 fullName: "smith/widgets",
207 remoteId: "77",
208 htmlUrl: "https://anvil.example.org/smith/widgets",
209 });
210 rememberOriginRepo(app.db, o.value.id, {
211 remoteId: "77",
212 fullName: "smith/widgets",
213 owner: "smith",
214 name: "widgets",
215 description: "",
216 private: false,
217 fork: false,
218 parent: null,
219 defaultBranch: "main",
220 cloneUrl: "",
221 sshUrl: "",
222 htmlUrl: "https://anvil.example.org/smith/widgets",
223 pushedAt: null,
224 permissions: { push: false, admin: false },
225 openIssues: 0,
226 openPulls: 0,
227 openIssuesIncludesPulls: false,
228 } as never);
229 const got = getRepo(app.db, "alice", "anvil-mirror")!;
230 expect(got.origin?.software).toBe("forge");
231 expect(originGlyph(got)).toBe("anvil");
232 const hits = searchOriginRepos(app.db, alice.id, "widgets", 10);
233 const hit = hits[0];
234 expect(hit?.source === "origin" && hit.originSoftware).toBe("forge");
235 });
test/tui-icons.test.ts +8
@@ -29,6 +29,7 @@ import {
2929 icon,
3030 iconNames,
3131 looksLikeImage,
32 originMark,
3233 type IconName,
3334 } from "../src/tui/ui/icons.ts";
3435 import { clusterWidth, clusters, displayWidth } from "../src/tui/term/width.ts";
@@ -376,3 +377,10 @@ describe("the icon set a session actually draws", () => {
376377 }
377378 });
378379 });
380
381 test("another forge's origin gets the anvil in the terminal; a Gitea one keeps the cup", () => {
382 expect(originMark({ kind: "gitea", software: "forge" })).toBe("anvil");
383 expect(originMark({ kind: "gitea", software: "" })).toBe("gitea");
384 expect(originMark({ kind: "github" })).toBe("github");
385 expect(iconNames()).toContain("anvil");
386 });
test/tui-take-back.test.ts +1
@@ -198,6 +198,7 @@ test("a mirrored repository shows no key", async () => {
198198 origin: {
199199 originId: "o1",
200200 kind: "github",
201 software: "",
201202 fullName: "up/lib",
202203 htmlUrl: "https://example.test/up/lib",
203204 lastFetchAt: null,

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs