List comments on a snippet

Used to retrieve a paginated list of all comments for a specific snippet. This resource works identical to commit and pull request comments. The default sorting is oldest to newest and can be overridden with the `sort` query parameter.

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
 * List comments on a snippet
7
 * Used to retrieve a paginated list of all comments for a specific
8
snippet.
9

10
This resource works identical to commit and pull request comments.
11

12
The default sorting is oldest to newest and can be overridden with
13
the `sort` query parameter.
14
 */
15
export async function main(
16
  auth: Bitbucket,
17
  encoded_id: string,
18
  workspace: string
19
) {
20
  const url = new URL(
21
    `https://api.bitbucket.org/2.0/snippets/${workspace}/${encoded_id}/comments`
22
  );
23

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