0

Update Issue

by
Published today

Update an issue's title, body, state, assignees, labels or milestone. Only the fields you set change; assignees and labels replace the existing lists.

Script github Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 1 hour ago
1
//native
2

3
/**
4
 * Update Issue
5
 * Update an issue's title, body, state, assignees, labels or milestone. Only the fields you set change; assignees and labels replace the existing lists.
6
 */
7
export async function main(
8
  auth: RT.Github,
9
  owner: string,
10
  repo: string,
11
  issue_number: number,
12
  title: string | undefined,
13
  body: string | undefined,
14
  state: "open" | "closed" | undefined,
15
  state_reason: "completed" | "not_planned" | "reopened" | undefined,
16
  assignees: string[] | undefined,
17
  labels: string[] | undefined,
18
  milestone: number | undefined
19
) {
20
  const response = await fetch(
21
    `https://api.github.com/repos/${owner}/${repo}/issues/${issue_number}`,
22
    {
23
      method: "PATCH",
24
      headers: {
25
        Authorization: `Bearer ${auth.token}`,
26
        "Content-Type": "application/json",
27
        Accept: "application/vnd.github+json",
28
        "X-GitHub-Api-Version": "2022-11-28",
29
      },
30
      body: JSON.stringify({
31
        title,
32
        body,
33
        state,
34
        state_reason,
35
        assignees,
36
        labels,
37
        milestone,
38
      }),
39
    }
40
  )
41

42
  if (!response.ok) {
43
    throw new Error(`${response.status} ${await response.text()}`)
44
  }
45

46
  return await response.json()
47
}
48