Check if a user can be assigned to a issue

Checks if a user has permission to be assigned to a specific issue. If the `assignee` can be assigned to this issue, a `204` status code with no content is returned. Otherwise a `404` status code is returned.

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
 * Check if a user can be assigned to a issue
6
 * Checks if a user has permission to be assigned to a specific issue.
7

8
If the `assignee` can be assigned to this issue, a `204` status code with no content is returned.
9

10
Otherwise a `404` status code is returned.
11
 */
12
export async function main(
13
  auth: Github,
14
  owner: string,
15
  repo: string,
16
  issue_number: string,
17
  assignee: string
18
) {
19
  const url = new URL(
20
    `https://api.github.com/repos/${owner}/${repo}/issues/${issue_number}/assignees/${assignee}`
21
  );
22

23
  const response = await fetch(url, {
24
    method: "GET",
25
    headers: {
26
      Authorization: "Bearer " + auth.token,
27
    },
28
    body: undefined,
29
  });
30
  if (!response.ok) {
31
    const text = await response.text();
32
    throw new Error(`${response.status} ${text}`);
33
  }
34
  return await response.text();
35
}
36