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

/migrate opens on one paste field, with each connected account behind a searchable 8-row picker, and a stale search never overwrites a newer one #6384

Closed opened this
Closed without merging

scout/forge:scout/6228-migrate-opens-on-one-paste-field-with-ea → main 3 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
8 files changed +801 −165
README.md +17
@@ -354,6 +354,23 @@ rights on GitHub: without them the migration still succeeds and says the
354354 repository was not archived, so you can do it there yourself. Only repositories
355355 read through a connected origin have an original to change; a pasted URL does not.
356356
357 **Migrate on the web.** `/migrate` opens on one large field, "Paste a repository
358 URL"; the line under it names the host and repository as you type, and says
359 size and visibility when the URL is one of your accounts' repositories. Enter
360 migrates. Under it, "Your accounts" is one row per connected account ("GitHub,
361 62 repositories") that opens to a search box and eight rows, newest push first;
362 typing swaps the rows for the server's answer to the same query (no script:
363 Enter does it), each row has a one-click Migrate, and ticked rows go together
364 with "Migrate selected" (at most 20, each under its own name). No account
365 connected: the field and a Connect GitHub button. A spawned forge runs the same
366 page. No dependency was added. With scripts off, a search is a separate GET, so
367 ticks made before it are dropped: tick after searching. The Name field no longer
368 follows the URL as you type, deliberately: the preview names what it will be
369 called, and blank keeps the source's name.
370
371 The terminal (`M` on the dashboard) is unchanged here: it gets the same sort,
372 preview and multi-pick in its own issue, over the same `migrateRepo`.
373
357374 **Migrate from the terminal.** Press `M` on the dashboard (or pick "Migrate a
358375 repository" in the palette, `ctrl+k`). The list is your connected origins'
359376 repositories, private ones marked; `/` filters it and `u` pastes a URL instead.
docs/design/areas/forms.md +2
@@ -4,3 +4,5 @@ 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`, the freeze form in `pages/frozen.ts` and the new-pull form in `pages/pulls.ts`.
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
8 - `.input[data-size="lg"]` — the one large field a page is for (`field({ size: "lg" })` in `ui.ts`; `/migrate`'s URL). `searchInput` in `ui.ts` is the search box of a list that filters as you type: `data-search` names the container a script swaps for the server's answer to the same query.
src/web/html.ts +20
@@ -50,6 +50,26 @@ export function html(strings: TemplateStringsArray, ...values: Value[]): Html {
5050 return new Html(out);
5151 }
5252
53 const BLOCK = "div|li|ul|ol|p|form|details|summary|h[1-6]|option|select|section|header|footer";
54
55 /**
56 * Markup with its indentation squeezed out, rendered the same: every run of
57 * whitespace holding a newline becomes one space, a space before a tag's
58 * closing `>` goes, and whitespace between block-level tags goes (between
59 * inline ones it is a word space, and stays). For a page of rows whose
60 * template indentation outweighs its content; never for markup holding
61 * `<pre>`, `<textarea>` or `<script>`.
62 */
63 export function tight(markup: Html): Html {
64 return new Html(
65 markup.text
66 .replace(/\s*\n\s*/g, " ")
67 .replace(/ +(\/?>)/g, "$1")
68 .replace(new RegExp(`(<\\/?(?:${BLOCK})\\b[^>]*>) +(?=<)`, "g"), "$1")
69 .replace(new RegExp(` +(?=<\\/?(?:${BLOCK})\\b)`, "g"), ""),
70 );
71 }
72
5373 /** Conditional helper: `when(user, (u) => html`…`)` renders nothing on miss. */
5474 export function when<T>(
5575 value: T | undefined | null | false,
src/web/pages/migrate.ts +398 −164
@@ -46,14 +46,16 @@ import type { Ctx } from "../../http/context.ts";
4646 import type { MirrorJob, MirrorStage } from "../../origins/jobs.ts";
4747 import { notFoundPage, pageHead, signInFirst } from "../chrome.ts";
4848 import { field, readForm } from "../form.ts";
49 import { html, raw, type Html } from "../html.ts";
49 import { html, raw, tight, type Html } from "../html.ts";
5050 import { flashTo, page, redirect } from "../layout.ts";
5151 import {
5252 badge,
5353 btn,
5454 card,
55 disclosure,
5556 icon,
5657 row,
58 searchInput,
5759 selectField,
5860 field as formField,
5961 } from "../ui.ts";
@@ -63,8 +65,10 @@ import { githubConnectable, hostLabel } from "./origins.ts";
6365
6466 interface MigrateValues {
6567 source: string;
66 /** The picker's filter: rows whose name or description holds it. */
68 /** The search: rows whose name or description holds it. */
6769 q: string;
70 /** Rows ticked for "Migrate selected": `<origin id>/<owner>/<name>`. */
71 multi: string[];
6872 url: string;
6973 owner: string;
7074 name: string;
@@ -191,8 +195,11 @@ function branchList(choices: BranchChoices): Html {
191195 </div>`;
192196 }
193197
194 /** Rows drawn per origin; past it, the filter narrows. */
195 export const PICKER_ROWS = 200;
198 /** Rows an account shows before you search; the rest wait behind the filter. */
199 export const PICKER_ROWS = 8;
200
201 /** The most repositories one "Migrate selected" starts. */
202 export const MULTI_MAX = 20;
196203
197204 /**
198205 * A size an origin reported in KiB, in the unit that keeps it short:
@@ -221,115 +228,160 @@ export function matchesFilter(
221228 );
222229 }
223230
231 /** A description as one short line: an origin allows several hundred characters. */
232 const clip = (text: string): string =>
233 text.length > 80 ? `${text.slice(0, 79)}…` : text;
234
235 /** Most recently pushed first; a row with no push time goes last. */
236 export function byRecentPush<T extends Pick<OriginRepoRow, "pushedAt">>(
237 repos: readonly T[],
238 ): T[] {
239 const at = (r: T): number => Date.parse(r.pushedAt ?? "") || 0;
240 return [...repos].sort((a, b) => at(b) - at(a));
241 }
242
243 /** A URL without its scheme's noise, to compare a pasted one with an origin's. */
244 const sameRepoUrl = (a: string, b: string): boolean => {
245 const norm = (u: string): string =>
246 u
247 .trim()
248 .toLowerCase()
249 .replace(/^[a-z+]+:\/\//, "")
250 .replace(/[?#].*$/, "")
251 .replace(/\/+$/, "")
252 .replace(/\.git$/, "");
253 return norm(a) !== "" && norm(a) === norm(b);
254 };
255
256 /** What a pasted URL is, as plain data: the page and the terminal each say it their way. */
257 export type UrlPreview =
258 | { readonly kind: "empty" }
259 | { readonly kind: "invalid" }
260 | {
261 readonly kind: "account";
262 readonly github: boolean;
263 readonly fullName: string;
264 readonly host: string;
265 readonly private: boolean;
266 readonly size: string;
267 }
268 | { readonly kind: "public"; readonly name: string; readonly host: string };
269
224270 /**
225 * The accounts half, outside the migrate form (forms do not nest): each
226 * connected origin with a Disconnect, and Connect GitHub when there is no
227 * GitHub account yet. Both come back here (`then=migrate`).
271 * What the pasted URL is, before Migrate: its host and name, and — when it
272 * is one of your accounts' repositories — its size and visibility. Pure: the
273 * URL and the rows in, data out.
228274 */
229 function accounts(ctx: Ctx, origins: readonly OriginChoices[]): Html {
230 const hasGithub = origins.some((o) => o.kind === "github");
231 const connect = hasGithub
232 ? null
233 : githubConnectable(ctx)
234 ? html`<form method="post" action="/settings/origins/oauth" class="bar">
235 <input type="hidden" name="kind" value="github" />
236 <input type="hidden" name="then" value="migrate" />
237 ${btn("Connect GitHub", { variant: "outline", icon: "github", type: "submit" })}
238 <span class="muted small"
239 >A short code you type at github.com — no token to paste. Your
240 private repositories and their issues come too.</span
241 >
242 </form>`
243 : html`<p class="muted small">
244 ${icon("github")} Connect GitHub needs this forge's GitHub
245 application, set up once under
246 <a href="/settings/origins">Settings → Origins</a>; a token pasted
247 there works until then.
248 </p>`;
249 return card(
250 html`${origins.length === 0
251 ? null
252 : html`<ul class="list" id="migrate-accounts">
253 ${origins.map((origin) =>
254 row({
255 lead: icon(origin.kind === "github" ? "github" : "globe"),
256 title: origin.label,
257 meta: html`${origin.repos.length} repositories`,
258 trail: html`<form
259 method="post"
260 action="/settings/origins/${origin.id}/delete"
261 >
262 <input type="hidden" name="then" value="migrate" />
263 ${btn("Disconnect", { size: "sm", variant: "ghost", type: "submit" })}
264 </form>`,
265 }),
266 )}
267 </ul>`}
268 ${connect}`,
269 {
270 head: html`${icon("globe")}
271 <h2>Your accounts</h2>`,
272 },
273 );
275 export function urlPreview(
276 url: string,
277 origins: readonly Pick<OriginChoices, "kind" | "repos">[],
278 ): UrlPreview {
279 const text = url.trim();
280 if (text === "") return { kind: "empty" };
281 const parsed = URL.parse(text);
282 if (
283 parsed === null ||
284 !["https:", "http:", "git:"].includes(parsed.protocol) ||
285 parsed.pathname.replace(/\/+$/, "") === ""
286 )
287 return { kind: "invalid" };
288 for (const origin of origins) {
289 const hit = origin.repos.find(
290 (r) => sameRepoUrl(r.htmlUrl, text) || sameRepoUrl(r.cloneUrl, text),
291 );
292 if (hit === undefined) continue;
293 return {
294 kind: "account",
295 github: origin.kind === "github",
296 fullName: hit.fullName,
297 host: hostLabel(parsed.href),
298 private: hit.private,
299 size: formatKib(hit.sizeKb),
300 };
301 }
302 const name = parsed.pathname
303 .replace(/\/+$/, "")
304 .replace(/\.git$/i, "")
305 .split("/")
306 .pop()!;
307 return { kind: "public", name, host: parsed.host };
308 }
309
310 /** The preview as the page's line. */
311 function preview(url: string, origins: readonly OriginChoices[]): Html {
312 const p = urlPreview(url, origins);
313 if (p.kind === "empty")
314 return html`Public repositories clone anonymously; private ones come
315 through Your accounts.`;
316 if (p.kind === "invalid")
317 return html`That does not look like a repository URL yet.`;
318 if (p.kind === "account")
319 return html`${icon(p.github ? "github" : "globe")}
320 <strong class="mono">${p.fullName}</strong> on ${p.host}
321 · ${p.private ? "private" : "public"}${p.size === "" ? null : html` · ${p.size}`}`;
322 return html`${icon("globe")} <strong class="mono">${p.name}</strong> on
323 ${p.host} · cloned anonymously, so it must be public`;
324 }
325
326 /** The Connect GitHub button, or why there is not one yet. */
327 function connectGithub(ctx: Ctx): Html {
328 return githubConnectable(ctx)
329 ? html`<form method="post" action="/settings/origins/oauth" class="bar">
330 <input type="hidden" name="kind" value="github" />
331 <input type="hidden" name="then" value="migrate" />
332 ${btn("Connect GitHub", { variant: "outline", icon: "github", type: "submit" })}
333 <span class="muted small"
334 >A short code you type at github.com — no token to paste. Your
335 private repositories and their issues come too.</span
336 >
337 </form>`
338 : html`<p class="muted small">
339 ${icon("github")} Connect GitHub needs this forge's GitHub
340 application, set up once under
341 <a href="/settings/origins">Settings → Origins</a>; a token pasted
342 there works until then.
343 </p>`;
274344 }
275345
276346 /**
277 * One row per repository: name, private mark, size, description, and the
278 * button that migrates it. The buttons are the form's submitters
279 * (`name="pick"`), so one click carries the destination and crew fields
280 * below with it.
347 * One account's rows, newest push first: eight before a search, the rest
348 * behind it. The list is its own container so a script can swap it for the
349 * server's answer to the same query as you type.
281350 */
282 function picker(
283 origins: readonly OriginChoices[],
351 function pickRows(
352 origin: OriginChoices,
284353 values: MigrateValues,
285354 withCrew: boolean,
286 branches: BranchChoices | undefined,
287355 ): Html {
288 const listed = origins.filter((o) => o.repos.length > 0);
289 if (listed.length === 0)
290 return html`<p class="muted small mb">
291 ${icon("globe")} Connect an account above — or another forge under
292 <a href="/settings/origins">Settings → Origins</a> — to pick from your
293 repositories there, private ones included.
294 </p>`;
295 return html`<div class="field" id="migrate-picker">
296 <label for="f-q">Your repositories</label>
297 <input
298 class="input"
299 type="search"
300 id="f-q"
301 name="q"
302 form="migrate-search"
303 value="${values.q}"
304 placeholder="Filter by name or description"
305 autocomplete="off"
306 />
307 ${values.source === ""
308 ? null
309 : html`<input type="hidden" name="source" value="${values.source}" />`}
310 ${listed.map((origin) => {
311 const rows = origin.repos.filter((r) => matchesFilter(r, values.q));
312 const shown = rows.slice(0, PICKER_ROWS);
313 return html`<h4 class="mt small muted">${origin.label}</h4>
314 <ul class="list" data-pick-rows>
356 const q = values.q;
357 const rows = byRecentPush(origin.repos.filter((r) => matchesFilter(r, q)));
358 const shown = rows.slice(0, PICKER_ROWS);
359 return html`<div id="pick-${origin.id}">
360 ${shown.length === 0
361 ? html`<p class="muted small">Nothing here matches.</p>`
362 : html`<ul class="list" data-pick-rows>
315363 ${shown.map((remote) => {
316364 const value = pickValue(origin.id, remote.fullName);
317365 const size = formatKib(remote.sizeKb);
318366 const branches = `/migrate?${new URLSearchParams({
319367 source: value,
320368 branches: "1",
321 ...(values.q === "" ? {} : { q: values.q }),
369 ...(q === "" ? {} : { q }),
322370 })}#migrate-branches`;
323371 return row({
324 data: {
325 q: `${remote.fullName} ${remote.description}`.toLowerCase(),
326 },
327372 current: values.source === value,
328 title: html`<span class="mono">${remote.fullName}</span>
373 title: html`<label class="check"
374 ><input
375 type="checkbox"
376 name="multi"
377 value="${value}"
378 aria-label="Select ${remote.fullName}"
379 ${values.multi.includes(value) ? raw("checked") : null}
380 /></label>
381 <a class="mono" href="${branches}">${remote.fullName}</a>
329382 ${remote.private ? badge("private") : null}`,
330 meta: html`${size === "" ? null : html`${size} · `}${remote.description}`,
331 trail: html`${btn("Branches", { href: branches, size: "sm", variant: "ghost" })}
332 ${btn(withCrew ? "Migrate with the crew" : "Migrate", {
383 meta: html`${size === "" ? null : html`${size} · `}${clip(remote.description)}`,
384 trail: html`${btn(withCrew ? "Migrate with the crew" : "Migrate", {
333385 size: "sm",
334386 variant: "outline",
335387 type: "submit",
@@ -338,21 +390,92 @@ function picker(
338390 })}`,
339391 });
340392 })}
341 </ul>
342 ${rows.length > shown.length
343 ? html`<p class="muted small">
344 ${rows.length - shown.length} more — filter to narrow.
345 </p>`
346 : null}`;
347 })}
348 ${branches === undefined ? null : branchList(branches)}
349 <span class="hint"
350 >Cloned with your account's credential, so private repositories come
351 too — with their issues, comments, labels and open pull requests.</span
352 >
393 </ul>`}
394 ${rows.length > shown.length
395 ? html`<p class="muted small">
396 ${rows.length - shown.length} more — search to narrow.
397 </p>`
398 : null}
353399 </div>`;
354400 }
355401
402 /**
403 * Your accounts, inside the migrate form (its rows' buttons and ticks submit it; the
404 * search and Disconnect belong to the small forms beside it): one row per connected
405 * account that opens to its search and rows, and Connect GitHub when there
406 * is no GitHub account yet. With no account at all it is that one button.
407 */
408 function accounts(
409 ctx: Ctx,
410 origins: readonly OriginChoices[],
411 values: MigrateValues,
412 withCrew: boolean,
413 branches: BranchChoices | undefined,
414 ): Html {
415 if (origins.length === 0) return html``;
416 return html`<h3 class="mt mb">Your accounts</h3>
417 <ul class="list" id="migrate-accounts">
418 ${origins.map((origin) => {
419 const open =
420 values.q !== "" || values.source.startsWith(`${origin.id}/`);
421 return row({
422 lead: icon(origin.kind === "github" ? "github" : "globe"),
423 title: origin.label,
424 meta: html`${origin.repos.length} repositories`,
425 fold: {
426 id: `acct-${origin.id}`,
427 open,
428 body: html`<div class="card-body">
429 ${origin.repos.length === 0
430 ? html`<p class="muted small">
431 Nothing listed for this account.
432 </p>`
433 : html`${searchInput({
434 name: "q",
435 value: values.q,
436 label: `Search ${origin.label}`,
437 placeholder: `Search ${origin.repos.length} repositories`,
438 target: `pick-${origin.id}`,
439 form: "find",
440 })}
441 ${pickRows(origin, values, withCrew)}
442 ${branches !== undefined &&
443 values.source.startsWith(`${origin.id}/`)
444 ? branchList(branches)
445 : null}`}
446 <div class="bar mt">
447 ${origin.repos.length === 0
448 ? null
449 : btn("Migrate selected", {
450 name: "go",
451 value: "multi",
452 variant: "primary",
453 size: "sm",
454 })}
455 ${btn("Disconnect", {
456 size: "sm",
457 variant: "ghost",
458 type: "submit",
459 form: "drop",
460 formaction: `/settings/origins/${origin.id}/delete`,
461 })}
462 </div>
463 </div>`,
464 },
465 });
466 })}
467 </ul>`;
468 }
469
470 /**
471 * The small forms the account rows' controls belong to by `form=`: a form
472 * cannot sit inside the migrate form, so they stand beside it, empty.
473 */
474 function accountForms(): Html {
475 return html`<form id="find" method="get" action="/migrate"></form>
476 <form id="drop" method="post"><input type="hidden" name="then" value="migrate" /></form>`;
477 }
478
356479 /** `<origin id>/<owner>/<name>` — an id never holds a slash, so the first one splits. */
357480 const pickValue = (originId: string, fullName: string): string =>
358481 `${originId}/${fullName}`;
@@ -378,15 +501,16 @@ function migrateForm(
378501 const owners = [user.username, ...writeOrgs.map((o) => o.username)];
379502 const agents = listAllAgents(ctx.app, user);
380503 const crew = agents.ok ? agents.value : [];
504 const picking = values.source !== "" || values.multi.length > 0;
381505
382506 return html`<div class="narrow-wide">
383507 ${pageHead("Migrate a repository", {
384 sub: "A one-time clone of the whole history — every branch, every tag — into a repository that lives here from now on. Nothing is written back to where it came from.",
508 sub: "A one-time clone of every branch and tag. Nothing is written back to where it came from.",
385509 })}
386510 ${ctx.url.searchParams.get("connected") === "1"
387511 ? html`<p class="muted small mb" id="migrate-connected">
388 ${icon("check")} Connected. Pick a repository below — one click
389 migrates it.
512 ${icon("check")} Connected. Open your account below — one click
513 migrates a repository.
390514 </p>`
391515 : null}
392516 ${unmatched.length === 0
@@ -395,25 +519,34 @@ function migrateForm(
395519 ${icon("globe")} Ignored, nothing here matches:
396520 ${unmatched.join(", ")}
397521 </p>`}
398 ${accounts(ctx, origins)}
399 <form method="get" action="/migrate" id="migrate-search"></form>
400 ${card(
401 html`<form method="post" action="/migrate">
402 <h3 class="mb">Source</h3>
403 ${picker(origins, values, crew.length > 0, branches)}
404 ${formField({
405 label: origins.every((o) => o.repos.length === 0)
406 ? "Repository URL"
407 : "Or a URL",
408 name: "url",
409 value: values.url,
410 placeholder: "https://github.com/owner/name",
411 autocomplete: "off",
412 mono: true,
413 autofocus: origins.every((o) => o.repos.length === 0),
414 hint: "Any public repository over https, http or git. It is cloned anonymously.",
415 })}
416 <h3 class="mb mt">Destination</h3>
522 ${error
523 ? html`<p class="error mb" role="alert" id="migrate-error">${error}</p>`
524 : null}
525 <form method="post" action="/migrate" id="migrate-form">
526 ${values.source === ""
527 ? null
528 : html`<input type="hidden" name="source" value="${values.source}" />`}
529 ${formField({
530 label: "Paste a repository URL (GitHub, GitLab, any git URL)",
531 name: "url",
532 value: values.url,
533 placeholder: "https://github.com/owner/name",
534 autocomplete: "off",
535 mono: true,
536 spellcheck: false,
537 size: "lg",
538 autofocus: !picking,
539 })}
540 <p class="muted small" id="migrate-preview" aria-live="polite">
541 ${preview(values.url, origins)}
542 </p>
543 <div class="form-actions">
544 ${btn("Migrate", { variant: "primary" })}
545 </div>
546 <div id="migrate-chosen"></div>
547 ${disclosure(
548 "Destination, crew and what happens afterwards",
549 html`<h3 class="mb mt">Destination</h3>
417550 ${selectField({
418551 label: "Owner",
419552 name: "owner",
@@ -429,7 +562,6 @@ function migrateForm(
429562 value: values.name,
430563 pattern: "[A-Za-z0-9][A-Za-z0-9._-]*",
431564 hint: "Left blank, it keeps the source's name.",
432 ...(error ? { error } : {}),
433565 })}
434566 ${selectField({
435567 label: "Visibility",
@@ -460,7 +592,7 @@ function migrateForm(
460592 : html`${selectField({
461593 label: "Agent",
462594 name: "agent",
463 hint: "Joins the crew, makes the repository an app, and is told to make it run here — adapting it, not rewriting it.",
595 hint: "Makes the repository an app and gets it running here.",
464596 options: [
465597 {
466598 value: "",
@@ -490,11 +622,11 @@ function migrateForm(
490622 >
491623 </label>
492624 </div>`}
493 <h3 class="mb mt">What happens to the GitHub repository</h3>
625 <h3 class="mb mt">What happens to the original</h3>
494626 ${selectField({
495627 label: "Afterwards",
496628 name: "after",
497 hint: "Applies to a repository picked from a connected origin. Archiving needs admin rights there; without them the migration still succeeds and says so.",
629 hint: "For a repository from a connected account. Archiving needs admin rights there.",
498630 options: [
499631 {
500632 value: "leave",
@@ -512,45 +644,84 @@ function migrateForm(
512644 selected: values.after === "mirror",
513645 },
514646 ],
515 })}
516 <div class="form-actions">
517 ${btn("Migrate", { variant: "primary", icon: "download" })}
518 ${btn("Cancel", { href: "/", variant: "ghost" })}
519 </div>
520 </form>`,
521 )}
647 })}`,
648 { extra: "mt" },
649 )}
650 ${accounts(ctx, origins, values, crew.length > 0, branches)}
651 </form>
652 ${origins.length === 0 ? null : accountForms()}
653 ${origins.some((o) => o.kind === "github")
654 ? null
655 : html`<div class="mt" id="migrate-connect">${connectGithub(ctx)}</div>`}
522656 </div>`;
523657 }
524658
525659 /**
526 * The name field follows the picked repository or the pasted URL until
527 * somebody types in it — a preview; the server names it the same way.
660 * The preview under the URL and an account's rows follow what you type by
661 * asking the page itself (`/migrate?url=` and `?o=&q=`) and swapping in the
662 * element that changed. Ticked rows are remembered as hidden fields, so a
663 * search does not forget them.
528664 */
529 const migrateJs = /* js */ `
665 export const migrateJs = new Bun.Transpiler({ minifyWhitespace: true }).transformSync(/* js */ `
530666 (function () {
531 var name = document.getElementById('f-name');
532667 var url = document.getElementById('f-url');
533 var q = document.getElementById('f-q');
534 if (q) q.addEventListener('input', function () {
535 var needle = q.value.trim().toLowerCase();
536 var rows = document.querySelectorAll('[data-pick-rows] [data-q]');
537 for (var i = 0; i < rows.length; i++)
538 rows[i].hidden = needle !== '' && rows[i].getAttribute('data-q').indexOf(needle) < 0;
668 var chosen = document.getElementById('migrate-chosen');
669 var flying = {};
670 function swap(query, ids, after) {
671 var key = ids[0];
672 if (flying[key]) flying[key].abort();
673 var ctl = flying[key] = new AbortController();
674 fetch('/migrate?' + query, { credentials: 'same-origin', headers: { accept: 'text/html' }, signal: ctl.signal })
675 .then(function (r) { return r.ok ? r.text() : ''; })
676 .then(function (text) {
677 if (!text || flying[key] !== ctl) return;
678 var doc = new DOMParser().parseFromString(text, 'text/html');
679 ids.forEach(function (id) {
680 var fresh = doc.getElementById(id), old = document.getElementById(id);
681 if (fresh && old) old.innerHTML = fresh.innerHTML;
682 });
683 if (after) after();
684 }, function () {});
685 }
686 function ticked() {
687 var boxes = document.querySelectorAll('input[type=checkbox][name=multi]');
688 var held = chosen ? chosen.querySelectorAll('input') : [];
689 for (var i = 0; i < boxes.length; i++)
690 for (var j = 0; j < held.length; j++)
691 if (held[j].value === boxes[i].value) boxes[i].checked = true;
692 }
693 document.addEventListener('change', function (e) {
694 var t = e.target;
695 if (!chosen || t.name !== 'multi' || t.type !== 'checkbox') return;
696 var held = chosen.querySelectorAll('input');
697 for (var i = 0; i < held.length; i++) if (held[i].value === t.value) chosen.removeChild(held[i]);
698 if (t.checked) {
699 var h = document.createElement('input');
700 h.type = 'hidden'; h.name = 'multi'; h.value = t.value;
701 chosen.appendChild(h);
702 }
539703 });
540 if (!name) return;
541 var touched = name.value.trim() !== '';
542 name.addEventListener('input', function () { touched = true; });
543 function fromUrl(v) {
544 var path = v.trim().replace(/[?#].*$/, '').replace(/\\/+$/, '');
545 return (path.split('/').pop() || '').replace(/\\.git$/i, '');
704 var timer;
705 document.addEventListener('input', function (e) {
706 var t = e.target;
707 var target = t.getAttribute && t.getAttribute('data-search');
708 if (!target) return;
709 clearTimeout(timer);
710 timer = setTimeout(function () {
711 swap('q=' + encodeURIComponent(t.value.slice(0, 100)), [target], ticked);
712 }, 120);
713 });
714 if (url) {
715 var seen;
716 url.addEventListener('input', function () {
717 clearTimeout(seen);
718 seen = setTimeout(function () {
719 swap('url=' + encodeURIComponent(url.value.slice(0, 500)), ['migrate-preview']);
720 }, 150);
721 });
546722 }
547 function follow() {
548 if (touched) return;
549 name.value = url ? fromUrl(url.value) : '';
550 }
551 if (url) url.addEventListener('input', follow);
552723 })();
553 `;
724 `);
554725
555726 async function show(
556727 ctx: Ctx,
@@ -572,7 +743,7 @@ async function show(
572743 {
573744 ctx,
574745 title: "Migrate",
575 body: migrateForm(ctx, values, origins, branches, error, unmatched),
746 body: tight(migrateForm(ctx, values, origins, branches, error, unmatched)),
576747 scriptJs: migrateJs,
577748 },
578749 status,
@@ -605,8 +776,10 @@ export async function migratePage(ctx: Ctx): Promise<Response> {
605776 source: linked.repo
606777 ? pickValue(linked.repo.originId, linked.repo.fullName)
607778 : (q.get("source") ?? ""),
608 q: (q.get("q") ?? "").slice(0, 100),
609 url: q.get("url") ?? "",
779 // Every account's box shares one form, so the empty ones come too.
780 q: (q.getAll("q").find((v) => v !== "") ?? "").slice(0, 100),
781 multi: [],
782 url: (q.get("url") ?? "").slice(0, 500),
610783 owner: q.get("owner") ?? ctx.auth.user.username,
611784 name: q.get("name") ?? (linked.repo?.fullName.split("/").pop() ?? ""),
612785 visibility: "private",
@@ -625,6 +798,46 @@ export async function migratePage(ctx: Ctx): Promise<Response> {
625798 );
626799 }
627800
801 /** Every ticked row, each under its own name; one job goes to its page, several to the feed. */
802 async function migrateMany(
803 ctx: Ctx,
804 values: MigrateValues,
805 again: (message: string) => Promise<Response>,
806 ): Promise<Response> {
807 const user = ctx.auth.user!;
808 const jobs: string[] = [];
809 for (const value of values.multi.slice(0, MULTI_MAX)) {
810 const source = parsePick(value);
811 if (source === undefined || !("fullName" in source)) continue;
812 const started = await migrateRepo(ctx.app, user, {
813 source,
814 owner: values.owner,
815 name: "",
816 visibility: values.visibility === "public" ? "public" : "private",
817 ...(values.agent === ""
818 ? {}
819 : { crew: { agent: values.agent, autonomous: values.autonomous } }),
820 after: values.after,
821 });
822 if (!started.ok) {
823 if (started.error === "forbidden_owner" || started.error === "unauthorized")
824 return new Response("forbidden", { status: 403 });
825 const said = migrateMessage(started.error, repositoryLimitMessage(ctx.app, user));
826 if (jobs.length === 0) return again(`${source.fullName}: ${said}`);
827 return flashTo(ctx, "/", {
828 tone: "attn",
829 message: `Started ${jobs.length}; ${source.fullName} stopped the rest: ${said}`,
830 });
831 }
832 jobs.push(started.value.job.id);
833 }
834 if (jobs.length === 1) return redirect(`/migrate/jobs/${jobs[0]}`);
835 if (jobs.length === 0) return again("Tick the repositories you want first.");
836 return flashTo(ctx, "/", {
837 message: `Started ${jobs.length} migrations — each repository appears as it lands.`,
838 });
839 }
840
628841 // POST /migrate
629842 export async function migrateSubmit(ctx: Ctx): Promise<Response> {
630843 if (!ctx.auth.user) return signInFirst(ctx);
@@ -634,6 +847,13 @@ export async function migrateSubmit(ctx: Ctx): Promise<Response> {
634847 // A row's button names its repository; it wins over a prefilled pick.
635848 source: field(form, "pick") || field(form, "source"),
636849 q: "",
850 multi: [
851 ...new Set(
852 form
853 .getAll("multi")
854 .filter((v): v is string => typeof v === "string" && v.length <= 400),
855 ),
856 ],
637857 url: field(form, "url").trim(),
638858 owner: field(form, "owner"),
639859 name: field(form, "name").trim(),
@@ -653,6 +873,20 @@ export async function migrateSubmit(ctx: Ctx): Promise<Response> {
653873 const again = async (message: string): Promise<Response> =>
654874 show(ctx, values, await originChoices(ctx), message, 422);
655875
876 const wantsMulti =
877 field(form, "pick") === "" &&
878 values.multi.length > 0 &&
879 (field(form, "go") === "multi" || (values.source === "" && values.url === ""));
880 if (field(form, "go") === "multi" && values.multi.length === 0)
881 return again("Tick the repositories you want first.");
882 if (wantsMulti) {
883 if (values.url !== "")
884 return again("Tick repositories or paste a URL, not both — clear one of them.");
885 if (ctx.auth.scope === undefined || !scopeAllows(ctx.auth.scope, "admin"))
886 return new Response("forbidden", { status: 403 });
887 return migrateMany(ctx, values, again);
888 }
889
656890 const picked = values.source === "" ? undefined : parsePick(values.source);
657891 if (picked !== undefined && values.url !== "")
658892 return again(
src/web/style/components.ts +6
@@ -90,6 +90,7 @@ export const components = /* css */ `
9090 box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 14%, transparent);
9191 }
9292 .input[readonly] { background: var(--muted); color: var(--muted-fg); }
93 .input[data-size="lg"] { min-height: 52px; padding: 12px 14px; font-size: 16px; }
9394 .input[data-size="sm"] { min-height: 28px; padding: 4px 8px; font-size: 13px; }
9495 textarea.input {
9596 resize: vertical; min-height: 88px; line-height: 1.55; font-family: inherit;
@@ -453,6 +454,11 @@ details[open] > summary.row > .row-lead { transform: rotate(90deg); }
453454 .setting-list .row-trail { flex: 0 1 auto; max-width: 100%; }
454455 @media (max-width: 640px) { .setting-list .row-trail { flex-basis: 100%; } }
455456 @media (pointer: coarse) { .row-actions { opacity: 1; } .row { min-height: 44px; } }
457 /* A picker row's name is a link beside its tick: both keep a 44px target. */
458 @media (pointer: coarse) {
459 [data-pick-rows] .row-title { display: flex; align-items: center; gap: 8px; }
460 [data-pick-rows] .row-title a { display: inline-flex; align-items: center; min-height: 44px; }
461 }
456462 .row[data-state="closed"] .row-title, .row[data-state="merged"] .row-title { color: var(--muted-fg); }
457463
458464 /* ---- edit row: a list row whose body is a small form ---- */
src/web/ui.ts +36 −1
@@ -162,6 +162,8 @@ export interface BtnOptions {
162162 /** Submit a form this button does not sit inside — the way to offer two
163163 * actions in one row without nesting forms, which HTML forbids. */
164164 form?: string;
165 /** Where this button submits its form instead of the form's own action. */
166 formaction?: string;
165167 /** A `g i`-style keyboard sequence the shell's shortcut layer picks up. */
166168 shortcut?: string;
167169 /** Copy the text of the element with this id (enhancement; inert with JS off). */
@@ -201,6 +203,7 @@ export function btn(content: Html | string, o: BtnOptions = {}): Html {
201203 ${o.name ? html`name="${o.name}"` : null}
202204 ${o.value !== undefined ? html`value="${o.value}"` : null}
203205 ${o.form ? html`form="${o.form}"` : null}
206 ${o.formaction ? html`formaction="${o.formaction}"` : null}
204207 ${o.disabled ? raw("disabled") : null}
205208 ${btnAttrs(o)}
206209 >
@@ -1144,6 +1147,8 @@ export function menu(o: {
11441147
11451148 export interface FieldOptions {
11461149 label: string;
1150 /** `lg`: the one large field a page is for. */
1151 size?: "lg";
11471152 name: string;
11481153 value?: string;
11491154 type?: string;
@@ -1164,6 +1169,35 @@ export interface FieldOptions {
11641169 id?: string;
11651170 }
11661171
1172 /**
1173 * A search box for a list that filters as you type: `data-search` names the
1174 * list it narrows (the id of its container), and a script may swap that
1175 * container for the server's answer to the same query. Without a script it
1176 * is a plain GET field — Enter narrows on the server.
1177 */
1178 export function searchInput(o: {
1179 name: string;
1180 value: string;
1181 label: string;
1182 placeholder: string;
1183 /** The id of the list container this box narrows. */
1184 target: string;
1185 /** The GET form it belongs to, when it sits outside one. */
1186 form?: string;
1187 }): Html {
1188 return html`<input
1189 class="input"
1190 type="search"
1191 name="${o.name}"
1192 value="${o.value}"
1193 aria-label="${o.label}"
1194 placeholder="${o.placeholder}"
1195 autocomplete="off"
1196 data-search="${o.target}"
1197 ${o.form ? html`form="${o.form}"` : null}
1198 />`;
1199 }
1200
11671201 /** Label, control, hint and error, wired together with `aria-describedby`. */
11681202 export function field(o: FieldOptions): Html {
11691203 const id = o.id ?? `f-${o.name}`;
@@ -1178,7 +1212,8 @@ export function field(o: FieldOptions): Html {
11781212 ${o.autofocus ? raw("autofocus") : null}
11791213 ${o.readonly ? raw("readonly") : null}
11801214 ${o.placeholder ? html`placeholder="${o.placeholder}"` : null}
1181 ${o.spellcheck === false ? raw('spellcheck="false"') : null}`;
1215 ${o.spellcheck === false ? raw('spellcheck="false"') : null}
1216 ${o.size === "lg" ? raw('data-size="lg"') : null}`;
11821217 const control =
11831218 o.type === "textarea"
11841219 ? html`<textarea ${shared} rows="${o.rows ?? 6}" data-grow>
test/html-tight.test.ts added +25
@@ -0,0 +1,25 @@
1 import { expect, test } from "bun:test";
2 import { html, raw, tight } from "../src/web/html.ts";
3
4 test("tight drops indentation and whitespace between block tags", () => {
5 const out = tight(html`<ul>
6 <li>
7 <div class="row" >a</div>
8 </li>
9 </ul>`).text;
10 expect(out).toBe('<ul><li><div class="row">a</div></li></ul>');
11 });
12
13 test("tight keeps the space between inline tags, so words stay apart", () => {
14 const out = tight(html`<p>
15 <a href="/x">one</a>
16 <span>two</span>
17 </p>`).text;
18 expect(out).toBe('<p><a href="/x">one</a> <span>two</span></p>');
19 });
20
21 test("tight leaves text and escaped angle brackets alone", () => {
22 const out = tight(html`<p>${"a > b < c"} and more</p>`).text;
23 expect(out).toBe("<p>a &gt; b &lt; c and more</p>");
24 expect(tight(raw("<b>x</b>")).text).toBe("<b>x</b>");
25 });
test/migrate-layout.test.ts added +297
@@ -0,0 +1,297 @@
1 /** `/migrate` leads with the URL field; accounts are compact and show eight rows (#5816). */
2 import { afterAll, beforeAll, expect, test } from "bun:test";
3 import { mkdtempSync, rmSync } from "node:fs";
4 import { tmpdir } from "node:os";
5 import { join } from "node:path";
6 import { createApp, type App } from "../src/app.ts";
7 import { cacheOriginRepos, createOrigin } from "../src/core/origins.ts";
8 import { createUser } from "../src/core/users.ts";
9 import { serve, type Servers } from "../src/http/server.ts";
10 import { byRecentPush, migrateJs, MULTI_MAX, PICKER_ROWS } from "../src/web/pages/migrate.ts";
11 import { createToken } from "../src/core/tokens.ts";
12 import { searchInput, btn } from "../src/web/ui.ts";
13 import { connectOrigin } from "../src/actions/origins.ts";
14 import { forgetProviders } from "../src/origins/providers/index.ts";
15 import { newFakeState, serveFakeForge, type FakeForge } from "./fake-origin.ts";
16 import type { User } from "../src/core/users.ts";
17 import { quietLogs } from "./helpers/globals.ts";
18
19 quietLogs();
20
21 let root = "";
22 let app: App;
23 let servers: Servers;
24 let cookie = "";
25 let userId = "";
26 let alice: User;
27 let fake: FakeForge | undefined;
28 let fakeOrigin = "";
29
30 beforeAll(async () => {
31 root = mkdtempSync(join(tmpdir(), "forge-migrate-layout-"));
32 app = createApp({ dataDir: root, port: 0, forgeRepo: "alice/forge" });
33 const u = await createUser(app.db, {
34 origin: "seed",
35 trusted: true,
36 username: "alice",
37 email: "[email protected]",
38 password: "a-good-passphrase",
39 adminIfFirst: true,
40 });
41 if (!u.ok) throw new Error(u.error);
42 userId = u.value.id;
43 alice = u.value;
44 servers = await serve(app);
45 const signin = await fetch(`${servers.url}/signin`, {
46 method: "POST",
47 headers: { origin: servers.url },
48 body: new URLSearchParams({ username: "alice", password: "a-good-passphrase" }),
49 redirect: "manual",
50 });
51 cookie = (signin.headers.get("set-cookie") ?? "").split(";")[0]!;
52 });
53 afterAll(() => {
54 fake?.stop();
55 servers.stop();
56 app.close();
57 rmSync(root, { recursive: true, force: true });
58 });
59
60 const get = async (path: string): Promise<string> =>
61 (await fetch(`${servers.url}${path}`, { headers: { cookie } })).text();
62
63 const main = (page: string): string => page.slice(page.indexOf("<main"));
64 const rowCount = (page: string): number => page.split('name="pick"').length - 1;
65
66 test("with no account the URL field leads and there is no list", async () => {
67 const bare = await get("/migrate");
68 const page = main(bare);
69 expect(page).toContain('name="url"');
70 expect(page).toContain("Paste a repository URL");
71 expect(page).not.toContain('name="pick"');
72 expect(page).not.toContain("Your accounts</h3>");
73 expect(page).toContain("Connect GitHub");
74 });
75
76 test("200 repositories: the URL field is the first input, the page is small, eight rows show until you search", async () => {
77 const made = createOrigin(app.db, root, {
78 userId,
79 kind: "github",
80 apiUrl: "https://api.github.com",
81 webUrl: "https://github.com",
82 login: "octo",
83 token: "t0ken",
84 });
85 if (!made.ok) throw new Error(made.error);
86 const repos = Array.from({ length: 200 }, (_, i) => ({
87 remoteId: String(1000 + i),
88 owner: "octo",
89 name: `repo-${i}`,
90 fullName: `octo/repo-${i}`,
91 description: `Repository number ${i}, and a plain line about it`,
92 private: i === 5,
93 fork: false,
94 defaultBranch: "main",
95 cloneUrl: `https://github.com/octo/repo-${i}.git`,
96 htmlUrl: `https://github.com/octo/repo-${i}`,
97 pushedAt: new Date(Date.UTC(2026, 0, 1) + i * 86_400_000).toISOString(),
98 sshUrl: "",
99 permissions: { push: true, admin: false },
100 openIssues: 0,
101 openPulls: 0,
102 openIssuesIncludesPulls: false,
103 sizeKb: 2048,
104 parent: null,
105 }));
106 cacheOriginRepos(app.db, made.value.id, repos);
107
108 const full = await get("/migrate");
109 const page = main(full);
110 // The page's own part (the form and the rows) stays small; the shared
111 // shell around it is not this page's to shrink.
112 const own = page.slice(0, page.indexOf("</main>"));
113 expect(new TextEncoder().encode(own).length).toBeLessThan(14 * 1024);
114 expect(new TextEncoder().encode(full).length).toBeLessThan(40 * 1024);
115 const firstInput = /<input[^>]*>/s.exec(page)![0];
116 expect(firstInput).toContain('name="url"');
117 expect(rowCount(full)).toBe(PICKER_ROWS);
118 // Every tick box is named, or a screen reader hears eight unnamed boxes.
119 const boxes = page.match(/<input[^>]*name="multi"[^>]*>/g) ?? [];
120 expect(boxes.length).toBe(PICKER_ROWS);
121 for (const box of boxes) expect(box).toMatch(/aria-label="Select octo\/repo-\d+"/);
122 // Disconnect submits the shared drop form to this account's own route.
123 expect(page).toMatch(/<button[^>]*form="drop"[^>]*formaction="\/settings\/origins\/[^"]+\/delete"/);
124 expect(page).toContain('data-search="pick-');
125 expect(page).toContain("200 repositories");
126 expect(page).toContain("192 more");
127 // Newest push first.
128 expect(page.indexOf("octo/repo-199")).toBeLessThan(page.indexOf("octo/repo-198"));
129 expect(page).not.toContain("octo/repo-3<");
130
131 // Searching reaches rows beyond the eight, on the server too.
132 const found = await get("/migrate?q=repo-0");
133 expect(found).toContain("octo/repo-0<");
134 expect(rowCount(found)).toBe(1);
135 const many = await get("/migrate?q=repo-17");
136 expect(many).toContain("octo/repo-179<");
137 expect(many).not.toContain("octo/repo-170<");
138 expect(rowCount(many)).toBe(PICKER_ROWS);
139 expect(many).toContain("3 more");
140 });
141
142 test("a pasted URL of one of your repositories shows its visibility and size", async () => {
143 const known = await get("/migrate?url=" + encodeURIComponent("https://github.com/octo/repo-5.git"));
144 const preview = /id="migrate-preview"[^>]*>([\s\S]*?)<\/p>/.exec(known)![1]!;
145 expect(preview).toContain("octo/repo-5");
146 expect(preview).toContain("private");
147 expect(preview).toContain("2.0 MiB");
148 const other = await get("/migrate?url=" + encodeURIComponent("https://gitlab.com/x/y"));
149 expect(/id="migrate-preview"[^>]*>([\s\S]*?)<\/p>/.exec(other)![1]).toContain("gitlab.com");
150 const junk = await get("/migrate?url=" + encodeURIComponent("<script>alert(1)</script>"));
151 expect(junk).not.toContain("<script>alert(1)");
152 });
153
154 test("Migrate selected needs a tick, and a tick and a URL are not both", async () => {
155 const post = (body: Record<string, string | string[]>) => {
156 const form = new URLSearchParams();
157 for (const [k, v] of Object.entries(body))
158 for (const one of Array.isArray(v) ? v : [v]) form.append(k, one);
159 return fetch(`${servers.url}/migrate`, {
160 method: "POST",
161 headers: { cookie, origin: servers.url },
162 body: form,
163 redirect: "manual",
164 });
165 };
166 const none = await post({ go: "multi", url: "", owner: "alice" });
167 expect(none.status).toBe(422);
168 expect(await none.text()).toContain("Tick the repositories");
169 const both = await post({ multi: ["x/octo/repo-1"], url: "https://github.com/a/b", owner: "alice", go: "multi" });
170 expect(both.status).toBe(422);
171 expect(await both.text()).toContain("not both");
172 });
173
174 test("recently pushed sorts first, unknown last", () => {
175 const rows = [{ pushedAt: null }, { pushedAt: "2026-01-01T00:00:00Z" }, { pushedAt: "2026-02-01T00:00:00Z" }];
176 expect(byRecentPush(rows).map((r) => r.pushedAt)).toEqual(["2026-02-01T00:00:00Z", "2026-01-01T00:00:00Z", null]);
177 });
178
179 /** A real (fake) forgejo behind one more account, so a started job can resolve its source. */
180 async function fakeAccount(): Promise<string> {
181 if (fakeOrigin !== "") return fakeOrigin;
182 const state = newFakeState("forgejo", "octo", "fake-secret");
183 for (let i = 0; i < 80; i++)
184 state.repos.push({
185 id: 7000 + i,
186 fullName: `octo/pick-${i}`,
187 description: "",
188 cloneUrl: `http://127.0.0.1:9/octo/pick-${i}.git`,
189 htmlUrl: `http://127.0.0.1:9/octo/pick-${i}`,
190 defaultBranch: "main",
191 private: false,
192 });
193 fake = serveFakeForge(state);
194 forgetProviders(root);
195 const connected = await connectOrigin(app, alice, { host: fake.url, kind: "forgejo", token: "fake-secret" });
196 if (!connected.ok) throw new Error(connected.error);
197 fakeOrigin = connected.value.id;
198 return fakeOrigin;
199 }
200
201 const pickOf = async (index: number): Promise<string> => `${await fakeAccount()}/octo/pick-${index}`;
202
203 const postWith = (headers: Record<string, string>, body: URLSearchParams) =>
204 fetch(`${servers.url}/migrate`, {
205 method: "POST",
206 headers: { origin: servers.url, ...headers },
207 body,
208 redirect: "manual",
209 });
210
211 const ticks = (picks: string[]): URLSearchParams => {
212 const form = new URLSearchParams({ go: "multi", url: "", owner: "alice", visibility: "private" });
213 for (const p of picks) form.append("multi", p);
214 return form;
215 };
216
217 test("one tick starts one job and lands on its page; duplicates collapse", async () => {
218 const one = await postWith({ cookie }, ticks([await pickOf(1)]));
219 expect(one.status).toBe(303);
220 expect(one.headers.get("location")).toMatch(/^\/migrate\/jobs\/[A-Za-z0-9]+$/);
221 const twice = await postWith({ cookie }, ticks([await pickOf(2), await pickOf(2)]));
222 expect(twice.status).toBe(303);
223 expect(twice.headers.get("location")).toMatch(/^\/migrate\/jobs\//);
224 });
225
226 test("several ticks go to the feed with a flash saying how many", async () => {
227 const several = await postWith({ cookie }, ticks([await pickOf(3), await pickOf(4), await pickOf(5)]));
228 expect(several.status).toBe(303);
229 expect(several.headers.get("location")).toBe("/");
230 expect(decodeURIComponent(several.headers.get("set-cookie") ?? "")).toContain("Started 3 migrations");
231 });
232
233 test(`Migrate selected starts at most ${MULTI_MAX}`, async () => {
234 const picks: string[] = [];
235 for (let i = 10; i < 10 + MULTI_MAX + 5; i++) picks.push(await pickOf(i));
236 const res = await postWith({ cookie }, ticks(picks));
237 expect(res.status).toBe(303);
238 expect(decodeURIComponent(res.headers.get("set-cookie") ?? "")).toContain(`Started ${MULTI_MAX} migrations`);
239 });
240
241 test("a token that cannot spend an account's credential is refused ticked rows", async () => {
242 const rw = createToken(app.db, userId, "multi", "rw").token;
243 const res = await postWith({ authorization: `Bearer ${rw}` }, ticks([await pickOf(60)]));
244 expect(res.status).toBe(403);
245 });
246
247 test("without a script, a search in any account's box filters, the empty boxes ignored", async () => {
248 const second = createOrigin(app.db, root, {
249 userId,
250 kind: "forgejo",
251 apiUrl: "https://git.example.test/api/v1",
252 webUrl: "https://git.example.test",
253 login: "alice",
254 token: "t0ken",
255 });
256 if (!second.ok) throw new Error(second.error);
257 cacheOriginRepos(app.db, second.value.id, [
258 {
259 remoteId: "9001", owner: "alice", name: "zebra", fullName: "alice/zebra", description: "", private: false,
260 fork: false, defaultBranch: "main", cloneUrl: "https://git.example.test/alice/zebra.git",
261 htmlUrl: "https://git.example.test/alice/zebra", sshUrl: "", pushedAt: null,
262 permissions: { push: true, admin: false }, openIssues: 0, openPulls: 0,
263 openIssuesIncludesPulls: false, sizeKb: 0, parent: null,
264 },
265 ]);
266 const full = await get("/migrate");
267 // One shared GET form, both boxes attached to it.
268 expect(full.match(/data-search="pick-[^"]+"[^>]*form="find"|form="find"[^>]*data-search/g)?.length ?? 0).toBeGreaterThanOrEqual(2);
269 expect(full).toContain('<form id="find" method="get" action="/migrate">');
270 // A browser sends every box; the empty one first must not win.
271 const res = await get("/migrate?q=&q=zebra");
272 expect(res).toContain("alice/zebra<");
273 expect(res).not.toContain("octo/repo-199<");
274 });
275
276 test("searchInput names its list and its form, and escapes its words", () => {
277 const out = searchInput({
278 name: "q", value: '"><x>', label: "Find", placeholder: "Search", target: "pick-1", form: "find",
279 }).text;
280 expect(out).toContain('type="search"');
281 expect(out).toContain('data-search="pick-1"');
282 expect(out).toContain('form="find"');
283 expect(out).not.toContain("<x>");
284 expect(btn("Go", { form: "drop", formaction: "/a/b" }).text).toContain('formaction="/a/b"');
285 });
286
287 test("the page holds no <pre> or <textarea>, which tight() would mangle", async () => {
288 const page = await get("/migrate");
289 expect(page).not.toMatch(/<pre[\s>]/i);
290 expect(page).not.toMatch(/<textarea[\s>]/i);
291 });
292
293 test("a live swap aborts the one before it and drops an answer that is no longer the latest", async () => {
294 expect(migrateJs).toContain("new AbortController");
295 expect(migrateJs).toContain(".abort()");
296 expect(migrateJs).toMatch(/flying\[\w+\]\s*!==\s*ctl/);
297 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs