| 1 | import { notFound } from "next/navigation"; |
| 2 | |
| 3 | import { |
| 4 | createServerClient, |
| 5 | getServerSession, |
| 6 | getViewerRole, |
| 7 | } from "@/lib/api/server"; |
| 8 | import { API_URL } |
| 9 | import type { PullRequestReview |
| 10 | import { atLeast } |
| 11 | |
| 12 | import { ReviewDiff } |
| 13 | |
| 14 | export default async function |
| 15 | params, |
| 16 | }: PageProps< |
| 17 | const { username, |
| 18 | |
| 19 | const [session, |
| 20 | getServerSession(), |
| 21 | createServerClient(), |
| 22 | getViewerRole(username, repo |
| 23 | ]); |
| 24 | const path = |
| 25 | const [summary, |
| 26 | client.GET("/api/repositories/{username}/{repo}/pulls/{number}/files |
| 27 | params: { path |
| 28 | }), |
| 29 | client.GET("/api/repositories/{username}/{repo}/pulls/{number} |
| 30 | params: { path |
| 31 | }), |
| 32 | client.GET("/api/repositories/{username}/{repo}/issues/{number}/timeline |
| 33 | params: { path |
| 34 | }), |
| 35 | session |
| 36 | ? client.GET( |
| 37 | "/api/repositories/{username}/{repo}/pulls/{number}/reviews/pending", |
| 38 | { params: { path |
| 39 | ) |
| 40 | : null, |
| 41 | ]); |
| 42 | |
| 43 | if (summary.response |
| 44 | if (!summary.data |
| 45 | throw new Error( |
| 46 | } |
| 47 | |
| 48 | const viewer = |
| 49 | return ( |
| 50 | <ReviewDiff |
| 51 | username={username} |
| 52 | repo={repo} |
| 53 | number={Number(number |
| 54 | viewer={viewer} |
| 55 | canModerate={atLeast(role |
| 56 | from={summary.data |
| 57 | to={summary.data |
| 58 | files={summary.data |
| 59 | patchUrl={`${API_URL |
| 60 | reviews={(timeline. |
| 61 | (item): item |
| 62 | )} |
| 63 | pending={pending?.data |
| 64 | canReview={viewer !== |
| 65 | isAuthor={viewer === |
| 66 | blobUrl={ |
| 67 | pull.data.head |
| 68 | `${API_URL}/api/repositories/${pull |
| 69 | } |
| 70 | /> |
| 71 | ); |
| 72 | } |