List tasks on a pull request

Returns a paginated list of the pull request's tasks. This endpoint supports filtering and sorting of the results by the 'task' field. See filtering and sorting for more details.

Script bitbucket Verified

by hugo697 ยท 3/6/2024

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 tasks on a pull request
7
 * Returns a paginated list of the pull request's tasks.
8

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