//native
/**
* Update Issue
* Update an issue's title, body, state, assignees, labels or milestone. Only the fields you set change: empty text or an empty list keeps the current value. Assignees and labels you set replace the existing lists; turn on clear_assignees or clear_labels to remove them all. Turn on clear_milestone to remove the milestone.
*/
export async function main(
auth: RT.Github,
owner: string,
repo: string,
issue_number: number,
title: string | undefined,
body: string | undefined,
state: "open" | "closed" | undefined,
state_reason: "completed" | "not_planned" | "reopened" | undefined,
assignees: string[] | undefined,
labels: string[] | undefined,
milestone: number | undefined,
clear_assignees: boolean = false,
clear_labels: boolean = false,
clear_milestone: boolean = false
) {
const response = await fetch(
`https://api.github.com/repos/${owner}/${repo}/issues/${issue_number}`,
{
method: "PATCH",
headers: {
Authorization: `Bearer ${auth.token}`,
"Content-Type": "application/json",
Accept: "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28",
},
body: JSON.stringify({
title: title || undefined,
body: body || undefined,
state: state || undefined,
state_reason: state_reason || undefined,
assignees: clear_assignees
? []
: assignees?.length
? assignees
: undefined,
labels: clear_labels ? [] : labels?.length ? labels : undefined,
milestone: clear_milestone ? null : (milestone ?? undefined),
}),
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 20 days ago
//native
/**
* Update Issue
* Update an issue's title, body, state, assignees, labels or milestone. Only the fields you set change; assignees and labels replace the existing lists.
*/
export async function main(
auth: RT.Github,
owner: string,
repo: string,
issue_number: number,
title: string | undefined,
body: string | undefined,
state: "open" | "closed" | undefined,
state_reason: "completed" | "not_planned" | "reopened" | undefined,
assignees: string[] | undefined,
labels: string[] | undefined,
milestone: number | undefined
) {
const response = await fetch(
`https://api.github.com/repos/${owner}/${repo}/issues/${issue_number}`,
{
method: "PATCH",
headers: {
Authorization: `Bearer ${auth.token}`,
"Content-Type": "application/json",
Accept: "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28",
},
body: JSON.stringify({
title,
body,
state,
state_reason,
assignees,
labels,
milestone,
}),
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 21 days ago