List user account issues assigned to the authenticated user

List issues across owned and member repositories assigned to the authenticated user.

Script github Verified

by hugo697 ยท 10/25/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 367 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * List user account issues assigned to the authenticated user
6
 * List issues across owned and member repositories assigned to the authenticated user.
7
 */
8
export async function main(
9
  auth: Github,
10
  filter:
11
    | "assigned"
12
    | "created"
13
    | "mentioned"
14
    | "subscribed"
15
    | "repos"
16
    | "all"
17
    | undefined,
18
  state: "open" | "closed" | "all" | undefined,
19
  labels: string | undefined,
20
  sort: "created" | "updated" | "comments" | undefined,
21
  direction: "asc" | "desc" | undefined,
22
  since: string | undefined,
23
  per_page: string | undefined,
24
  page: string | undefined
25
) {
26
  const url = new URL(`https://api.github.com/user/issues`);
27
  for (const [k, v] of [
28
    ["filter", filter],
29
    ["state", state],
30
    ["labels", labels],
31
    ["sort", sort],
32
    ["direction", direction],
33
    ["since", since],
34
    ["per_page", per_page],
35
    ["page", page],
36
  ]) {
37
    if (v !== undefined && v !== "") {
38
      url.searchParams.append(k, v);
39
    }
40
  }
41
  const response = await fetch(url, {
42
    method: "GET",
43
    headers: {
44
      Authorization: "Bearer " + auth.token,
45
    },
46
    body: undefined,
47
  });
48
  if (!response.ok) {
49
    const text = await response.text();
50
    throw new Error(`${response.status} ${text}`);
51
  }
52
  return await response.json();
53
}
54