g1t/apps/web/app/routes/repo/pulls.tsx
| 1 | import { Bot, GitBranch, Plus } from "lucide-react"; |
| 2 | import { Link } from "react-router"; |
| 3 | |
| 4 | import type { Route } from "./+types/pulls"; |
| 5 | import { page } from "../../lib/meta"; |
| 6 | import { ButtonLink, EmptyState, TimeAgo } from "../../components/ui"; |
| 7 | import { CheckBadge } from "../../components/checks"; |
| 8 | import { ChangeSize, PullIcon, StateTabs } from "../../components/work"; |
| 9 | import { work } from "../../lib/services.server"; |
| 10 | import { getViewer, unwrap } from "../../lib/session.server"; |
| 11 | |
| 12 | export function meta({ params, ...args }: Route.MetaArgs) { |
| 13 | return page(args, { title: `Pull requests · ${params.owner}/${params.repo} · g1t` }); |
| 14 | } |
| 15 | |
| 16 | export async function loader({ params, context, request }: Route.LoaderArgs) { |
| 17 | const path = { namespace: params.owner, name: params.repo }; |
| 18 | const state = |
| 19 | new URL(request.url).searchParams.get("state") === "closed" ? "closed" : "open"; |
| 20 | return { |
| 21 | pulls: unwrap(await work.listPulls(path, getViewer(context), state)), |
| 22 | state, |
| 23 | } as const; |
| 24 | } |
| 25 | |
| 26 | export default function Pulls({ loaderData, params }: Route.ComponentProps) { |
| 27 | const { pulls, state } = loaderData; |
| 28 | const base = `/${params.owner}/${params.repo}`; |
| 29 | return ( |
| 30 | <div> |
| 31 | <StateTabs |
| 32 | to={`${base}/pulls`} |
| 33 | state={state} |
| 34 | action={ |
| 35 | <ButtonLink to={`${base}/pulls/new`}> |
| 36 | <Plus size={15} /> |
| 37 | New pull request |
| 38 | </ButtonLink> |
| 39 | } |
| 40 | /> |
| 41 | <div className="mt-4"> |
| 42 | {pulls.length === 0 ? ( |
| 43 | <EmptyState |
| 44 | title={state === "open" ? "No open pull requests" : "No closed pull requests"} |
| 45 | > |
| 46 | A pull request proposes a change. Assign agents to an issue and |
| 47 | each opens one in its own fork, or push a branch and open one |
| 48 | yourself. |
| 49 | </EmptyState> |
| 50 | ) : ( |
| 51 | <ul className="divide-y divide-line overflow-hidden rounded-xl border border-line"> |
| 52 | {pulls.map((pull) => ( |
| 53 | <li key={pull.id}> |
| 54 | <Link |
| 55 | prefetch="intent" |
| 56 | to={`${base}/pull/${pull.number}`} |
| 57 | className="flex items-start gap-3 px-4 py-3 transition-colors hover:bg-surface" |
| 58 | > |
| 59 | <span className="mt-0.5"> |
| 60 | <PullIcon status={pull.status} /> |
| 61 | </span> |
| 62 | <span className="min-w-0 grow"> |
| 63 | <span className="flex items-center gap-2"> |
| 64 | <span className="truncate font-medium">{pull.title}</span> |
| 65 | {pull.status === "draft" && ( |
| 66 | <span className="shrink-0 rounded-full border border-line px-1.5 py-px text-[0.6875rem] text-faint"> |
| 67 | draft |
| 68 | </span> |
| 69 | )} |
| 70 | </span> |
| 71 | <span className="mt-0.5 block text-xs text-faint"> |
| 72 | #{pull.number} opened <TimeAgo at={pull.createdAt} /> by{" "} |
| 73 | {pull.author.username} |
| 74 | {pull.issue != null && <> · for #{pull.issue}</>} |
| 75 | {pull.supersededBy != null && <> · superseded by #{pull.supersededBy}</>} |
| 76 | </span> |
| 77 | </span> |
| 78 | <span className="mt-0.5 hidden sm:block"> |
| 79 | <ChangeSize files={pull.files} /> |
| 80 | </span> |
| 81 | <span className="mt-0.5"> |
| 82 | <CheckBadge status={pull.checkStatus} /> |
| 83 | </span> |
| 84 | <span className="mt-0.5 flex shrink-0 items-center gap-1 font-mono text-xs text-muted"> |
| 85 | {pull.branch ? <GitBranch size={13} /> : <Bot size={13} />} |
| 86 | {pull.branch ?? pull.agent} |
| 87 | </span> |
| 88 | </Link> |
| 89 | </li> |
| 90 | ))} |
| 91 | </ul> |
| 92 | )} |
| 93 | </div> |
| 94 | </div> |
| 95 | ); |
| 96 | } |