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
Check · Review · Land · Live — No review yet.
scout/forge:scout/14302-a-connected-forge-shows-gitea-s-cup-on-i → main 2 commits fork
12 files
changed +101
−15
src/core/repos.ts +6 −1
| @@ -53,6 +53,8 @@ const log = createLog("repos"); | ||
| 53 | 53 | export interface RepoOrigin { |
| 54 | 54 | readonly originId: string; |
| 55 | 55 | readonly kind: "github" | "forgejo" | "gitea"; |
| 56 | /** `forge` for another forge, which speaks Gitea's API; see `Origin.software`. */ | |
| 57 | readonly software: string; | |
| 56 | 58 | /** `owner/name` on the origin. */ |
| 57 | 59 | readonly fullName: string; |
| 58 | 60 | readonly htmlUrl: string; |
| @@ -227,6 +229,7 @@ interface RepoRow { | ||
| 227 | 229 | archived_at: string | null; |
| 228 | 230 | origin_id: string | null; |
| 229 | 231 | origin_kind: "github" | "forgejo" | "gitea" | null; |
| 232 | origin_software: string | null; | |
| 230 | 233 | origin_full_name: string | null; |
| 231 | 234 | origin_html_url: string | null; |
| 232 | 235 | last_fetch_at: string | null; |
| @@ -237,7 +240,8 @@ interface RepoRow { | ||
| 237 | 240 | // LEFT JOIN, because the origin may have been disconnected out from under a |
| 238 | 241 | // mirror — the repo survives, the link does not. |
| 239 | 242 | 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 | |
| 241 | 245 | FROM repo JOIN user ON user.id = repo.owner_id |
| 242 | 246 | LEFT JOIN origin ON origin.id = repo.origin_id`; |
| 243 | 247 | |
| @@ -277,6 +281,7 @@ function toRepo(row: RepoRow): Repo { | ||
| 277 | 281 | ? { |
| 278 | 282 | originId: row.origin_id, |
| 279 | 283 | kind: row.origin_kind, |
| 284 | software: row.origin_software ?? "", | |
| 280 | 285 | fullName: row.origin_full_name ?? "", |
| 281 | 286 | htmlUrl: row.origin_html_url ?? "", |
| 282 | 287 | lastFetchAt: row.last_fetch_at, |
src/core/search.ts +4 −1
| @@ -111,6 +111,7 @@ export type RepoHit = | ||
| 111 | 111 | readonly source: "origin"; |
| 112 | 112 | readonly originId: string; |
| 113 | 113 | readonly originKind: string; |
| 114 | readonly originSoftware: string; | |
| 114 | 115 | readonly fullName: string; |
| 115 | 116 | readonly description: string; |
| 116 | 117 | readonly private: boolean; |
| @@ -309,6 +310,7 @@ function describedRepos( | ||
| 309 | 310 | interface OriginRepoHitRow { |
| 310 | 311 | origin_id: string; |
| 311 | 312 | origin_kind: string; |
| 313 | origin_software: string; | |
| 312 | 314 | full_name: string; |
| 313 | 315 | description: string; |
| 314 | 316 | private: number; |
| @@ -334,7 +336,7 @@ export function searchOriginRepos( | ||
| 334 | 336 | const like = `%${likeEscape(query.trim())}%`; |
| 335 | 337 | const rows = db |
| 336 | 338 | .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, | |
| 338 | 340 | origin_repo.full_name, origin_repo.description, |
| 339 | 341 | origin_repo.private, origin_repo.html_url, |
| 340 | 342 | origin_repo.open_issues, origin_repo.open_pulls, |
| @@ -357,6 +359,7 @@ export function searchOriginRepos( | ||
| 357 | 359 | source: "origin" as const, |
| 358 | 360 | originId: row.origin_id, |
| 359 | 361 | originKind: row.origin_kind, |
| 362 | originSoftware: row.origin_software, | |
| 360 | 363 | fullName: row.full_name, |
| 361 | 364 | description: row.description, |
| 362 | 365 | private: row.private === 1, |
src/tui/screens/connections.ts +2 −1
| @@ -14,6 +14,7 @@ import { binding } from "../app/keys.ts"; | ||
| 14 | 14 | import { style } from "../term/style.ts"; |
| 15 | 15 | import { truncate } from "../term/width.ts"; |
| 16 | 16 | import type { Session } from "../session.ts"; |
| 17 | import { icon, originMark } from "../ui/icons.ts"; | |
| 17 | 18 | import { fill, len, split } from "../ui/layout.ts"; |
| 18 | 19 | import { ListState, confirmScreen, drawList, later, promptScreen } from "./common.ts"; |
| 19 | 20 | import type { PaletteEntry } from "./entries.ts"; |
| @@ -53,7 +54,7 @@ export function connectionsScreen(f: Session, ctx: Ctx): Screen { | ||
| 53 | 54 | all.map((o) => { |
| 54 | 55 | const k = n.get(o.id)?.count ?? 0; |
| 55 | 56 | return { |
| 56 | title: `${host(o.webUrl)} · ${o.login}`, | |
| 57 | title: `${icon(originMark(o), ctx.icons)} ${host(o.webUrl)} · ${o.login}`, | |
| 57 | 58 | ...(o.lastError !== "" || writesPaused(f.app, o.id) !== undefined ? { tone: "danger" as const } : {}), |
| 58 | 59 | secondary: `${o.software === "forge" ? "another forge · " : ""}${o.readOnly ? "read-only · " : ""}${k} repositor${k === 1 ? "y" : "ies"} · ${day(o.lastSyncAt)}`, |
| 59 | 60 | 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 = | ||
| 55 | 55 | | "origin" |
| 56 | 56 | | "github" |
| 57 | 57 | | "forgejo" |
| 58 | | "gitea" | |
| 59 | | "anvil" | |
| 58 | 60 | | "gitlab" |
| 59 | 61 | // marks |
| 60 | 62 | | "warning" |
| @@ -110,6 +112,8 @@ const ICONS: Readonly<Record<IconName, Pair>> = { | ||
| 110 | 112 | origin: { plain: G.chevron, nerd: "\u{f484}" }, // nf-oct-globe |
| 111 | 113 | github: { plain: G.diamond, nerd: "\u{f408}" }, // nf-oct-mark_github |
| 112 | 114 | 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 | |
| 113 | 117 | gitlab: { plain: G.diamond, nerd: "\u{f296}" }, // nf-fa-gitlab |
| 114 | 118 | warning: { plain: G.up, nerd: "\u{f421}" }, // nf-oct-alert |
| 115 | 119 | check: { plain: G.check, nerd: "\u{f42e}" }, // nf-oct-check |
| @@ -132,6 +136,14 @@ export function icon(name: IconName, set: IconSet): string { | ||
| 132 | 136 | return set === "nerd" ? pair.nerd : pair.plain; |
| 133 | 137 | } |
| 134 | 138 | |
| 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 | ||
| 135 | 147 | /** Every name in the table — what a settings preview iterates. */ |
| 136 | 148 | export function iconNames(): IconName[] { |
| 137 | 149 | return Object.keys(ICONS) as IconName[]; |
src/web/pages/browse.ts +1 −1
| @@ -300,7 +300,7 @@ function summaryRow( | ||
| 300 | 300 | |
| 301 | 301 | /** The mark an imported author wears on this scope. */ |
| 302 | 302 | 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"); | |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | /** A `ListQuery` as the source's own query shape. */ |
src/web/pages/commits.ts +6 −1
| @@ -10,6 +10,7 @@ | ||
| 10 | 10 | * list can do neither, so the live browse pages by cursor and says so. |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | import { originIcon } from "./origins.ts"; | |
| 13 | 14 | import { immutableWhenAddressed } from "../../http/addressed.ts"; |
| 14 | 15 | import { checkOfCommit, verdictsOfCommits } from "../../actions/runs.ts"; |
| 15 | 16 | import type { CommitCheck } from "../../checks/commit_check.ts"; |
| @@ -165,7 +166,11 @@ export function renderCommit( | ||
| 165 | 166 | ${commit.login |
| 166 | 167 | ? originTag( |
| 167 | 168 | 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", | |
| 169 | 174 | ) |
| 170 | 175 | : avatar(commit.author)} |
| 171 | 176 | <span>${commit.author} committed ${time(commit.date)}</span> |
src/web/pages/search.ts +6 −7
| @@ -10,6 +10,7 @@ | ||
| 10 | 10 | * that was never meant to be confirmed. |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | import { originIcon } from "./origins.ts"; | |
| 13 | 14 | import { ARCHIVE_DETAIL, RESTORE_DETAIL, archiveTitle, restoreTitle } from "../../core/archive-words.ts"; |
| 14 | 15 | import { cappedQuery, echoed, queryTooLong, QUERY_TRIMMED_NOTE } from "../../core/query_limit.ts"; |
| 15 | 16 | import { returnTo, withReturn } from "../return_to.ts"; |
| @@ -166,13 +167,11 @@ function repoHitRow(ctx: Ctx, apps: Apps, hit: RepoHit): Html { | ||
| 166 | 167 | href: browseBase(hit.originId, hit.fullName), |
| 167 | 168 | nav: true, |
| 168 | 169 | 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", | |
| 176 | 175 | ), |
| 177 | 176 | title: hit.fullName, |
| 178 | 177 | titleAttr: hit.fullName, |
src/web/pages/thread.ts +2 −1
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | * is what makes a long thread skimmable. |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | import { originIcon } from "./origins.ts"; | |
| 11 | 12 | import { TELL_LIMIT_WORDS, TELL_TEXT_MAX } from "../../actions/tell_from.ts"; |
| 12 | 13 | import { returnTo, withReturn } from "../return_to.ts"; |
| 13 | 14 | import { mayView } from "../../core/sealed.ts"; |
| @@ -111,7 +112,7 @@ export function originError(error: string): string | undefined { | ||
| 111 | 112 | |
| 112 | 113 | /** The origin's mark, when this repo has one. */ |
| 113 | 114 | export function originGlyph(repo: Repo): Glyph { |
| 114 | return repo.origin?.kind ?? "globe"; | |
| 115 | return repo.origin ? originIcon(repo.origin) : "globe"; | |
| 115 | 116 | } |
| 116 | 117 | |
| 117 | 118 | /** 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"; | ||
| 43 | 43 | import { html, when, type Html } from "./html.ts"; |
| 44 | 44 | import { repoSteps } from "./repo_steps.ts"; |
| 45 | 45 | import { icon, type IconName } from "./icons.ts"; |
| 46 | import { originIcon } from "./pages/origins.ts"; | |
| 46 | 47 | import type { PaletteItem } from "./layout.ts"; |
| 47 | 48 | import { time, timeAgo } from "./ui.ts"; |
| 48 | 49 | |
| @@ -354,7 +355,7 @@ function placesFor(ctx: Ctx, scope: RepoScope): Place[] { | ||
| 354 | 355 | label: hostOf(scope.origin.webUrl), |
| 355 | 356 | state: "reading", |
| 356 | 357 | glyph: "●", |
| 357 | icon: scope.origin.kind, | |
| 358 | icon: originIcon(scope.origin), | |
| 358 | 359 | ...(scope.originUrl === "" |
| 359 | 360 | ? {} |
| 360 | 361 | : { href: scope.originUrl, external: true }), |
test/origins-page-shape.test.ts +51 −1
| @@ -4,7 +4,10 @@ import { mkdtempSync, rmSync } from "node:fs"; | ||
| 4 | 4 | import { tmpdir } from "node:os"; |
| 5 | 5 | import { join } from "node:path"; |
| 6 | 6 | 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"; | |
| 8 | 11 | import { createOrigin, linkRepoToOrigin } from "../src/core/origins.ts"; |
| 9 | 12 | import { createUser, getUserByName } from "../src/core/users.ts"; |
| 10 | 13 | 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 | ||
| 183 | 186 | expect(rule).toContain("min-width: 0"); |
| 184 | 187 | expect(rule).toContain("overflow-wrap: anywhere"); |
| 185 | 188 | }); |
| 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 { | ||
| 29 | 29 | icon, |
| 30 | 30 | iconNames, |
| 31 | 31 | looksLikeImage, |
| 32 | originMark, | |
| 32 | 33 | type IconName, |
| 33 | 34 | } from "../src/tui/ui/icons.ts"; |
| 34 | 35 | import { clusterWidth, clusters, displayWidth } from "../src/tui/term/width.ts"; |
| @@ -376,3 +377,10 @@ describe("the icon set a session actually draws", () => { | ||
| 376 | 377 | } |
| 377 | 378 | }); |
| 378 | 379 | }); |
| 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 () => { | ||
| 198 | 198 | origin: { |
| 199 | 199 | originId: "o1", |
| 200 | 200 | kind: "github", |
| 201 | software: "", | |
| 201 | 202 | fullName: "up/lib", |
| 202 | 203 | htmlUrl: "https://example.test/up/lib", |
| 203 | 204 | lastFetchAt: null, |
new above
offline