flagon-io/g1t

public

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

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

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