0

List issues assigned to the authenticated user

by
Published Oct 25, 2023

List issues assigned to the authenticated user across all visible repositories including owned repositories, member repositories, and organization repositories.

Script github Verified

The script

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