Delete a repository

Deleting a repository requires admin access. If OAuth is used, the `delete_repo` scope is required. If an organization owner has configured the organization to prevent members from deleting organization-owned repositories, you will get a `403 Forbidden` response.

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
 * Delete a repository
6
 * Deleting a repository requires admin access. If OAuth is used, the `delete_repo` scope is required.
7

8
If an organization owner has configured the organization to prevent members from deleting organization-owned
9
repositories, you will get a `403 Forbidden` response.
10
 */
11
export async function main(auth: Github, owner: string, repo: string) {
12
  const url = new URL(`https://api.github.com/repos/${owner}/${repo}`);
13

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