| 1 | "use server"; |
| 2 | |
| 3 | import { revalidatePath } from |
| 4 | import { cookies } |
| 5 | import { redirect } |
| 6 | import { createSafeActionClient } |
| 7 | import { z } |
| 8 | |
| 9 | import { fetchClient } |
| 10 | |
| 11 | import { createPullRequestSchema } |
| 12 | |
| 13 | const actionClient = createSafeActionClient |
| 14 | handleServerError: (error) |
| 15 | }); |
| 16 | |
| 17 | const target = z |
| 18 | username: z.string |
| 19 | repo: z.string |
| 20 | number: z.number |
| 21 | }); |
| 22 | |
| 23 | export const createPullRequest = |
| 24 | .inputSchema( |
| 25 | createPullRequestSchema.extend({ |
| 26 | ) |
| 27 | .action( |
| 28 | async ({ parsedInput |
| 29 | const { data, |
| 30 | "/api/repositories/{username}/{repo}/pulls", |
| 31 | { |
| 32 | params: { path: { |
| 33 | body: { title, |
| 34 | headers: { cookie: ( |
| 35 | }, |
| 36 | ); |
| 37 | |
| 38 | if (error) throw |
| 39 | |
| 40 | redirect(`/${username |
| 41 | }, |
| 42 | ); |
| 43 | |
| 44 | export const mergePullRequest = |
| 45 | .inputSchema(target.extend |
| 46 | .action(async ( |
| 47 | const { data, |
| 48 | "/api/repositories/{username}/{repo}/pulls/{number}/merge", |
| 49 | { |
| 50 | params: { path: { |
| 51 | body: { title |
| 52 | headers: { cookie: ( |
| 53 | }, |
| 54 | ); |
| 55 | |
| 56 | if (error) throw |
| 57 | |
| 58 | revalidatePath(`/${username |
| 59 | return data; |
| 60 | }); |
| 61 | |
| 62 | export const closePullRequest = |
| 63 | .inputSchema(target) |
| 64 | .action(async ( |
| 65 | const { error |
| 66 | "/api/repositories/{username}/{repo}/pulls/{number}/close", |
| 67 | { |
| 68 | params: { path: { |
| 69 | headers: { cookie: ( |
| 70 | }, |
| 71 | ); |
| 72 | |
| 73 | if (error) throw |
| 74 | |
| 75 | revalidatePath(`/${username |
| 76 | }); |
| 77 | |
| 78 | export const updatePullRequest = |
| 79 | .inputSchema( |
| 80 | target.extend({ |
| 81 | title: z |
| 82 | .string() |
| 83 | .trim() |
| 84 | .min(1, " |
| 85 | .max(200, " |
| 86 | .optional(), |
| 87 | body: z |
| 88 | .string() |
| 89 | .max(20000, " |
| 90 | .nullable() |
| 91 | .optional(), |
| 92 | }), |
| 93 | ) |
| 94 | .action(async ( |
| 95 | const { data, |
| 96 | "/api/repositories/{username}/{repo}/pulls/{number}", |
| 97 | { |
| 98 | params: { path: { |
| 99 | body: { title, |
| 100 | headers: { cookie: ( |
| 101 | }, |
| 102 | ); |
| 103 | |
| 104 | if (error) throw |
| 105 | |
| 106 | revalidatePath(`/${username |
| 107 | return data; |
| 108 | }); |