List comments on an issue

Returns a paginated list of all comments that were made on the specified issue. The default sorting is oldest to newest and can be overridden with the `sort` query parameter. This endpoint also supports filtering and sorting of the results. See filtering and sorting for more details.

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 an issue
7
 * Returns a paginated list of all comments that were made on the
8
specified issue.
9

10
The default sorting is oldest to newest and can be overridden with
11
the `sort` query parameter.
12

13
This endpoint also supports filtering and sorting of the results. See
14
filtering and sorting for more details.
15
 */
16
export async function main(
17
  auth: Bitbucket,
18
  issue_id: string,
19
  repo_slug: string,
20
  workspace: string,
21
  q: string | undefined
22
) {
23
  const url = new URL(
24
    `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/issues/${issue_id}/comments`
25
  );
26
  for (const [k, v] of [["q", q]]) {
27
    if (v !== undefined && v !== "") {
28
      url.searchParams.append(k, v);
29
    }
30
  }
31
  const response = await fetch(url, {
32
    method: "GET",
33
    headers: {
34
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
35
    },
36
    body: undefined,
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.json();
43
}
44