0

Create Issue

by
Published today

Open an issue in a repository, optionally with assignees, labels and a milestone.

Script github Verified

The script

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

3
/**
4
 * Create Issue
5
 * Open an issue in a repository, optionally with assignees, labels and a milestone.
6
 */
7
export async function main(
8
  auth: RT.Github,
9
  owner: string,
10
  repo: string,
11
  title: string,
12
  body: string | undefined,
13
  assignees: string[] | undefined,
14
  labels: string[] | undefined,
15
  milestone: number | undefined
16
) {
17
  const response = await fetch(
18
    `https://api.github.com/repos/${owner}/${repo}/issues`,
19
    {
20
      method: "POST",
21
      headers: {
22
        Authorization: `Bearer ${auth.token}`,
23
        "Content-Type": "application/json",
24
        Accept: "application/vnd.github+json",
25
        "X-GitHub-Api-Version": "2022-11-28",
26
      },
27
      body: JSON.stringify({ title, body, assignees, labels, milestone }),
28
    }
29
  )
30

31
  if (!response.ok) {
32
    throw new Error(`${response.status} ${await response.text()}`)
33
  }
34

35
  return await response.json()
36
}
37