List the people the authenticated user follows
One script reply has been approved by the moderators Verified

Lists the people who the authenticated user follows.

Created by hugo697 878 days ago
Submitted by hugo697 Typescript (fetch-only)
Verified 318 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * List the people the authenticated user follows
6
 * Lists the people who the authenticated user follows.
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/following`);
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