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