Update an issue

Issue owners and users with push access can edit an issue.

Script github Verified

by hugo697 ยท 10/25/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 366 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Update an issue
6
 * Issue owners and users with push access can edit an issue.
7
 */
8
export async function main(
9
  auth: Github,
10
  owner: string,
11
  repo: string,
12
  issue_number: string,
13
  body: {
14
    assignee?: string;
15
    assignees?: string[];
16
    body?: string;
17
    labels?: (
18
      | string
19
      | {
20
          color?: string;
21
          description?: string;
22
          id?: number;
23
          name?: string;
24
          [k: string]: unknown;
25
        }
26
    )[];
27
    milestone?: string | number;
28
    state?: "open" | "closed";
29
    state_reason?: "completed" | "not_planned" | "reopened";
30
    title?: string | number;
31
    [k: string]: unknown;
32
  }
33
) {
34
  const url = new URL(
35
    `https://api.github.com/repos/${owner}/${repo}/issues/${issue_number}`
36
  );
37

38
  const response = await fetch(url, {
39
    method: "PATCH",
40
    headers: {
41
      "Content-Type": "application/json",
42
      Authorization: "Bearer " + auth.token,
43
    },
44
    body: JSON.stringify(body),
45
  });
46
  if (!response.ok) {
47
    const text = await response.text();
48
    throw new Error(`${response.status} ${text}`);
49
  }
50
  return await response.json();
51
}
52