0

List organization issues assigned to the authenticated user

by
Published Oct 25, 2023

List issues in an organization assigned to the authenticated user.

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 organization issues assigned to the authenticated user
6
 * List issues in an organization assigned to the authenticated user.
7
 */
8
export async function main(
9
  auth: Github,
10
  org: string,
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
  per_page: string | undefined,
25
  page: string | undefined
26
) {
27
  const url = new URL(`https://api.github.com/orgs/${org}/issues`);
28
  for (const [k, v] of [
29
    ["filter", filter],
30
    ["state", state],
31
    ["labels", labels],
32
    ["sort", sort],
33
    ["direction", direction],
34
    ["since", since],
35
    ["per_page", per_page],
36
    ["page", page],
37
  ]) {
38
    if (v !== undefined && v !== "") {
39
      url.searchParams.append(k, v);
40
    }
41
  }
42
  const response = await fetch(url, {
43
    method: "GET",
44
    headers: {
45
      Authorization: "Bearer " + auth.token,
46
    },
47
    body: undefined,
48
  });
49
  if (!response.ok) {
50
    const text = await response.text();
51
    throw new Error(`${response.status} ${text}`);
52
  }
53
  return await response.json();
54
}
55