Create a tag object

Note that creating a tag object does not create the reference that makes a tag in Git.

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 tag object
6
 * Note that creating a tag object does not create the reference that makes a tag in Git.
7
 */
8
export async function main(
9
  auth: Github,
10
  owner: string,
11
  repo: string,
12
  body: {
13
    message: string;
14
    object: string;
15
    tag: string;
16
    tagger?: {
17
      date?: string;
18
      email: string;
19
      name: string;
20
      [k: string]: unknown;
21
    };
22
    type: "commit" | "tree" | "blob";
23
    [k: string]: unknown;
24
  }
25
) {
26
  const url = new URL(`https://api.github.com/repos/${owner}/${repo}/git/tags`);
27

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