0
Get the latest release
One script reply has been approved by the moderators Verified

View the latest published full release for the repository.

The latest release is the most recent non-prerelease, non-draft release, sorted by the created_at attribute. The created_at attribute is the date of the commit used for the release, and not the date when the release was drafted or published.

Created by hugo697 199 days ago Viewed 6138 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 199 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Get the latest release
6
 * View the latest published full release for the repository.
7

8
The latest release is the most recent non-prerelease, non-draft release, sorted by the `created_at` attribute. The `created_at` attribute is the date of the commit used for the release, and not the date when the release was drafted or published.
9
 */
10
export async function main(auth: Github, owner: string, repo: string) {
11
  const url = new URL(
12
    `https://api.github.com/repos/${owner}/${repo}/releases/latest`
13
  );
14

15
  const response = await fetch(url, {
16
    method: "GET",
17
    headers: {
18
      Authorization: "Bearer " + auth.token,
19
    },
20
    body: undefined,
21
  });
22
  if (!response.ok) {
23
    const text = await response.text();
24
    throw new Error(`${response.status} ${text}`);
25
  }
26
  return await response.json();
27
}
28