List followers of the authenticated user
One script reply has been approved by the moderators Verified

Lists the people following the authenticated user.

Created by hugo697 819 days ago
Submitted by hugo697 Typescript (fetch-only)
Verified 259 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * List followers of the authenticated user
6
 * Lists the people following the authenticated user.
7
 */
8
export async function main(
9
  auth: Github,
10
  per_page: string | undefined,
11
  page: string | undefined
12
) {
13
  const url = new URL(`https://api.github.com/user/followers`);
14
  for (const [k, v] of [
15
    ["per_page", per_page],
16
    ["page", page],
17
  ]) {
18
    if (v !== undefined && v !== "") {
19
      url.searchParams.append(k, v);
20
    }
21
  }
22
  const response = await fetch(url, {
23
    method: "GET",
24
    headers: {
25
      Authorization: "Bearer " + auth.token,
26
    },
27
    body: undefined,
28
  });
29
  if (!response.ok) {
30
    const text = await response.text();
31
    throw new Error(`${response.status} ${text}`);
32
  }
33
  return await response.json();
34
}
35