List comments on a pull request

Returns a paginated list of the pull request's comments. This includes both global, inline comments and replies. 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 a pull request
7
 * Returns a paginated list of the pull request's comments.
8

9
This includes both global, inline comments and replies.
10

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

14
This endpoint also supports filtering and sorting of the results. See
15
filtering and sorting for more
16
details.
17
 */
18
export async function main(
19
  auth: Bitbucket,
20
  pull_request_id: string,
21
  repo_slug: string,
22
  workspace: string
23
) {
24
  const url = new URL(
25
    `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/pullrequests/${pull_request_id}/comments`
26
  );
27

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