0
List public events for a network of repositories
One script reply has been approved by the moderators Verified
Created by hugo697 406 days ago Viewed 9050 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 406 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * List public events for a network of repositories
6
 *
7
 */
8
export async function main(
9
  auth: Github,
10
  owner: string,
11
  repo: string,
12
  per_page: string | undefined,
13
  page: string | undefined
14
) {
15
  const url = new URL(
16
    `https://api.github.com/networks/${owner}/${repo}/events`
17
  );
18
  for (const [k, v] of [
19
    ["per_page", per_page],
20
    ["page", page],
21
  ]) {
22
    if (v !== undefined && v !== "") {
23
      url.searchParams.append(k, v);
24
    }
25
  }
26
  const response = await fetch(url, {
27
    method: "GET",
28
    headers: {
29
      Authorization: "Bearer " + auth.token,
30
    },
31
    body: undefined,
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39