0

Add assignees to an issue

by
Published Oct 25, 2023

Adds up to 10 assignees to an issue. Users already assigned to an issue are not replaced.

Script github Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 398 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Add assignees to an issue
6
 * Adds up to 10 assignees to an issue. Users already assigned to an issue are not replaced.
7
 */
8
export async function main(
9
  auth: Github,
10
  owner: string,
11
  repo: string,
12
  issue_number: string,
13
  body: { assignees?: string[]; [k: string]: unknown }
14
) {
15
  const url = new URL(
16
    `https://api.github.com/repos/${owner}/${repo}/issues/${issue_number}/assignees`
17
  );
18

19
  const response = await fetch(url, {
20
    method: "POST",
21
    headers: {
22
      "Content-Type": "application/json",
23
      Authorization: "Bearer " + auth.token,
24
    },
25
    body: JSON.stringify(body),
26
  });
27
  if (!response.ok) {
28
    const text = await response.text();
29
    throw new Error(`${response.status} ${text}`);
30
  }
31
  return await response.json();
32
}
33