Delete a repository

Deletes the repository. This is an irreversible operation. This does not affect its forks.

Script bitbucket Verified

by hugo697 ยท 10/24/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 375 days ago
1
type Bitbucket = {
2
  username: string;
3
  password: string;
4
};
5
/**
6
 * Delete a repository
7
 * Deletes the repository. This is an irreversible operation.
8

9
This does not affect its forks.
10
 */
11
export async function main(
12
  auth: Bitbucket,
13
  repo_slug: string,
14
  workspace: string,
15
  redirect_to: string | undefined
16
) {
17
  const url = new URL(
18
    `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}`
19
  );
20
  for (const [k, v] of [["redirect_to", redirect_to]]) {
21
    if (v !== undefined && v !== "") {
22
      url.searchParams.append(k, v);
23
    }
24
  }
25
  const response = await fetch(url, {
26
    method: "DELETE",
27
    headers: {
28
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
29
    },
30
    body: undefined,
31
  });
32
  if (!response.ok) {
33
    const text = await response.text();
34
    throw new Error(`${response.status} ${text}`);
35
  }
36
  return await response.text();
37
}
38