| 1 | "use server"; |
| 2 | |
| 3 | import { cookies } from |
| 4 | import { createSafeActionClient } |
| 5 | import { z } |
| 6 | |
| 7 | import { fetchClient } |
| 8 | import { webhookEvents } |
| 9 | |
| 10 | const actionClient = createSafeActionClient |
| 11 | handleServerError: (error) |
| 12 | }); |
| 13 | |
| 14 | const repositoryPath = z |
| 15 | const webhookPath = repositoryPath |
| 16 | const events = z |
| 17 | .array(z.enum |
| 18 | .min(1, " |
| 19 | |
| 20 | const headers = async |
| 21 | |
| 22 | export const createWebhook = |
| 23 | .inputSchema( |
| 24 | repositoryPath.extend({ |
| 25 | url: z.string |
| 26 | events, |
| 27 | }), |
| 28 | ) |
| 29 | .action(async ( |
| 30 | const { data, |
| 31 | "/api/repositories/{username}/{repo}/webhooks", |
| 32 | { |
| 33 | params: { path: { |
| 34 | body: { url, |
| 35 | headers: await headers |
| 36 | }, |
| 37 | ); |
| 38 | if (error) throw |
| 39 | return data; |
| 40 | }); |
| 41 | |
| 42 | export const updateWebhook = |
| 43 | .inputSchema( |
| 44 | webhookPath.extend({ |
| 45 | url: z.string |
| 46 | events: events.optional |
| 47 | active: z.boolean |
| 48 | }), |
| 49 | ) |
| 50 | .action(async ( |
| 51 | const { error |
| 52 | "/api/repositories/{username}/{repo}/webhooks/{webhookId}", |
| 53 | { |
| 54 | params: { path: { |
| 55 | body, |
| 56 | headers: await headers |
| 57 | }, |
| 58 | ); |
| 59 | if (error) throw |
| 60 | }); |
| 61 | |
| 62 | export const deleteWebhook = |
| 63 | .inputSchema(webhookPath) |
| 64 | .action(async ( |
| 65 | const { error |
| 66 | "/api/repositories/{username}/{repo}/webhooks/{webhookId}", |
| 67 | { |
| 68 | params: { path: { |
| 69 | headers: await headers |
| 70 | }, |
| 71 | ); |
| 72 | if (error) throw |
| 73 | }); |
| 74 | |
| 75 | export const pingWebhook = |
| 76 | .inputSchema(webhookPath) |
| 77 | .action(async ( |
| 78 | const { error |
| 79 | "/api/repositories/{username}/{repo}/webhooks/{webhookId}/pings", |
| 80 | { |
| 81 | params: { path: { |
| 82 | headers: await headers |
| 83 | }, |
| 84 | ); |
| 85 | if (error) throw |
| 86 | }); |
| 87 | |
| 88 | export const redeliverWebhook = |
| 89 | .inputSchema(webhookPath.extend |
| 90 | .action( |
| 91 | async ({ parsedInput |
| 92 | const { error |
| 93 | "/api/repositories/{username}/{repo}/webhooks/{webhookId}/deliveries/{deliveryId}/redeliveries", |
| 94 | { |
| 95 | params: { path: { |
| 96 | headers: await headers |
| 97 | }, |
| 98 | ); |
| 99 | if (error) throw |
| 100 | }, |
| 101 | ); |