0
Get a webhook delivery for an organization webhook
One script reply has been approved by the moderators Verified

Returns a delivery for a webhook configured in an organization.

Created by hugo697 406 days ago Viewed 9016 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 406 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Get a webhook delivery for an organization webhook
6
 * Returns a delivery for a webhook configured in an organization.
7
 */
8
export async function main(
9
  auth: Github,
10
  org: string,
11
  hook_id: string,
12
  delivery_id: string
13
) {
14
  const url = new URL(
15
    `https://api.github.com/orgs/${org}/hooks/${hook_id}/deliveries/${delivery_id}`
16
  );
17

18
  const response = await fetch(url, {
19
    method: "GET",
20
    headers: {
21
      Authorization: "Bearer " + auth.token,
22
    },
23
    body: undefined,
24
  });
25
  if (!response.ok) {
26
    const text = await response.text();
27
    throw new Error(`${response.status} ${text}`);
28
  }
29
  return await response.json();
30
}
31