Update a release

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

Script github Verified

by hugo697 ยท 10/25/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 367 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Update a release
6
 * Users with push access to the repository can edit a release.
7
 */
8
export async function main(
9
  auth: Github,
10
  owner: string,
11
  repo: string,
12
  release_id: string,
13
  body: {
14
    body?: string;
15
    discussion_category_name?: string;
16
    draft?: 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(
26
    `https://api.github.com/repos/${owner}/${repo}/releases/${release_id}`
27
  );
28

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