Create a release

Users with push access to the repository can create a release.

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
 * Create a release
6
 * Users with push access to the repository can create a release.
7
 */
8
export async function main(
9
  auth: Github,
10
  owner: string,
11
  repo: string,
12
  body: {
13
    body?: string;
14
    discussion_category_name?: string;
15
    draft?: boolean;
16
    generate_release_notes?: boolean;
17
    make_latest?: "true" | "false" | "legacy";
18
    name?: string;
19
    prerelease?: boolean;
20
    tag_name: string;
21
    target_commitish?: string;
22
    [k: string]: unknown;
23
  }
24
) {
25
  const url = new URL(`https://api.github.com/repos/${owner}/${repo}/releases`);
26

27
  const response = await fetch(url, {
28
    method: "POST",
29
    headers: {
30
      "Content-Type": "application/json",
31
      Authorization: "Bearer " + auth.token,
32
    },
33
    body: JSON.stringify(body),
34
  });
35
  if (!response.ok) {
36
    const text = await response.text();
37
    throw new Error(`${response.status} ${text}`);
38
  }
39
  return await response.json();
40
}
41