0

Delete a commit comment

by
Published Oct 24, 2023

Deletes the specified commit comment. Note that deleting comments that have visible replies that point to them will not really delete the resource. This is to retain the integrity of the original comment tree. Instead, the `deleted` element is set to `true` and the content is blanked out. The comment will continue to be returned by the collections and self endpoints.

Script bitbucket Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 398 days ago
1
type Bitbucket = {
2
  username: string;
3
  password: string;
4
};
5
/**
6
 * Delete a commit comment
7
 * Deletes the specified commit comment.
8

9
Note that deleting comments that have visible replies that point to
10
them will not really delete the resource. This is to retain the integrity
11
of the original comment tree. Instead, the `deleted` element is set to
12
`true` and the content is blanked out. The comment will continue to be
13
returned by the collections and self endpoints.
14
 */
15
export async function main(
16
  auth: Bitbucket,
17
  comment_id: string,
18
  commit: string,
19
  repo_slug: string,
20
  workspace: string
21
) {
22
  const url = new URL(
23
    `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/commit/${commit}/comments/${comment_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