Skip to content

g1t/apps/web/app/routes/repo/pull.tsx

1,452 lines64,717 bytesCodeBlame
1import { env } from "cloudflare:workers";
2import {
3 Bot,
4 ChevronRight,
5 FileDiff,
6 GitBranch,
7 GitCommitHorizontal,
8 CircleCheck,
9 CircleSlash,
10 GitMerge,
11 Layers,
12 GitPullRequestArrow,
13 Hand,
14 Loader,
15 Radar,
16 Sparkles,
17 MessageSquare,
18 ArrowUpRight,
19 MessagesSquare,
20 Rocket,
21 Network,
22 StickyNote,
23 User,
24 Wrench,
25} from "lucide-react";
26import { Suspense } from "react";
27import { Await, Form, Link, redirect } from "react-router";
28
29import {
30 type Capability,
31 type Comparison,
32 type Deployment,
33 type Job,
34 type LiveApp,
35 type SessionEntry,
36 type Viewer,
37 pullComparison,
38 workOwner,
39} from "@g1t/contracts";
40
41import type { Route } from "./+types/pull";
42import { excerpt, page } from "../../lib/meta";
43import { openedBy } from "../../lib/opened-by";
44import { cloneUrl, useAddresses } from "../../lib/addresses";
45import { DiffView } from "../../components/diff-view";
46import { LifecyclePanel } from "../../components/lifecycle";
47import { AgentPanel } from "../../components/agents";
48import { Markdown } from "../../components/markdown";
49import {
50 Avatar,
51 ButtonLink,
52 CopyLine,
53 EmptyState,
54 ComputeNote,
55 ErrorText,
56 SubmitButton,
57 Textarea,
58 TimeAgo,
59 usePending,
60} from "../../components/ui";
61import { CheckboxOption } from "../../components/ui/checkbox";
62import { WorkflowStatuses } from "../../components/actions";
63import { AddCiPrompt } from "../../components/add-ci";
64import {
65 CommentForm,
66 CommentList,
67 IssueIcon,
68 PeoplePicker,
69 PersonLink,
70 PullState,
71 TimelineItem,
72 verdicts,
73} from "../../components/work";
74import { CatchUpProgress, ChecksSection, ConflictsSection, MergeabilityRow, runIdOf } from "../../components/merge-box";
75import { CATCH_UP_TIMEOUT_MS } from "../../lib/catch-up";
76import { notFound } from "../../lib/not-found.server";
77import { computeNoteFor } from "../../lib/compute.server";
78import { actions, deployments, identity, inbox, projects, repos, work } from "../../lib/services.server";
79import { assertSameOrigin, getViewer, requireUser } from "../../lib/session.server";
80import { accessTo, refusal, repoFor } from "../../lib/access.server";
81import { SubscriptionBox } from "../../components/notifications";
82import { REFRESH_MS, useRefreshWhile } from "../../lib/refresh";
83
84const EMPTY_COMPARISON: Comparison = { base: null, head: "", files: [], truncated: false };
85const TABS = ["conversation", "session", "changes"] as const;
86type Tab = (typeof TABS)[number];
87
88export function meta({ loaderData, params, ...args }: Route.MetaArgs) {
89 const pull = loaderData?.pull;
90 const title = pull ? `${pull.title} · Pull request #${pull.number} · ` : "";
91 const state = { draft: "Draft", open: "Open", merged: "Merged", closed: "Closed" }[pull?.status ?? "open"];
92 const body = excerpt(pull?.body);
93 const opener = pull ? openedBy(pull) : null;
94 return page(args, {
95 title: `${title}${params.owner}/${params.repo} · g1t`,
96 description: pull
97 ? `${state} pull request #${pull.number} on ${params.owner}/${params.repo} by ${opener!.name}${opener!.requestedBy ? `, requested by ${opener!.requestedBy}` : ""}.${body ? ` ${body}` : ""}`
98 : null,
99 // The card shows the title and the state.
100 version: pull ? [pull.title, pull.status] : undefined,
101 type: "article",
102 });
103}
104
105export async function loader({ params, context, request }: Route.LoaderArgs) {
106 const viewer = getViewer(context);
107 const path = { namespace: params.owner, name: params.repo };
108 const number = Number(params.number);
109 const asked = new URL(request.url).searchParams.get("tab");
110 const tab: Tab = TABS.find((name) => name === asked) ?? "conversation";
111
112 // Members of the workspace pick reviewers and assignees from its people;
113 // what the viewer may do here goes by their role on the repository.
114 const member = (viewer?.workspaces ?? []).some(
115 (membership) => membership.slug === params.owner,
116 );
117 // Everything starts at once. Only what the viewer's role decides waits
118 // for the repository, which the layout is looking up in this request too
119 // (lib/access.server.ts), and only what the pull request decides waits
120 // for it.
121 const ref = { workspace: params.owner, slug: params.repo };
122 const access = accessTo(context, params);
123 const pullFound = work.getPull(path, number, viewer);
124 const deps = projects.dependencies(params.owner, params.repo, viewer);
125 // Awaited below, unless the pull request is missing first.
126 deps.catch(() => null);
127 const [{ can }, found, repo, settings, agentsEnabled, members, computeNote, session, deployed, subscription] = await Promise.all([
128 access,
129 pullFound,
130 repos.get(path, viewer),
131 work.getSettings(path, viewer),
132 env.RUNNER.enabled(viewer, path),
133 // A member picks reviewers and assignees from the workspace's people.
134 member ? identity.listMembers(params.owner, viewer) : null,
135 // Before someone asks g1t for something: whether the plan lets it start.
136 access.then(({ can }) => (can.run ? computeNoteFor(params.owner, "agent") : null)),
137 tab === "session" ? work.readSession(path, number, viewer) : null,
138 // Its preview, for people with a role here: beside the rest, not after.
139 access.then(({ insider }) => (insider ? deployments.list(ref, viewer).catch(() => null) : null)),
140 // Whether the viewer hears of it, for the sidebar's Notifications.
141 viewer
142 ? repoFor(context, params).then((found) =>
143 found.ok ? inbox.subscription(viewer, { repoId: found.value.id, number }).catch(() => null) : null,
144 )
145 : null,
146 ]);
147 if (!found.ok) {
148 // Issues and pull requests share numbers; this one may be an issue.
149 const issue = await work.getIssue(path, number, viewer);
150 if (issue.ok) throw redirect(`/${params.owner}/${params.repo}/issues/${number}`);
151 throw notFound("pull");
152 }
153 const { pull } = found.value;
154 const range = pullComparison(pull);
155 // The jobs of each workflow run on its head, to list checks job by job.
156 // Read as the viewer: a run they cannot see is listed by its status alone.
157 // Streamed: the checks show by status first, then job by job.
158 const runIds = [...new Set((found.value.statuses ?? []).map(runIdOf).filter((id) => id != null))].slice(0, 10);
159 const workflowJobs =
160 tab === "conversation" && pull.status === "open" && runIds.length > 0
161 ? Promise.all(runIds.map((id) => actions.run(path, viewer, id).catch(() => null))).then((runs) => {
162 const jobs: Record<string, Job[]> = {};
163 for (const run of runs) if (run?.ok) jobs[run.value.run.id] = run.value.jobs;
164 return jobs;
165 })
166 .catch(() => ({}) as Record<string, Job[]>)
167 : Promise.resolve({} as Record<string, Job[]>);
168 // No checks at all on an open pull request: whether that is because the
169 // repository has no workflows, to offer a starter one.
170 const unchecked =
171 tab === "conversation" &&
172 pull.status === "open" &&
173 (found.value.statuses ?? []).length === 0 &&
174 (found.value.requiredChecks ?? []).length === 0;
175 const [comparison, used, noChecks] = await Promise.all([
176 tab === "changes" ? repos.compare(range.repoId, viewer, range.base, range.head) : null,
177 deps,
178 unchecked
179 ? actions
180 .workflows(path, viewer)
181 .then((found) => found.ok && found.value.length === 0)
182 .catch(() => false)
183 : false,
184 ]);
185 const affects = used.ok ? used.value.usedBy : [];
186 return {
187 ...found.value,
188 workflowJobs,
189 tab,
190 session: session?.ok ? session.value : [],
191 // An empty comparison if it could not be made.
192 comparison: comparison && (comparison.ok ? comparison.value : EMPTY_COMPARISON),
193 viewer,
194 // Write and up can merge.
195 canMerge: can.merge,
196 // Triage and up manage anyone's pull request; its author, their own,
197 // and whoever asked g1t for one, that one.
198 canManage: can.triage || (viewer != null && viewer.id === workOwner(pull).id),
199 // Telling its agent things, and re-running checks, spend compute: Write and up.
200 canRun: can.run,
201 // A catch-up is pushed as the viewer: a fork takes pushes only from
202 // whoever it is for (who asked g1t for it, or its author), a branch
203 // from anyone who can push.
204 canUpdate: pull.fork ? viewer?.id === workOwner(pull).id : can.push,
205 agentsEnabled,
206 computeNote,
207 subscription,
208 members: members?.ok ? members.value.map((person) => person.username) : [],
209 requireUpToDate: settings.ok && settings.value.requireUpToDate,
210 mergeQueue: settings.ok && settings.value.mergeQueue,
211 requiredApprovals: settings.ok ? settings.value.requiredApprovals : 0,
212 canIgnoreChecks: !settings.ok || settings.value.allowIgnoringChecks,
213 noChecks,
214 // Who may open the pull request that adds CI: anyone who can push.
215 canAddCi: can.push,
216 // Who may choose the required checks.
217 canProtect: can.manage_protection,
218 defaultBranch: repo.ok ? repo.value.defaultBranch : "main",
219 affects,
220 // Streamed: the conversation shows first, the preview card after.
221 ...deploymentOf(deployed?.ok ? deployed.value : null, number, params.owner, affects, viewer),
222 };
223}
224
225/**
226 * Where this pull request is live: its preview (or its latest build, while
227 * one is going or after one failed), and the previews of the projects
228 * that use this one, built against it.
229 */
230function deploymentOf(
231 list: { deployments: Deployment[]; live: LiveApp[] } | null,
232 number: number,
233 owner: string,
234 affects: { slug: string; name: string }[],
235 viewer: Viewer,
236): { preview: LiveApp | null; build: Deployment | null; stacked: Promise<Stacked[]> } {
237 const preview = list?.live.find((app) => app.kind === "preview" && app.number === number) ?? null;
238 const build = list?.deployments.find((d) => d.kind === "preview" && d.number === number) ?? null;
239 const branch = preview?.branch ?? build?.branch ?? null;
240 // Streamed: another lookup per project, shown in the card once known.
241 const stacked: Promise<Stacked[]> = branch
242 ? Promise.all(
243 affects.slice(0, 5).map(async (project) => {
244 const theirs = await deployments.list({ workspace: owner, slug: project.slug }, viewer).catch(() => null);
245 const app = theirs?.ok ? theirs.value.live.find((a) => a.kind === "preview" && a.branch === branch) : undefined;
246 return app ? { name: project.name, slug: project.slug, url: app.url } : null;
247 }),
248 ).then((found) => found.filter((entry) => entry != null))
249 : Promise.resolve([]);
250 return { preview, build, stacked };
251}
252
253/** A project that uses this one, with its preview built against this change. */
254type Stacked = { name: string; slug: string; url: string };
255
256const PULL_NEEDS: Record<string, Capability> = {
257 stack: "run",
258 "agent-review": "run",
259 "rerun-workflow": "run",
260 "rerun-failed": "run",
261 message: "run",
262 merge: "merge",
263 unqueue: "merge",
264};
265
266export async function action({ request, params, context }: Route.ActionArgs) {
267 assertSameOrigin(request);
268 const user = requireUser(context, request);
269 const form = await request.formData();
270 const path = { namespace: params.owner, name: params.repo };
271 const number = Number(params.number);
272 const action = form.get("action");
273 // What each form needs beyond reading; work checks the rest.
274 const needed = typeof action === "string" ? PULL_NEEDS[action] : undefined;
275 const refused = needed ? await refusal(context, params, needed) : null;
276 if (refused) return { error: refused, action: String(action) };
277 const verdict = form.get("verdict");
278 const line = Number(form.get("line"));
279 /** Names ticked in a people picker, plus those typed beside it. */
280 const picked = (field: string) => [
281 ...form.getAll(field).map(String),
282 ...String(form.get("others") ?? "").split(/[\s,]+/),
283 ];
284 // The projects that use this one, built against this pull request's preview.
285 if (action === "stack") {
286 const built = await deployments.stack(user, { workspace: params.owner, slug: params.repo }, String(form.get("branch") ?? ""));
287 return built.ok
288 ? { action, notice: `Building ${built.value.join(", ")} against this preview. They appear on their Deployments pages.` }
289 : { action, error: built.error.message };
290 }
291 // Asking g1t for its review records the request, then starts it.
292 if (action === "agent-review") {
293 const asked = await work.updatePull(user, path, number, {
294 reviewers: [...form.getAll("reviewer").map(String), "g1t"],
295 });
296 if (!asked.ok) return { error: asked.error.message, action };
297 }
298 // Catching up: merged and pushed in seconds when the two sides changed
299 // different files; otherwise handed to a sandbox, which takes a minute.
300 if (action === "update") {
301 const caught = await work.catchUpPull(user, path, number);
302 if (!caught.ok) return { action, error: caught.error.message };
303 const update = caught.value;
304 if (update.outcome !== "needs_agent") {
305 return {
306 action,
307 updated: { commit: update.commit, already: update.outcome === "up_to_date", at: Date.now() },
308 };
309 }
310 const started = await env.RUNNER.update(user, path, number);
311 if (!started.ok) return { action, error: started.error.message };
312 return { action, agent: { update, startedAt: Date.now() } };
313 }
314 // A workflow run's failed jobs, run again. Who may is the actions service's call.
315 if (action === "rerun-workflow") {
316 const rerun = await actions.rerun(user, path, String(form.get("run") ?? ""), true);
317 return rerun.ok ? null : { error: rerun.error.message, action };
318 }
319 // Every failed run on its head, run again: Mission control's quick action.
320 if (action === "rerun-failed") {
321 const found = await work.getPull(path, number, user);
322 if (!found.ok) return { error: found.error.message, action };
323 const failed = [
324 ...new Set(
325 (found.value.statuses ?? [])
326 .filter((status) => status.state === "failure" || status.state === "error")
327 .map(runIdOf)
328 .filter((id) => id != null),
329 ),
330 ];
331 if (failed.length === 0) return { error: "No workflow run failed on its latest commit.", action };
332 const reruns = await Promise.all(failed.map((id) => actions.rerun(user, path, id, true)));
333 const refused = reruns.find((rerun) => !rerun.ok);
334 return refused && !refused.ok ? { error: refused.error.message, action } : null;
335 }
336 const result =
337 action === "merge"
338 ? await work.mergePull(user, path, number, {
339 keepIssueOpen: form.get("keepIssueOpen") === "on",
340 ignoreChecks: form.get("ignoreChecks") === "on",
341 })
342 : action === "unqueue"
343 ? await work.removeFromQueue(user, path, number)
344 : action === "message"
345 ? await work.messageAgent(user, path, number, String(form.get("body") ?? ""))
346 : action === "close"
347 ? await work.closePull(user, path, number)
348 : action === "agent-review"
349 ? await env.RUNNER.review(user, path, number)
350 : action === "reviewers"
351 ? await work.updatePull(user, path, number, { reviewers: picked("reviewer") })
352 : action === "assign"
353 ? await work.updatePull(user, path, number, { assignees: picked("assignee") })
354 : action === "comment"
355 ? await work.addComment(user, path, number, {
356 body: String(form.get("body") ?? ""),
357 path: String(form.get("path") ?? "") || undefined,
358 line: line > 0 ? line : undefined,
359 verdict:
360 verdict === "approve" || verdict === "request_changes" ? verdict : undefined,
361 })
362 : await work.readyPull(user, path, number, String(form.get("summary") ?? ""));
363 return result.ok ? null : { error: result.error.message, action };
364}
365
366/** How many, beside a tab's name, when there are any. */
367function TabCount({ n }: { n: number }) {
368 if (n <= 0) return null;
369 return (
370 <span className="rounded-full bg-raised px-1.5 py-px text-xs tabular-nums text-muted ring-1 ring-line">
371 {n.toLocaleString("en-US")}
372 </span>
373 );
374}
375
376function TabLink({
377 to,
378 active,
379 children,
380}: {
381 to: string;
382 active: boolean;
383 children: React.ReactNode;
384}) {
385 return (
386 <Link
387 to={to}
388 preventScrollReset
389 className={
390 "-mb-px flex items-center gap-2 border-b-2 px-3 pb-2.5 text-sm transition-colors " +
391 (active
392 ? "border-accent font-medium text-fg"
393 : "border-transparent text-muted hover:text-fg")
394 }
395 >
396 {children}
397 </Link>
398 );
399}
400
401/** One step of the session, on the timeline's rail. */
402function Entry({ entry, agent }: { entry: SessionEntry; agent: string }) {
403 const isTool = entry.kind === "tool_call" || entry.kind === "tool_result";
404 const Icon =
405 entry.kind === "prompt"
406 ? User
407 : entry.kind === "note"
408 ? StickyNote
409 : isTool
410 ? Wrench
411 : Bot;
412 return (
413 <li className="relative pl-10">
414 <span
415 className={`absolute top-0.5 left-0 flex size-7 items-center justify-center rounded-full border bg-bg ${
416 entry.kind === "prompt"
417 ? "border-accent/50 text-accent"
418 : "border-line text-faint"
419 }`}
420 >
421 <Icon size={14} />
422 </span>
423 {isTool ? (
424 <details className="group rounded-lg border border-line bg-surface">
425 <summary className="flex cursor-pointer list-none items-center gap-2 px-3 py-1.5 text-sm">
426 <ChevronRight
427 size={14}
428 className="text-faint transition-transform group-open:rotate-90"
429 />
430 <span className="font-mono text-xs text-accent">
431 {entry.tool ?? "tool"}
432 </span>
433 <span className="truncate font-mono text-xs text-muted">
434 {entry.kind === "tool_result" ? "→ " : ""}
435 {entry.text.split("\n")[0]}
436 </span>
437 </summary>
438 <pre className="overflow-x-auto border-t border-line p-3 font-mono text-xs whitespace-pre-wrap text-muted">
439 <code>{entry.text}</code>
440 </pre>
441 </details>
442 ) : (
443 <div>
444 <p className="text-xs font-medium text-faint">
445 {entry.kind === "prompt"
446 ? "Prompt"
447 : entry.kind === "note"
448 ? "Note"
449 : agent}
450 </p>
451 {entry.kind === "message" ? (
452 <div className="mt-1">
453 <Markdown source={entry.text} />
454 </div>
455 ) : entry.kind === "prompt" ? (
456 <div className="mt-1.5 max-h-[32rem] overflow-y-auto rounded-xl border border-line bg-surface p-4">
457 <Markdown source={entry.text} />
458 </div>
459 ) : (
460 <p className="mt-1 text-[0.9375rem] leading-relaxed wrap-break-word whitespace-pre-wrap">
461 {entry.text}
462 </p>
463 )}
464 </div>
465 )}
466 {entry.commit && (
467 <p className="mt-1.5 flex items-center gap-1 font-mono text-xs text-faint">
468 <GitCommitHorizontal size={12} />
469 {entry.commit.slice(0, 7)}
470 </p>
471 )}
472 </li>
473 );
474}
475
476/** The box at the foot of the conversation saying what stands before a merge. */
477function StatusBox({ children }: { children: React.ReactNode }) {
478 return (
479 <div className="flex gap-3">
480 <span className="hidden w-8 shrink-0 sm:block" />
481 <section className="min-w-0 grow divide-y divide-line overflow-hidden rounded-xl border border-line-strong bg-surface">
482 {children}
483 </section>
484 </div>
485 );
486}
487
488function StatusRow({
489 icon,
490 title,
491 children,
492}: {
493 icon: React.ReactNode;
494 title: string;
495 children?: React.ReactNode;
496}) {
497 return (
498 <div className="flex gap-3 px-4 py-3 text-sm">
499 <span className="mt-0.5 shrink-0">{icon}</span>
500 <div className="min-w-0">
501 <p className="font-medium">{title}</p>
502 {children && <div className="mt-0.5 text-muted">{children}</div>}
503 </div>
504 </div>
505 );
506}
507
508export default function PullPage({ loaderData, actionData, params }: Route.ComponentProps) {
509 const {
510 pull,
511 issue,
512 comments,
513 checks,
514 overlaps,
515 behind,
516 reviewPending,
517 lifecycle,
518 messages,
519 statuses = [],
520 requiredChecks = [],
521 noChecks,
522 canAddCi,
523 canProtect,
524 mergeable = "unknown",
525 conflicts = [],
526 earlierChecks = [],
527 workflowJobs,
528 affects,
529 preview,
530 build,
531 stacked,
532 landing,
533 stalled,
534 requireUpToDate,
535 mergeQueue,
536 requiredApprovals,
537 canIgnoreChecks,
538 canUpdate,
539 agentsEnabled,
540 members,
541 tab,
542 session,
543 comparison,
544 viewer,
545 canMerge,
546 canManage,
547 canRun,
548 defaultBranch,
549 } = loaderData;
550 const base = `/${params.owner}/${params.repo}`;
551 const here = `${base}/pull/${pull.number}`;
552 // g1t, on a pull request it made: the person who asked for it is a line below.
553 const opener = openedBy(pull);
554 const checksSection = (jobs: Record<string, Job[]>) => (
555 <ChecksSection
556 run={checks}
557 required={requiredChecks}
558 statuses={statuses}
559 jobs={jobs}
560 pull={pull}
561 base={base}
562 earlier={earlierChecks}
563 canRerunWorkflows={canMerge}
564 settingsUrl={canProtect ? `${base}/settings/branches` : null}
565 error={actionData?.action === "rerun-failed" || actionData?.action === "rerun-workflow" ? actionData.error : null}
566 />
567 );
568 const addresses = useAddresses();
569 const remote = pull.fork
570 ? cloneUrl(addresses, `${pull.fork.namespace}/${pull.fork.name}`)
571 : cloneUrl(addresses, `${params.owner}/${params.repo}`);
572 const active = pull.status === "draft" || pull.status === "open";
573
574 // Follow an agent at work, or checks in progress, without a manual reload.
575 const working = pull.status === "draft";
576 const checking = statuses.some((status) => status.state === "pending");
577 const reviews = verdicts(comments);
578 // What stands between this pull request and a merge, if anything: a
579 // required check that has not passed, or the merge queue taking it out.
580 const unchecked = requiredChecks.some((check) => check.state !== "success") || checks?.status === "failed";
581 const requiredFailed = requiredChecks.some((check) => check.state === "failure") || checks?.status === "failed";
582 // Pull requests for other issues changing the same files will conflict;
583 // ones for the same issue are alternatives, and expected to.
584 const collisions = overlaps.filter((other) => other.issue == null || other.issue !== pull.issue);
585 const review = {
586 changesUrl: here + "?tab=changes",
587 // Nobody reviews their own pull request, nor one g1t made for them.
588 canJudge: active && viewer != null && viewer.id !== workOwner(pull).id,
589 };
590 // Everyone whose review was asked for, then anyone who reviewed unasked.
591 const reviewerNames = [
592 ...new Set([...pull.reviewers, ...reviews.map(({ reviewer }) => reviewer)]),
593 ];
594 // A catch-up: the click shows at once; the answer says whether it is
595 // done already or a sandbox is on it.
596 const catchUpPending = usePending({ action: "update" });
597 const catchUp = actionData?.action === "update" ? actionData : null;
598 const caughtUp = catchUp && "updated" in catchUp ? catchUp.updated : null;
599 const agentCatchUp = catchUp && "agent" in catchUp ? catchUp.agent : null;
600 // Pushed already: followed until the pull request's head is the merge,
601 // so its checks show starting again, for a minute at most.
602 const settling =
603 caughtUp != null && !caughtUp.already && pull.headCommit !== caughtUp.commit && Date.now() - caughtUp.at < 60_000;
604 // Followed until it is pushed, or for so long, never longer.
605 const catchingUp =
606 agentCatchUp != null && behind && Date.now() - agentCatchUp.startedAt < CATCH_UP_TIMEOUT_MS + REFRESH_MS;
607 // g1t is taking a step of its own accord, so the page will change.
608 const moving =
609 lifecycle != null && lifecycle.stage !== "ready" && lifecycle.stage !== "needs_you";
610 // Whether it merges cleanly is being worked out, so the box will change.
611 const probing = active && mergeable === "checking";
612 const conflicting = active && mergeable === "conflicting";
613 useRefreshWhile(working || checking || reviewPending || catchingUp || settling || moving || landing || probing);
614 // Why the merge button cannot be pressed, if it cannot.
615 const mergeBlocked = conflicting
616 ? "Resolve the conflicts first."
617 : probing
618 ? "Waiting to find out whether it merges cleanly."
619 : behind && requireUpToDate
620 ? `This repository requires it to be up to date with ${defaultBranch} first.`
621 : unchecked && !canIgnoreChecks
622 ? `The checks ${defaultBranch} requires have to pass first.`
623 : null;
624
625 return (
626 // The changes get the whole width; people and settings are a tab away.
627 <div>
628 {/* The title and the tabs run the full width; what is happening on
629 the pull request sits at the top of Conversation. */}
630 <header>
631 <h2 className="text-2xl font-semibold tracking-tight text-balance">
632 {pull.title} <span className="font-normal text-faint">#{pull.number}</span>
633 </h2>
634 <div className="mt-3 flex flex-wrap items-center gap-x-3 gap-y-2 text-sm text-muted">
635 <PullState status={pull.status} />
636 <span className="flex items-center gap-2">
637 <Avatar
638 name={(pull.status === "merged" && pull.mergedBy) || opener.name}
639 size={18}
640 />
641 <span>
642 <PersonLink
643 name={(pull.status === "merged" && pull.mergedBy) || opener.name}
644 className="font-medium text-fg hover:underline"
645 />{" "}
646 {pull.status === "merged" ? "merged" : "wants to merge"}
647 {pull.branch && (
648 <>
649 {" "}
650 <span className="font-mono text-fg">{pull.branch}</span>
651 </>
652 )}{" "}
653 into <span className="font-mono text-fg">{defaultBranch}</span>
654 </span>
655 </span>
656 {opener.requestedBy && (
657 <span className="text-xs">
658 requested by{" "}
659 <PersonLink name={opener.requestedBy} className="font-medium text-fg-soft hover:underline" />
660 </span>
661 )}
662 {/* A pull request from a branch was made by its author, not an agent;
663 one g1t made already says so. */}
664 {!pull.branch && !opener.requestedBy && (
665 <span className="flex items-center gap-1.5 font-mono text-xs">
666 <Bot size={14} />
667 {pull.agent}
668 {pull.runtime === "hosted" && <span className="text-faint">on g1t</span>}
669 </span>
670 )}
671 </div>
672
673 {reviews.length > 0 && (
674 <p className="mt-3 flex flex-wrap items-center gap-x-4 gap-y-1 text-sm">
675 {reviews.map(({ reviewer, verdict }) => (
676 <span
677 key={reviewer}
678 className={`flex items-center gap-1.5 ${
679 verdict === "approve" ? "text-accent" : "text-danger"
680 }`}
681 >
682 {verdict === "approve" ? <CircleCheck size={15} /> : <CircleSlash size={15} />}
683 {verdict === "approve" ? "Approved by" : "Changes requested by"}{" "}
684 <span className="font-medium">{reviewer}</span>
685 </span>
686 ))}
687 </p>
688 )}
689
690 <nav className="mt-6 flex items-end gap-1 overflow-x-auto overflow-y-hidden border-b border-line [scrollbar-width:none] [&::-webkit-scrollbar]:hidden">
691 <TabLink to={here} active={tab === "conversation"}>
692 <MessageSquare size={15} />
693 Conversation
694 <TabCount n={comments.length} />
695 </TabLink>
696 <TabLink to={here + "?tab=session"} active={tab === "session"}>
697 <MessagesSquare size={15} />
698 Session
699 </TabLink>
700 <TabLink to={here + "?tab=changes"} active={tab === "changes"}>
701 <FileDiff size={15} />
702 Files changed
703 <TabCount n={pull.files.length} />
704 </TabLink>
705 {pull.files.length > 0 && (
706 <span className="ml-auto hidden pb-2.5 font-mono text-xs sm:inline">
707 <span className="text-accent">+{pull.files.reduce((sum, file) => sum + file.additions, 0).toLocaleString("en-US")}</span>{" "}
708 <span className="text-danger">−{pull.files.reduce((sum, file) => sum + file.deletions, 0).toLocaleString("en-US")}</span>
709 </span>
710 )}
711 </nav>
712 </header>
713 <div className={`mt-6 grid gap-8 ${tab === "changes" ? "" : "lg:grid-cols-[1fr_19rem]"}`}>
714 <div className="min-w-0">
715 {/* What is happening on it now: its stage, its agent, what people told
716 the agent, and what else touches the same files. On the conversation,
717 so the tabs sit right under the title. */}
718 {tab === "conversation" && (
719 <div>
720 {issue && (
721 <Link
722 to={`${base}/issues/${issue.number}`}
723 className="mt-4 flex items-center gap-2.5 rounded-xl border border-line bg-surface px-4 py-2.5 text-sm transition-colors hover:border-line-strong"
724 >
725 <IssueIcon issue={issue} />
726 <span className="text-muted">
727 {pull.status === "merged" && issue.resolvedBy === pull.number
728 ? "Resolved"
729 : "For issue"}
730 </span>
731 <span className="truncate font-medium">{issue.title}</span>
732 <span className="text-faint">#{issue.number}</span>
733 {issue.pullCount > 1 && (
734 <span className="ml-auto shrink-0 text-xs text-faint">
735 1 of {issue.pullCount} pull requests
736 </span>
737 )}
738 </Link>
739 )}
740 {pull.status === "merged" && (
741 <p className="mt-4 flex items-center gap-2.5 rounded-xl border border-merged/40 bg-merged/5 px-4 py-2.5 text-sm">
742 <GitMerge size={16} className="shrink-0 text-merged" />
743 <span>
744 Merged into <span className="font-mono">{defaultBranch}</span> by{" "}
745 <span className="font-medium">{pull.mergedBy}</span>{" "}
746 {/* Not an account: the repository's settings said to merge it. */}
747 {pull.mergedBy === "g1t" && "automatically, once it was ready, "}
748 {pull.mergedAt && <TimeAgo at={pull.mergedAt} />}
749 {pull.headCommit && (
750 <span className="font-mono text-muted"> · {pull.headCommit.slice(0, 7)}</span>
751 )}
752 </span>
753 </p>
754 )}
755 {pull.supersededBy != null && (
756 <p className="mt-4 rounded-xl border border-line bg-surface px-4 py-2.5 text-sm text-muted">
757 Closed because{" "}
758 <Link
759 to={`${base}/pull/${pull.supersededBy}`}
760 className="font-medium text-fg hover:underline"
761 >
762 #{pull.supersededBy}
763 </Link>{" "}
764 was merged for this issue instead.
765 </p>
766 )}
767 {lifecycle && <LifecyclePanel lifecycle={lifecycle} />}
768 {/* The agent on it: who, doing what this minute, for how long, at what cost. */}
769 <AgentPanel
770 owner={params.owner}
771 repo={params.repo}
772 number={pull.number}
773 stage={lifecycle?.stage ?? null}
774 confidence={pull.confidence ?? null}
775 />
776
777 {/* Steering: while its agent works, people can tell it things. */}
778 {canRun &&
779 pull.runtime === "hosted" &&
780 (working || ["working", "revising", "catching_up", "answering"].includes(lifecycle?.stage ?? "")) && (
781 // Keyed by the messages so the box empties once one shows below.
782 <Form method="post" className="mt-4 rounded-2xl bg-surface p-4 ring-1 ring-merged/30" key={messages.length}>
783 <p className="flex items-center gap-2 text-sm font-medium">
784 <Sparkles size={15} className="text-merged" />
785 Message the agent
786 </p>
787 <p className="mt-1 text-xs text-muted">
788 A correction, a hint, a change of plan. It reads it at its next step, without
789 starting over.
790 </p>
791 <div className="mt-3 flex gap-2">
792 <input type="hidden" name="action" value="message" />
793 <input
794 name="body"
795 required
796 autoComplete="off"
797 data-1p-ignore
798 placeholder="Keep the old flag working too…"
799 className="h-9 min-w-0 grow rounded-md bg-bg px-3 text-sm ring-1 ring-line outline-none placeholder:text-faint focus:ring-merged/60"
800 />
801 <SubmitButton match={{ action: "message" }} pending="Sending…">
802 Send
803 </SubmitButton>
804 </div>
805 </Form>
806 )}
807 {messages.length > 0 && (
808 <ul className="mt-3 space-y-1.5">
809 {messages.map((message) => (
810 <li key={message.id} className="flex items-start gap-2 text-sm">
811 <Avatar name={message.author} size={18} />
812 <span className="min-w-0 grow">
813 <span className="font-medium">
814 {message.fromNumber != null ? `The agent on #${message.fromNumber}` : message.author}
815 </span>{" "}
816 <span className="text-muted">
817 {message.kind === "question"
818 ? "asked:"
819 : message.kind === "handoff"
820 ? "handed over:"
821 : message.kind === "answer"
822 ? "answered:"
823 : "to the agent:"}
824 </span>{" "}
825 {message.body}
826 {message.answer && (
827 <span className="mt-1 block border-l-2 border-merged/40 pl-2 text-muted">
828 {message.declined ? "Declined: " : "Answer: "}
829 {message.answer}
830 </span>
831 )}
832 </span>
833 <span className={`shrink-0 text-xs ${message.deliveredAt ? "text-accent" : "text-faint"}`}>
834 {message.deliveredAt ? "read by the agent" : "waiting for its next step"}
835 </span>
836 </li>
837 ))}
838 </ul>
839 )}
840 {collisions.length > 0 && active && (
841 <div className="mt-4 rounded-xl border border-line bg-surface px-4 py-3 text-sm">
842 <p className="flex items-center gap-2.5 font-medium">
843 <Radar size={16} className="shrink-0 text-info" />
844 Other work is changing the same files
845 </p>
846 <ul className="mt-2 space-y-1.5">
847 {collisions.map((other) => (
848 <li key={other.number} className="flex flex-wrap items-baseline gap-x-2 text-muted">
849 <Link
850 to={`${base}/pull/${other.number}`}
851 className="font-medium text-fg hover:underline"
852 >
853 {other.title} <span className="font-normal text-faint">#{other.number}</span>
854 </Link>
855 <span className="font-mono text-xs">{other.paths.join(", ")}</span>
856 </li>
857 ))}
858 </ul>
859 <p className="mt-2 text-xs text-faint">
860 Whichever merges second will have to catch up, and may conflict.
861 </p>
862 </div>
863 )}
864 </div>
865 )}
866 <div className="mt-5">
867 {comparison ? (
868 <DiffView
869 comparison={comparison}
870 review={{
871 comments: comments.filter((comment) => comment.path),
872 canComment: Boolean(viewer),
873 }}
874 />
875 ) : tab === "session" ? (
876 session.length === 0 ? (
877 <EmptyState title="Nothing recorded yet">
878 The agent's prompts, reasoning and tool calls appear here as it
879 works.
880 </EmptyState>
881 ) : (
882 <ol className="relative space-y-5 before:absolute before:top-2 before:bottom-2 before:left-3.25 before:w-px before:bg-line">
883 {session.map((entry) => (
884 <Entry key={entry.seq} entry={entry} agent={pull.agent} />
885 ))}
886 </ol>
887 )
888 ) : (
889 <div className="space-y-4">
890 <TimelineItem
891 author={opener.name}
892 at={pull.createdAt}
893 action={
894 <span>
895 opened this pull request
896 {opener.requestedBy ? (
897 <>
898 {" "}
899 for{" "}
900 <PersonLink name={opener.requestedBy} className="font-medium text-fg-soft hover:underline" />
901 </>
902 ) : !pull.branch && (
903 <>
904 {" "}
905 with <span className="font-mono text-xs">{pull.agent}</span>
906 </>
907 )}
908 </span>
909 }
910 >
911 {pull.body ? (
912 <Markdown source={pull.body} repo={{ namespace: params.owner, name: params.repo }} />
913 ) : (
914 <p className="text-sm text-muted">
915 {working
916 ? "No description yet. It is written when the pull request is marked ready for review."
917 : "No description."}
918 </p>
919 )}
920 {canManage && pull.status === "open" && (
921 <details className="mt-3 border-t border-line pt-3 text-sm">
922 <summary className="cursor-pointer text-xs text-faint hover:text-fg">
923 Edit description
924 </summary>
925 <Form method="post" className="mt-3 space-y-2">
926 <input type="hidden" name="action" value="describe" />
927 <Textarea
928 name="summary"
929 rows={6}
930 placeholder="What changed and why"
931 defaultValue={pull.body ?? ""}
932 />
933 <SubmitButton match={{ action: "describe" }} pending="Saving…">
934 Save
935 </SubmitButton>
936 </Form>
937 </details>
938 )}
939 </TimelineItem>
940
941 <CommentList comments={comments} review={review} base={base} />
942
943 {(preview || build) && <DeploymentCard preview={preview} build={build} stacked={stacked} base={base} />}
944
945 {pull.status === "draft" && (
946 <StatusBox>
947 <StatusRow icon={<Loader size={16} className="text-faint" />} title="This is a draft">
948 It is still being worked on. It can be reviewed and merged once it is
949 marked ready.
950 </StatusRow>
951 {canManage && (
952 <Form method="post" className="space-y-2 px-4 py-3">
953 <input type="hidden" name="action" value="ready" />
954 <Textarea name="summary" rows={3} placeholder="What changed and why" />
955 <SubmitButton match={{ action: "ready" }} pending="Marking ready…">
956 Mark ready for review
957 </SubmitButton>
958 </Form>
959 )}
960 </StatusBox>
961 )}
962
963 {pull.status === "open" && (
964 <StatusBox>
965 {/* Checks by status at once; job by job when the runs are read. */}
966 <Suspense fallback={checksSection({})}>
967 <Await resolve={workflowJobs}>{checksSection}</Await>
968 </Suspense>
969 {noChecks && <AddCiPrompt owner={params.owner} repo={params.repo} canAdd={canAddCi} compact />}
970 <StatusRow
971 icon={
972 reviews.some(({ verdict }) => verdict === "request_changes") ? (
973 <CircleSlash size={16} className="text-danger" />
974 ) : reviews.length > 0 ? (
975 <CircleCheck size={16} className="text-accent" />
976 ) : (
977 <MessageSquare size={16} className="text-faint" />
978 )
979 }
980 title={
981 reviews.length === 0
982 ? "No reviews yet"
983 : reviews
984 .map(
985 ({ reviewer, verdict }) =>
986 `${verdict === "approve" ? "Approved by" : "Changes requested by"} ${reviewer}`,
987 )
988 .join(" · ")
989 }
990 >
991 {reviewPending && "g1t is reviewing it now. "}
992 {requiredApprovals > 0 &&
993 `This repository requires ${requiredApprovals} approving ${
994 requiredApprovals === 1 ? "review" : "reviews"
995 } before merging.`}
996 </StatusRow>
997 {landing ? (
998 <StatusRow
999 icon={<Loader size={16} className="animate-spin text-accent" />}
1000 title="Merging"
1001 >
1002 {defaultBranch} has moved, so g1t is bringing this up to date first. It
1003 lands as soon as that is done. Watch it in the Session tab.
1004 </StatusRow>
1005 ) : agentCatchUp && behind ? (
1006 <CatchUpProgress
1007 owner={params.owner}
1008 repo={params.repo}
1009 number={pull.number}
1010 defaultBranch={defaultBranch}
1011 behind={behind}
1012 update={agentCatchUp.update}
1013 startedAt={agentCatchUp.startedAt}
1014 retrying={catchUpPending}
1015 />
1016 ) : conflicting ? (
1017 <ConflictsSection
1018 conflicts={conflicts}
1019 pull={pull}
1020 owner={params.owner}
1021 repo={params.repo}
1022 defaultBranch={defaultBranch}
1023 changesUrl={here + "?tab=changes"}
1024 canResolve={canUpdate && agentsEnabled}
1025 resolving={catchUpPending}
1026 error={catchUp && "error" in catchUp ? catchUp.error : null}
1027 />
1028 ) : probing ? (
1029 <MergeabilityRow mergeable={mergeable} defaultBranch={defaultBranch} />
1030 ) : behind ? (
1031 <StatusRow
1032 icon={<GitPullRequestArrow size={16} className="text-info" />}
1033 title={`${defaultBranch} has moved since this was made`}
1034 >
1035 {mergeable === "clean" && "It has no conflicts with it. "}
1036 {requireUpToDate
1037 ? "This repository requires pull requests to be up to date, so it has to catch up before it can merge."
1038 : "That does not stop it merging: it is brought up to date as part of the merge."}
1039 {canUpdate && (
1040 <Form method="post" className="mt-2">
1041 <input type="hidden" name="action" value="update" />
1042 <SubmitButton variant="quiet" match={{ action: "update" }} pending={`Merging ${defaultBranch} in…`}>
1043 Catch up with {defaultBranch} now
1044 </SubmitButton>
1045 </Form>
1046 )}
1047 {catchUp && "error" in catchUp && <ErrorText>{catchUp.error}</ErrorText>}
1048 </StatusRow>
1049 ) : (
1050 (pull.headCommit || (catchUp && "error" in catchUp)) && (
1051 <StatusRow
1052 icon={<CircleCheck size={16} className="text-accent" />}
1053 title={
1054 (caughtUp && !caughtUp.already) || agentCatchUp
1055 ? `Brought up to date with ${defaultBranch}`
1056 : `Up to date with ${defaultBranch}`
1057 }
1058 >
1059 {caughtUp && !caughtUp.already && (
1060 <>
1061 Merged <span className="font-mono">{defaultBranch}</span> in as{" "}
1062 <span className="font-mono text-fg">{caughtUp.commit.slice(0, 7)}</span>. Its checks run
1063 again on the new commit.
1064 </>
1065 )}
1066 {agentCatchUp && "g1t merged it in and pushed the result. Its checks run again on the new commit."}
1067 {/* A catch-up refused or failed after the pull request stopped being behind. */}
1068 {catchUp && "error" in catchUp && <ErrorText>{catchUp.error}</ErrorText>}
1069 </StatusRow>
1070 )
1071 )}
1072 {stalled && !lifecycle && (
1073 <StatusRow icon={<Hand size={16} className="text-warn" />} title="Needs you">
1074 {stalled}
1075 </StatusRow>
1076 )}
1077 {canMerge && lifecycle?.stage === "queued" && (
1078 <Form method="post" className="flex flex-wrap items-center gap-3 px-4 py-3">
1079 <ButtonLink to={`${base}/queue`}>
1080 <Layers size={15} />
1081 See the queue
1082 </ButtonLink>
1083 <SubmitButton variant="quiet" name="action" value="unqueue" pending="Removing…">
1084 Remove from the queue
1085 </SubmitButton>
1086 </Form>
1087 )}
1088 {canMerge && !landing && lifecycle?.stage !== "queued" && (
1089 <Form method="post" className="space-y-3 px-4 py-3">
1090 {issue?.state === "open" && (
1091 <CheckboxOption
1092 name="keepIssueOpen"
1093 label={`Keep #${issue.number} open. This is only part of the work.`}
1094 labelClassName="text-xs text-muted"
1095 />
1096 )}
1097 {unchecked && canIgnoreChecks && (
1098 <CheckboxOption
1099 name="ignoreChecks"
1100 label={`Bypass the required checks: merge although ${requiredFailed ? "one failed" : "they have not all passed"}.`}
1101 labelClassName="text-xs text-muted"
1102 />
1103 )}
1104 <div className="flex flex-wrap items-center gap-3">
1105 <SubmitButton
1106 variant="accent"
1107 name="action"
1108 value="merge"
1109 disabled={mergeBlocked != null}
1110 title={mergeBlocked ?? undefined}
1111 pending={mergeQueue ? "Adding to the queue…" : "Merging…"}
1112 >
1113 {mergeQueue ? <Layers size={15} /> : <GitMerge size={15} />}
1114 {mergeQueue ? "Add to the merge queue" : `Merge into ${defaultBranch}`}
1115 </SubmitButton>
1116 <span className={`text-xs ${mergeBlocked ? "text-danger" : "text-muted"}`}>
1117 {mergeBlocked ?? (mergeQueue
1118 ? `Tested together with everything ahead of it, then lands on ${defaultBranch}.`
1119 : issue?.state === "open"
1120 ? `Closes issue #${issue.number}, and any other pull requests still open for it.`
1121 : `Lands its commits on ${defaultBranch}.`)}
1122 </span>
1123 </div>
1124 {actionData?.action === "merge" && (
1125 <ErrorText>{actionData.error}</ErrorText>
1126 )}
1127 </Form>
1128 )}
1129 </StatusBox>
1130 )}
1131
1132 <CommentForm
1133 author={viewer?.username ?? null}
1134 resetKey={comments.length}
1135 review={review}
1136 />
1137 {canManage && active && (
1138 <Form method="post" className="flex justify-end">
1139 <SubmitButton variant="quiet" name="action" value="close" pending="Closing…">
1140 Close pull request
1141 </SubmitButton>
1142 </Form>
1143 )}
1144 {actionData &&
1145 !["merge", "comment", "stack", "rerun-failed", "rerun-workflow", "update", "agent-review", "reviewers", "assign"].includes(
1146 String(actionData.action),
1147 ) && <ErrorText>{actionData.error}</ErrorText>}
1148 </div>
1149 )}
1150 {actionData?.action === "comment" && (
1151 <div className="mt-2">
1152 <ErrorText>{actionData.error}</ErrorText>
1153 </div>
1154 )}
1155 </div>
1156 </div>
1157
1158 <aside className={tab === "changes" ? "hidden" : "space-y-6"}>
1159 {/* An open pull request shows its checks in full in the merge box. */}
1160 {pull.status !== "open" && <WorkflowStatuses statuses={statuses} />}
1161 {affects.length > 0 && (
1162 <section>
1163 <h3 className="flex items-center gap-1.5 text-sm font-medium">
1164 <Network size={14} className="text-faint" />
1165 Affects
1166 </h3>
1167 <p className="mt-1 text-xs text-muted">Projects that use this one, and so may feel this change:</p>
1168 <ul className="mt-2 space-y-1 text-sm">
1169 {affects.map((project) => (
1170 <li key={project.slug} className="flex items-center justify-between gap-2">
1171 <Link to={`/${params.owner}/${project.slug}`} className="hover:underline">
1172 {project.name}
1173 </Link>
1174 {project.as && <code className="font-mono text-xs text-faint">{project.as}</code>}
1175 </li>
1176 ))}
1177 </ul>
1178 {preview?.branch && canMerge && (
1179 <Form method="post" className="mt-3">
1180 <input type="hidden" name="action" value="stack" />
1181 <input type="hidden" name="branch" value={preview.branch} />
1182 <SubmitButton
1183 match={{ action: "stack" }}
1184 pending="Starting the builds…"
1185 className="flex w-full items-center justify-center gap-1.5 rounded-md border border-line px-3 py-1.5 text-xs text-muted transition-colors hover:border-line-strong hover:text-fg disabled:opacity-50"
1186 >
1187 Preview them against this change
1188 </SubmitButton>
1189 </Form>
1190 )}
1191 {actionData?.action === "stack" &&
1192 ("notice" in actionData ? (
1193 <p className="mt-2 text-xs text-accent">{String(actionData.notice)}</p>
1194 ) : (
1195 <ErrorText>{actionData.error}</ErrorText>
1196 ))}
1197 </section>
1198 )}
1199
1200 <section>
1201 <h3 className="text-sm font-medium">Reviewers</h3>
1202 <ul className="mt-2 space-y-1.5 text-sm">
1203 {reviewerNames.map((name) => {
1204 const verdict = reviews.find(({ reviewer }) => reviewer === name)?.verdict;
1205 const pending = name === "g1t" && reviewPending;
1206 return (
1207 <li key={name} className="flex items-center gap-2 px-1">
1208 {name === "g1t" ? (
1209 <Sparkles size={16} className="shrink-0 text-accent" />
1210 ) : (
1211 <Avatar name={name} size={20} />
1212 )}
1213 <span className="grow truncate font-mono text-xs">{name}</span>
1214 {pending ? (
1215 <span className="flex items-center gap-1.5 text-xs text-muted">
1216 <span className="size-1.5 animate-pulse rounded-full bg-accent" />
1217 Reviewing
1218 </span>
1219 ) : verdict === "approve" ? (
1220 <span className="flex items-center gap-1 text-xs text-accent">
1221 <CircleCheck size={13} /> Approved
1222 </span>
1223 ) : verdict === "request_changes" ? (
1224 <span className="flex items-center gap-1 text-xs text-danger">
1225 <CircleSlash size={13} /> Changes requested
1226 </span>
1227 ) : (
1228 <span className="text-xs text-faint">Review requested</span>
1229 )}
1230 </li>
1231 );
1232 })}
1233 {reviewerNames.length === 0 && (
1234 <li className="px-1 text-xs text-faint">No reviews requested yet.</li>
1235 )}
1236 </ul>
1237 {pull.status === "open" && canManage && (
1238 <div className="mt-3 space-y-2">
1239 {agentsEnabled && !reviewPending && (
1240 <Form method="post">
1241 <input type="hidden" name="action" value="agent-review" />
1242 {pull.reviewers.map((name) => (
1243 <input key={name} type="hidden" name="reviewer" value={name} />
1244 ))}
1245 <div className="*:w-full">
1246 <SubmitButton variant="quiet" match={{ action: "agent-review" }} pending="Asking g1t…">
1247 <Sparkles size={14} className="text-accent" />
1248 Request review from g1t
1249 </SubmitButton>
1250 </div>
1251 <ComputeNote note={loaderData.computeNote} />
1252 </Form>
1253 )}
1254 <details>
1255 <summary className="cursor-pointer text-xs text-faint hover:text-fg">
1256 Request review from people
1257 </summary>
1258 <Form method="post" className="mt-2 space-y-2" key={pull.reviewers.join()}>
1259 <input type="hidden" name="action" value="reviewers" />
1260 {pull.reviewers.includes("g1t") && (
1261 <input type="hidden" name="reviewer" value="g1t" />
1262 )}
1263 <PeoplePicker
1264 name="reviewer"
1265 members={members.filter((name) => name !== workOwner(pull).username)}
1266 chosen={pull.reviewers.filter((name) => name !== "g1t")}
1267 />
1268 <SubmitButton variant="quiet" match={{ action: "reviewers" }} pending="Saving…">
1269 Save reviewers
1270 </SubmitButton>
1271 </Form>
1272 </details>
1273 </div>
1274 )}
1275 {["agent-review", "reviewers"].includes(String(actionData?.action)) && (
1276 <ErrorText>{actionData?.error}</ErrorText>
1277 )}
1278 </section>
1279
1280 <section>
1281 <h3 className="text-sm font-medium">Assignees</h3>
1282 <ul className="mt-2 space-y-1.5 text-sm">
1283 {pull.assignees.map((name) => (
1284 <li key={name} className="flex items-center gap-2 px-1">
1285 <Avatar name={name} size={20} />
1286 <span className="grow truncate font-mono text-xs">{name}</span>
1287 </li>
1288 ))}
1289 {pull.assignees.length === 0 && (
1290 <li className="px-1 text-xs text-faint">No one yet.</li>
1291 )}
1292 </ul>
1293 {viewer && canManage && active && (
1294 <div className="mt-3 space-y-2">
1295 {!pull.assignees.includes(viewer.username) && (
1296 <Form method="post">
1297 <input type="hidden" name="action" value="assign" />
1298 {pull.assignees.map((name) => (
1299 <input key={name} type="hidden" name="assignee" value={name} />
1300 ))}
1301 <input type="hidden" name="assignee" value={viewer.username} />
1302 <div className="*:w-full">
1303 <SubmitButton variant="quiet" name="who" value="self" pending="Assigning…">
1304 Assign yourself
1305 </SubmitButton>
1306 </div>
1307 </Form>
1308 )}
1309 <details>
1310 <summary className="cursor-pointer text-xs text-faint hover:text-fg">
1311 Assign people
1312 </summary>
1313 <Form method="post" className="mt-2 space-y-2" key={pull.assignees.join()}>
1314 <input type="hidden" name="action" value="assign" />
1315 <PeoplePicker name="assignee" members={members} chosen={pull.assignees} />
1316 <SubmitButton variant="quiet" name="who" value="picked" pending="Saving…">
1317 Save assignees
1318 </SubmitButton>
1319 </Form>
1320 </details>
1321 </div>
1322 )}
1323 {actionData?.action === "assign" && <ErrorText>{actionData.error}</ErrorText>}
1324 </section>
1325
1326 <section>
1327 <h3 className="text-sm font-medium">Working copy</h3>
1328 {pull.branch ? (
1329 <>
1330 <p className="mt-1 text-xs text-muted">
1331 <GitBranch size={13} className="mr-1 inline align-[-2px]" />
1332 Branch <span className="font-mono text-fg">{pull.branch}</span> of this
1333 repository. Pushes to it show up here.
1334 </p>
1335 <div className="mt-2">
1336 <CopyLine text={`git clone -b ${pull.branch} ${remote}`} />
1337 </div>
1338 </>
1339 ) : (
1340 <>
1341 <p className="mt-1 text-xs text-muted">
1342 This fork belongs to the pull request. Pushes to it show up here.
1343 </p>
1344 <div className="mt-2">
1345 <CopyLine text={`git clone ${remote}`} />
1346 </div>
1347 </>
1348 )}
1349 <p className="mt-3 flex items-center gap-1.5 font-mono text-xs text-faint">
1350 <GitCommitHorizontal size={13} />
1351 {pull.headCommit?.slice(0, 12) ?? "no commits pushed yet"}
1352 </p>
1353 </section>
1354 {loaderData.viewer && (
1355 <SubscriptionBox action={`${base}/notifications`} number={pull.number} kind="pull" subscription={loaderData.subscription} />
1356 )}
1357 </aside>
1358 </div>
1359 </div>
1360 );
1361}
1362
1363/** Where the pull request's change is live, as GitHub shows a deployment. */
1364function DeploymentCard({
1365 preview,
1366 build,
1367 stacked,
1368 base,
1369}: {
1370 preview: LiveApp | null;
1371 build: Deployment | null;
1372 stacked: Promise<Stacked[]>;
1373 base: string;
1374}) {
1375 const building = build?.status === "queued" || build?.status === "building";
1376 const failed = build?.status === "failed";
1377 return (
1378 <section className="ml-12 overflow-hidden rounded-xl border border-line bg-surface">
1379 <div className="flex flex-wrap items-center gap-3 px-4 py-3">
1380 <span
1381 className={`flex size-8 shrink-0 items-center justify-center rounded-full ring-1 ${
1382 failed ? "text-danger ring-danger/40" : building ? "text-warn ring-warn/40" : "text-accent ring-accent/40"
1383 }`}
1384 >
1385 {building ? <Loader size={15} className="animate-spin" /> : <Rocket size={15} />}
1386 </span>
1387 <div className="min-w-0 grow">
1388 <p className="text-sm font-medium">
1389 {building
1390 ? preview
1391 ? "Deploying the latest push. The last preview is still live."
1392 : "Deploying a preview"
1393 : failed
1394 ? "The preview failed to deploy"
1395 : "This branch is live"}
1396 </p>
1397 {preview ? (
1398 <a href={preview.url} className="mt-0.5 block truncate font-mono text-xs text-muted hover:text-accent">
1399 {preview.url.replace(/^https?:[/][/]/, "")}
1400 </a>
1401 ) : (
1402 build?.error && <p className="mt-0.5 truncate text-xs text-muted">{build.error}</p>
1403 )}
1404 </div>
1405 <div className="flex shrink-0 items-center gap-2">
1406 {build && (
1407 <Link to={`${base}/deployments/${build.id}`} className="text-xs text-muted hover:text-fg">
1408 {failed ? "See why" : "Build log"}
1409 </Link>
1410 )}
1411 {preview && (
1412 <a
1413 href={preview.url}
1414 className="inline-flex items-center gap-1.5 rounded-md bg-accent px-3 py-1.5 text-xs font-medium text-bg hover:opacity-90"
1415 >
1416 Visit preview
1417 <ArrowUpRight size={13} />
1418 </a>
1419 )}
1420 </div>
1421 </div>
1422 {preview && (
1423 <p className="border-t border-line px-4 py-2 text-xs text-faint">
1424 <span className="font-mono">{preview.commit.slice(0, 7)}</span> · deployed <TimeAgo at={preview.deployedAt} />
1425 {preview.branch && ` · from ${preview.branch}`}
1426 </p>
1427 )}
1428 {/* Read after the page: the card's own part shows at once. */}
1429 <Suspense fallback={null}>
1430 <Await resolve={stacked}>
1431 {(stacked) =>
1432 stacked.length > 0 && (
1433 <div className="border-t border-line px-4 py-2.5">
1434 <p className="text-xs text-muted">Built against this change:</p>
1435 <ul className="mt-1.5 space-y-1">
1436 {stacked.map((entry) => (
1437 <li key={entry.slug} className="flex items-center gap-2 text-xs">
1438 <span className="font-medium">{entry.name}</span>
1439 <a href={entry.url} className="truncate font-mono text-muted hover:text-accent">
1440 {entry.url.replace(/^https?:[/][/]/, "")}
1441 </a>
1442 </li>
1443 ))}
1444 </ul>
1445 </div>
1446 )
1447 }
1448 </Await>
1449 </Suspense>
1450 </section>
1451 );
1452}