Check if a user follows another user

Script github Verified

by hugo697 ยท 10/25/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 366 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Check if a user follows another user
6
 *
7
 */
8
export async function main(
9
  auth: Github,
10
  username: string,
11
  target_user: string
12
) {
13
  const url = new URL(
14
    `https://api.github.com/users/${username}/following/${target_user}`
15
  );
16

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