| 1 | import { atLeast } from "@ghost/permissions"; |
| 2 | import { GitBranch } |
| 3 | import type { Metadata |
| 4 | import Link from "next/link |
| 5 | import { notFound } |
| 6 | |
| 7 | import { Badge } |
| 8 | import { createServerClient } |
| 9 | |
| 10 | import { CreateBranchDialog } |
| 11 | import { DeleteBranchButton } |
| 12 | |
| 13 | export async function generateMetadata |
| 14 | params, |
| 15 | }: PageProps< |
| 16 | const { username, |
| 17 | return { title: |
| 18 | } |
| 19 | |
| 20 | export default async function |
| 21 | params, |
| 22 | }: PageProps< |
| 23 | const { username, |
| 24 | |
| 25 | const client = |
| 26 | const [repository, |
| 27 | client.GET("/api/repositories/{username}/{slug} |
| 28 | params: { path: { |
| 29 | }), |
| 30 | client.GET("/api/repositories/{username}/{slug}/branches |
| 31 | params: { path: { |
| 32 | }), |
| 33 | ]); |
| 34 | |
| 35 | if (branches.response |
| 36 | if (!branches.data |
| 37 | throw new Error( |
| 38 | } |
| 39 | const { defaultBranch |
| 40 | const canWrite = |
| 41 | |
| 42 | return ( |
| 43 | <div className="flex flex-col gap-4 |
| 44 | <div className="flex items-center gap-2 |
| 45 | <h2 className="text-lg font-semibold |
| 46 | {canWrite && defaultBranch |
| 47 | <CreateBranchDialog |
| 48 | username={username} |
| 49 | repo={repo} |
| 50 | branches={branches.data |
| 51 | defaultBranch={defaultBranch} |
| 52 | /> |
| 53 | )} |
| 54 | </div> |
| 55 | |
| 56 | {branches.data.branches |
| 57 | <div className="rounded-lg border py-16 text-center |
| 58 | <p className="font-medium |
| 59 | <p className="text-sm text-muted-foreground |
| 60 | Push one with <code>git push origin main</code>. |
| 61 | </p> |
| 62 | </div> |
| 63 | ) : ( |
| 64 | <ul className="divide-y rounded-lg border |
| 65 | {branches.data.branches |
| 66 | <li |
| 67 | key={branch} |
| 68 | className="flex items-center gap-3 px-4 py-3 text-sm" |
| 69 | > |
| 70 | <GitBranch className=" |
| 71 | <Link |
| 72 | href={`/${username |
| 73 | className="min-w-0 truncate font-medium hover:underline" |
| 74 | > |
| 75 | {branch} |
| 76 | </Link> |
| 77 | {branch === defaultBranch |
| 78 | <Badge variant=" |
| 79 | )} |
| 80 | {canWrite && branch |
| 81 | <div className="ml-auto |
| 82 | <DeleteBranchButton |
| 83 | username={username} |
| 84 | repo={repo} |
| 85 | branch={branch} |
| 86 | /> |
| 87 | </div> |
| 88 | )} |
| 89 | </li> |
| 90 | ))} |
| 91 | </ul> |
| 92 | )} |
| 93 | </div> |
| 94 | ); |
| 95 | } |