0
List comments on a snippet
One script reply has been approved by the moderators Verified

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.

Created by hugo697 396 days ago Viewed 9017 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 396 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