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

opened this

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

  • Merged. scout/6437-migrate-s-first-field-is-the-repository was merged into main as 6e1daf3.

Review

Sign in to review this change.
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
830830 make two copies of one pull. `test/mirror-pulls.test.ts`, against the fake
831831 Forgejo.
832832
833 **Migrate on the web.** `/migrate` leads with a pasted-URL field; how to use it is `docs/features/migrate.md`.
834
833835 **Migrate from the terminal.** Press `M` on the dashboard (or pick "Migrate a
834836 repository" in the palette, `ctrl+k`). The list is your connected origins'
835837 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
44
55 - `.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.
66 - `.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.
78 - `.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).
89
910 - 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 {
300300 there works until then.
301301 </p>`;
302302 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>`}
304304 ${origins.length === 0
305305 ? null
306306 : html`<ul class="list" id="migrate-accounts">
@@ -335,8 +335,9 @@ function picker(
335335 values: MigrateValues,
336336 withCrew: boolean,
337337 branches: BranchChoices | undefined,
338 ): Html {
338 ): Html | null {
339339 const listed = origins.filter((o) => o.repos.length > 0);
340 if (origins.length === 0) return null;
340341 if (listed.length === 0)
341342 return html`<p class="muted small mb">
342343 ${icon("globe")} Connect an account above — or another forge under
@@ -418,6 +419,44 @@ function parsePick(value: string): MigrateSource | undefined {
418419 return { originId: value.slice(0, slash), fullName: value.slice(slash + 1) };
419420 }
420421
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>

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.

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>
outdated

Principle 1 and 8, and accessibility: aria-live="polite" on a line rewritten per keystroke makes a screen reader read a fragment on every character. Remove it (keep aria-describedby) or update on change. The idle text repeats the label; leave it empty until a URL matches, or show an example.

456 <span class="hint mono" id="f-url-says">${target ? `${target.host} — ${target.repo}` : ""}</span>
457 </div>`;
458 }
459
421460 function migrateForm(
422461 ctx: Ctx,
423462 values: MigrateValues,
@@ -456,6 +495,7 @@ function migrateForm(
456495 : html`<p class="muted small mb" id="prefill-refused">
457496 ${icon("globe")} ${refused.join(" ")}
458497 </p>`}
498 ${urlField(values.url)}
459499 ${accounts(ctx, origins)}
460500 ${origins.length === 0
461501 ? null
@@ -463,21 +503,11 @@ function migrateForm(
463503 ${btn("See what is left to bring over", { href: "/migrate/inventory", variant: "outline", icon: "download" })}
464504 </p>`}
465505 <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>`}
468510 ${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 })}
481511 <h2 class="mb mt">Destination</h2>
482512 ${selectField({
483513 label: "Owner",
@@ -622,6 +652,14 @@ export const migrateJs = /* js */ `
622652 name.value = url ? fromUrl(url.value) : '';
623653 }
624654 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 }
625663 })();
626664 `;
627665
src/web/style/components.ts +1
@@ -87,6 +87,7 @@ export const components = /* css */ `
8787 box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 14%, transparent);
8888 }
8989 .input[readonly] { background: var(--muted); color: var(--muted-fg); }
90 .input-lg { min-height: 48px; padding: 12px 16px; font-size: 16px; }
9091 .input[data-size="sm"] { min-height: 28px; padding: 4px 8px; font-size: 13px; }
9192 textarea.input {
9293 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 => {
6565 test("/migrate with no account: headings, the URL field and Migrate, no card", async () => {
6666 const page = await get("/migrate", other);
6767 noCard(page);
68 expect(page).toContain("Your accounts");
68 expect(page).not.toContain("Your accounts");
6969 expect(page).toContain("Migrate");
7070 expect(page).toContain('name="url"');
7171 });
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 });

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

Keyboard shortcuts

Docs