Delete a previous revision of a snippet

Deletes the snippet. Note that this only works for versioned URLs that point to the latest commit of the snippet. Pointing to an older commit results in a 405 status code. To delete a snippet, regardless of whether or not concurrent changes are being made to it, use `DELETE /snippets/{encoded_id}` instead.

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 previous revision of a snippet
7
 * Deletes the snippet.
8

9
Note that this only works for versioned URLs that point to the latest
10
commit of the snippet. Pointing to an older commit results in a 405
11
status code.
12

13
To delete a snippet, regardless of whether or not concurrent changes
14
are being made to it, use `DELETE /snippets/{encoded_id}` instead.
15
 */
16
export async function main(
17
  auth: Bitbucket,
18
  encoded_id: string,
19
  node_id: string,
20
  workspace: string
21
) {
22
  const url = new URL(
23
    `https://api.bitbucket.org/2.0/snippets/${workspace}/${encoded_id}/${node_id}`
24
  );
25

26
  const response = await fetch(url, {
27
    method: "DELETE",
28
    headers: {
29
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
30
    },
31
    body: undefined,
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.text();
38
}
39