Public: anyone can read this; the crew can change it.
/migrate's first field is the repository URL, and with no account connected the page is that field and Connect GitHub (from branch scout/6406-…) #17339
Merged 36h 5m ago, live in production
scout/forge:scout/6437-migrate-s-first-field-is-the-repository → main 0 commits fork 2 threads · 2 unresolved
7 files
changed +210
−17
docs/ORIGINS.md +2
| @@ -830,6 +830,8 @@ the mirror pull's URL and run one at a time per repository, so they never | ||
| 830 | 830 | make two copies of one pull. `test/mirror-pulls.test.ts`, against the fake |
| 831 | 831 | Forgejo. |
| 832 | 832 | |
| 833 | **Migrate on the web.** `/migrate` leads with a pasted-URL field; how to use it is `docs/features/migrate.md`. | |
| 834 | ||
| 833 | 835 | **Migrate from the terminal.** Press `M` on the dashboard (or pick "Migrate a |
| 834 | 836 | repository" in the palette, `ctrl+k`). The list is your connected origins' |
| 835 | 837 | repositories, private ones marked; `/` filters it and `u` pastes a URL instead. |
docs/design/areas/forms.md +1
| @@ -4,6 +4,7 @@ A form's fields and its buttons sit in two rows, one for what you fill in and on | ||
| 4 | 4 | |
| 5 | 5 | - `.field-row` — a row of `.field`s side by side that wraps on a narrow screen, each at least 160px wide and aligned to the bottom so a labelled input and the button beside it share a baseline. Styled in `style/components.ts`; written by `createForm` in `pages/branches.ts` (the new-branch form), the graph filter in `pages/fleet-graph.ts` and the freeze form in `pages/frozen.ts`. The new-pull form stacks Base and Compare as plain `.field`s, one column at any width. |
| 6 | 6 | - `.form-actions` — the row of a form's buttons under its fields: 16px above, 8px apart, wrapping. Styled in `style/components.ts`, and in `style/content.ts` for a thread's close reason and "close into" input and for `.comment-form` on a narrow screen; written by nearly every form in `src/web/pages/` (`account.ts`, `settings.ts`, `crew.ts`, `edit.ts`, `issues.ts`, `pulls.ts`, `oauth.ts`, `teams.ts`, `chain.ts`, `everyday.ts`) and by the review comment form in `diff-view.ts`; `client.ts` finds its `.muted` note to report a save. |
| 7 | - `.input-lg` — a text input that is the page's one first act: 48px tall, 16px type. Styled in `style/components.ts`; written by the repository URL field on `/migrate` (`pages/migrate.ts`), which is the first input in `<main>` and joins the migrate form by its `form` attribute. | |
| 7 | 8 | - `.form-actions[data-stick]` — on a screen up to 640px the row sticks to the bottom edge (opaque `--bg`, 8px padding) so a long form's submit stays in view with the keyboard up; `/forges/new` sets it (#13005). |
| 8 | 9 | |
| 9 | 10 | - The gate break-glass (#7790) on the pull's Files step is a plain `field()` with a hint and a `.form-actions` row holding one `btn` in the `danger` variant; no new class. It sits under the disabled primary Merge button, so the page keeps one accent. |
docs/features/migrate.md added +14
| @@ -0,0 +1,14 @@ | ||
| 1 | --- | |
| 2 | topic: Backups and moving | |
| 3 | row: Migrate: paste a URL and press Enter | |
| 4 | --- | |
| 5 | # Migrate: paste a URL and press Enter | |
| 6 | ||
| 7 | For anyone bringing a repository onto the forge. | |
| 8 | ||
| 9 | ## Use it | |
| 10 | ||
| 11 | - Web: open `/migrate`. The first field is "Paste a repository URL (GitHub, GitLab, any git URL)". Paste, press Enter, and it migrates. The line under the field names the host and `owner/name` the URL points at (`github.com — owner/name`) once it matches. | |
| 12 | - The clone is anonymous, so a private repository needs its origin connected: connect GitHub, then pick it from the list below the field. | |
| 13 | - With no account connected the page is that field and **Connect GitHub**, nothing else. With one connected, your repositories are listed below the field. | |
| 14 | - Terminal: press `M` on the dashboard, then `u` to paste a URL instead of picking from the list. |
src/web/pages/migrate.ts +54 −16
| @@ -300,7 +300,7 @@ function accounts(ctx: Ctx, origins: readonly OriginChoices[]): Html { | ||
| 300 | 300 | there works until then. |
| 301 | 301 | </p>`; |
| 302 | 302 | return html`<section class="mb" id="migrate-accounts-section"> |
| 303 | <h2 class="mb">Your accounts</h2> | |
| 303 | ${origins.length === 0 ? null : html`<h2 class="mb">Your accounts</h2>`} | |
| 304 | 304 | ${origins.length === 0 |
| 305 | 305 | ? null |
| 306 | 306 | : html`<ul class="list" id="migrate-accounts"> |
| @@ -335,8 +335,9 @@ function picker( | ||
| 335 | 335 | values: MigrateValues, |
| 336 | 336 | withCrew: boolean, |
| 337 | 337 | branches: BranchChoices | undefined, |
| 338 | ): Html { | |
| 338 | ): Html | null { | |
| 339 | 339 | const listed = origins.filter((o) => o.repos.length > 0); |
| 340 | if (origins.length === 0) return null; | |
| 340 | 341 | if (listed.length === 0) |
| 341 | 342 | return html`<p class="muted small mb"> |
| 342 | 343 | ${icon("globe")} Connect an account above — or another forge under |
| @@ -418,6 +419,44 @@ function parsePick(value: string): MigrateSource | undefined { | ||
| 418 | 419 | return { originId: value.slice(0, slash), fullName: value.slice(slash + 1) }; |
| 419 | 420 | } |
| 420 | 421 | |
| 422 | /** The one pattern for a pasted URL's host and owner/name; the page script embeds its source. */ | |
| 423 | const URL_TARGET = | |
| 424 | /^[A-Za-z][A-Za-z0-9+.-]*:\/\/(?:[^@/]*@)?([^/:?#]+)(?::[0-9]+)?\/([^/?#]+)\/([^/?#]+?)(?:\.git)?\/?(?:[?#].*)?$/; | |
| 425 | ||
| 426 | /** Host and `owner/name` a pasted URL points at; undefined when it names neither. */ | |
| 427 | export function urlTarget(raw: string): { host: string; repo: string } | undefined { | |
| 428 | const m = URL_TARGET.exec(raw.trim()); | |
| 429 | return m ? { host: m[1]!, repo: `${m[2]}/${m[3]}` } : undefined; | |
| 430 | } | |
| 431 | ||
| 432 | const URL_NOTE = "Cloned anonymously, so the repository must be public."; | |
| 433 | ||
| 434 | /** | |
| 435 | * The first field on the page: a pasted URL, large, in the migrate form by | |
| 436 | * its `form` attribute (the accounts card sits between and forms do not nest). | |
| 437 | */ | |
| 438 | function urlField(value: string): Html { | |
| 439 | const target = urlTarget(value); | |
| 440 | return html`<div class="field"> | |
| 441 | <label for="f-url">Paste a repository URL (GitHub, GitLab, any git URL)</label> | |
| 442 | <input | |
| 443 | class="input input-lg mono" | |
| 444 | type="text" | |
| 445 | id="f-url" | |
| 446 | name="url" | |
| 447 | form="migrate-form" | |
| 448 | value="${value}" | |
| 449 | placeholder="https://github.com/owner/name" | |
| 450 | autocomplete="off" | |
| 451 | spellcheck="false" | |
| 452 | autofocus | |
| 453 | aria-describedby="f-url-note f-url-says" | |
| 454 | /> | |
| 455 | <span class="hint" id="f-url-note">${URL_NOTE}</span> | |
Principle 1 and 8, and accessibility: |
||
| 456 | <span class="hint mono" id="f-url-says">${target ? `${target.host} — ${target.repo}` : ""}</span> | |
| 457 | </div>`; | |
| 458 | } | |
| 459 | ||
| 421 | 460 | function migrateForm( |
| 422 | 461 | ctx: Ctx, |
| 423 | 462 | values: MigrateValues, |
| @@ -456,6 +495,7 @@ function migrateForm( | ||
| 456 | 495 | : html`<p class="muted small mb" id="prefill-refused"> |
| 457 | 496 | ${icon("globe")} ${refused.join(" ")} |
| 458 | 497 | </p>`} |
| 498 | ${urlField(values.url)} | |
| 459 | 499 | ${accounts(ctx, origins)} |
| 460 | 500 | ${origins.length === 0 |
| 461 | 501 | ? null |
| @@ -463,21 +503,11 @@ function migrateForm( | ||
| 463 | 503 | ${btn("See what is left to bring over", { href: "/migrate/inventory", variant: "outline", icon: "download" })} |
| 464 | 504 | </p>`} |
| 465 | 505 | <form method="get" action="/migrate" id="migrate-search"></form> |
| 466 | <form method="post" action="/migrate"> | |
| 467 | <h2 class="mb">Source</h2> | |
| 506 | <form method="post" action="/migrate" id="migrate-form"> | |
| 507 | <!-- Enter in the URL field presses the form's first submit button; this plain one comes first so it never presses a picker row. Do not delete. --> | |
| 508 | <button type="submit" hidden tabindex="-1" aria-hidden="true"></button> | |
| 509 | ${origins.length === 0 ? null : html`<h2 class="mb">Source</h2>`} | |
| 468 | 510 | ${picker(origins, values, crew.length > 0, branches)} |
| 469 | ${formField({ | |
| 470 | label: origins.every((o) => o.repos.length === 0) | |
| 471 | ? "Repository URL" | |
| 472 | : "Or a URL", | |
| 473 | name: "url", | |
| 474 | value: values.url, | |
| 475 | placeholder: "https://github.com/owner/name", | |
| 476 | autocomplete: "off", | |
| 477 | mono: true, | |
| 478 | autofocus: origins.every((o) => o.repos.length === 0), | |
| 479 | hint: "Any public repository over https, http or git. It is cloned anonymously.", | |
| 480 | })} | |
| 481 | 511 | <h2 class="mb mt">Destination</h2> |
| 482 | 512 | ${selectField({ |
| 483 | 513 | label: "Owner", |
| @@ -622,6 +652,14 @@ export const migrateJs = /* js */ ` | ||
| 622 | 652 | name.value = url ? fromUrl(url.value) : ''; |
| 623 | 653 | } |
| 624 | 654 | if (url) url.addEventListener('input', follow); |
| 655 | var says = document.getElementById('f-url-says'); | |
| 656 | if (url && says) { | |
| 657 | var idle = says.textContent; | |
| 658 | url.addEventListener('input', function () { | |
| 659 | var m = new RegExp(${JSON.stringify(URL_TARGET.source)}).exec(url.value.trim()); | |
| 660 | says.textContent = m ? m[1] + ' — ' + m[2] + '/' + m[3] : idle; | |
| 661 | }); | |
| 662 | } | |
| 625 | 663 | })(); |
| 626 | 664 | `; |
| 627 | 665 |
src/web/style/components.ts +1
| @@ -87,6 +87,7 @@ export const components = /* css */ ` | ||
| 87 | 87 | box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 14%, transparent); |
| 88 | 88 | } |
| 89 | 89 | .input[readonly] { background: var(--muted); color: var(--muted-fg); } |
| 90 | .input-lg { min-height: 48px; padding: 12px 16px; font-size: 16px; } | |
| 90 | 91 | .input[data-size="sm"] { min-height: 28px; padding: 4px 8px; font-size: 13px; } |
| 91 | 92 | textarea.input { |
| 92 | 93 | resize: vertical; min-height: 88px; line-height: 1.55; font-family: inherit; |
test/migrate-language.test.ts +1 −1
| @@ -65,7 +65,7 @@ const noCard = (page: string): void => { | ||
| 65 | 65 | test("/migrate with no account: headings, the URL field and Migrate, no card", async () => { |
| 66 | 66 | const page = await get("/migrate", other); |
| 67 | 67 | noCard(page); |
| 68 | expect(page).toContain("Your accounts"); | |
| 68 | expect(page).not.toContain("Your accounts"); | |
| 69 | 69 | expect(page).toContain("Migrate"); |
| 70 | 70 | expect(page).toContain('name="url"'); |
| 71 | 71 | }); |
test/migrate-layout.test.ts added +137
| @@ -0,0 +1,137 @@ | ||
| 1 | /** | |
| 2 | * /migrate leads with the repository URL field: first input in <main>, with | |
| 3 | * or without a connected origin, and no empty picker when none is connected. | |
| 4 | */ | |
| 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 6 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 7 | import { tmpdir } from "node:os"; | |
| 8 | import { join } from "node:path"; | |
| 9 | import { createApp, type App } from "../src/app.ts"; | |
| 10 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 11 | import { migrateJs, urlTarget } from "../src/web/pages/migrate.ts"; | |
| 12 | import { forgetProviders } from "../src/origins/providers/index.ts"; | |
| 13 | import { newFakeState, serveFakeForge } from "./fake-origin.ts"; | |
| 14 | import { adminCookie } from "./helpers/admin.ts"; | |
| 15 | import { quietLogs } from "./helpers/globals.ts"; | |
| 16 | ||
| 17 | quietLogs(); | |
| 18 | ||
| 19 | let dataDir: string; | |
| 20 | let app: App; | |
| 21 | let servers: Servers; | |
| 22 | let cookie: string; | |
| 23 | ||
| 24 | beforeAll(async () => { | |
| 25 | dataDir = await mkdtemp(join(tmpdir(), "forge-migrate-layout-")); | |
| 26 | app = createApp({ dataDir, port: 0, host: "forge.test" }); | |
| 27 | servers = await serve(app); | |
| 28 | cookie = await adminCookie(app, { username: "olive", email: "[email protected]", password: "a-good-passphrase" }); | |
| 29 | }); | |
| 30 | ||
| 31 | afterAll(async () => { | |
| 32 | await servers.stop(); | |
| 33 | await rm(dataDir, { recursive: true, force: true }); | |
| 34 | }); | |
| 35 | ||
| 36 | const get = async (path: string) => | |
| 37 | (await fetch(`${servers.url}${path}`, { headers: { cookie }, redirect: "manual" })).text(); | |
| 38 | ||
| 39 | const firstInput = (html: string): string => { | |
| 40 | const main = html.slice(html.indexOf("<main")); | |
| 41 | return /<input\b[^>]*>/.exec(main)?.[0] ?? ""; | |
| 42 | }; | |
| 43 | ||
| 44 | test("with no account connected the URL field leads, and no picker or empty accounts card is drawn", async () => { | |
| 45 | const html = await get("/migrate"); | |
| 46 | const first = firstInput(html); | |
| 47 | expect(first).toContain('name="url"'); | |
| 48 | expect(html).toContain("Paste a repository URL (GitHub, GitLab, any git URL)"); | |
| 49 | expect(html).not.toMatch(/<ul[^>]*data-pick-rows/); | |
| 50 | expect(html).not.toContain("Your accounts"); | |
| 51 | expect(html).not.toContain("migrate-picker"); | |
| 52 | }); | |
| 53 | ||
| 54 | test("the line under the field names host and owner/name after a refused submit", async () => { | |
| 55 | const html = await get("/migrate?url=" + encodeURIComponent("https://gitlab.com/acme/widgets.git")); | |
| 56 | expect(html).toMatch(/id="f-url-says"[^>]*>\s*gitlab\.com — acme\/widgets/); | |
| 57 | expect(html).toContain("f-url-says"); | |
| 58 | }); | |
| 59 | ||
| 60 | test("with an origin connected the URL field still leads", async () => { | |
| 61 | const { connectOrigin } = await import("../src/actions/origins.ts"); | |
| 62 | const { getUserByName } = await import("../src/core/users.ts"); | |
| 63 | const user = getUserByName(app.db, "olive")!; | |
| 64 | const state = newFakeState("github", "octo", "layout-secret"); | |
| 65 | state.repos.push({ | |
| 66 | id: 501, | |
| 67 | fullName: "octo/gadgets", | |
| 68 | description: "small machines", | |
| 69 | cloneUrl: "http://127.0.0.1/octo/gadgets.git", | |
| 70 | htmlUrl: "https://github.com/octo/gadgets", | |
| 71 | defaultBranch: "main", | |
| 72 | private: false, | |
| 73 | sizeKb: 10, | |
| 74 | }); | |
| 75 | const fake = serveFakeForge(state); | |
| 76 | forgetProviders(dataDir); | |
| 77 | try { | |
| 78 | const made = await connectOrigin(app, user, { host: fake.url, kind: "github", token: "layout-secret" }); | |
| 79 | if (!made.ok) throw new Error(String(made.error)); | |
| 80 | const html = await get("/migrate"); | |
| 81 | expect(html).toMatch(/<ul[^>]*data-pick-rows/); | |
| 82 | expect(firstInput(html)).toContain('name="url"'); | |
| 83 | } finally { | |
| 84 | fake.stop(); | |
| 85 | } | |
| 86 | }); | |
| 87 | ||
| 88 | test("urlTarget reads host and owner/name, and nothing from a bare word", () => { | |
| 89 | expect(urlTarget("https://github.com/o/n")).toEqual({ host: "github.com", repo: "o/n" }); | |
| 90 | expect(urlTarget("https://[email protected]:8443/o/n.git/")).toEqual({ host: "host.example", repo: "o/n" }); | |
| 91 | expect(urlTarget("nonsense")).toBeUndefined(); | |
| 92 | }); | |
| 93 | ||
| 94 | test("the typing-time line runs the server's pattern: the script updates the line as the URL changes", async () => { | |
| 95 | const script = migrateJs; | |
| 96 | expect(script).toContain("f-url-says"); | |
| 97 | const els: Record<string, { value: string; textContent: string; listeners: Record<string, () => void>; addEventListener(t: string, f: () => void): void }> = {}; | |
| 98 | const el = (value: string, textContent: string) => ({ | |
| 99 | value, | |
| 100 | textContent, | |
| 101 | listeners: {} as Record<string, () => void>, | |
| 102 | addEventListener(t: string, f: () => void) { | |
| 103 | this.listeners[t] = f; | |
| 104 | }, | |
| 105 | }); | |
| 106 | els["f-name"] = el("", ""); | |
| 107 | els["f-url"] = el("", ""); | |
| 108 | els["f-url-says"] = el("", "idle"); | |
| 109 | new Function("document", script)({ | |
| 110 | addEventListener: (_t: string, f: () => void) => f(), | |
| 111 | getElementById: (id: string) => els[id] ?? null, | |
| 112 | querySelectorAll: () => [], | |
| 113 | }); | |
| 114 | const url = els["f-url"]!; | |
| 115 | const says = els["f-url-says"]!; | |
| 116 | for (const raw of ["https://github.com/o/n", "https://[email protected]:8443/o/n.git/", "nonsense"]) { | |
| 117 | url.value = raw; | |
| 118 | url.listeners.input!(); | |
| 119 | const t = urlTarget(raw); | |
| 120 | expect(says.textContent).toBe(t ? `${t.host} — ${t.repo}` : "idle"); | |
| 121 | } | |
| 122 | }); | |
| 123 | ||
| 124 | test("Enter in the URL field cannot press a picker row: the form's first submit button is the plain one", async () => { | |
| 125 | const html = await get("/migrate"); | |
| 126 | const form = html.slice(html.indexOf('id="migrate-form"')); | |
| 127 | const first = /<button\b[^>]*type="submit"[^>]*>/.exec(form)?.[0] ?? ""; | |
| 128 | expect(first).toContain("hidden"); | |
| 129 | expect(first).not.toContain('name="pick"'); | |
| 130 | }); | |
| 131 | ||
| 132 | test("the URL field says the clone is anonymous, and the line under it is empty until a URL matches, with no live region", async () => { | |
| 133 | const html = await get("/migrate"); | |
| 134 | expect(html).toContain("Cloned anonymously, so the repository must be public."); | |
| 135 | expect(html).toMatch(/id="f-url-says"[^>]*><\/span>/); | |
| 136 | expect(html).not.toMatch(/id="f-url-says"[^>]*aria-live/); | |
| 137 | }); |
new above
offline
The label is now the only place that says what is accepted, and the earlier note that the repository is cloned anonymously (public only) is gone. Put that sentence back as the hint so a person with a private URL is not surprised by the refusal.