List changes on an issue

Returns the list of all changes that have been made to the specified issue.

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 changes on an issue
7
 * Returns the list of all changes that have been made to the specified
8
issue.
9
 */
10
export async function main(
11
  auth: Bitbucket,
12
  issue_id: string,
13
  repo_slug: string,
14
  workspace: string,
15
  q: string | undefined,
16
  sort: string | undefined
17
) {
18
  const url = new URL(
19
    `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/issues/${issue_id}/changes`
20
  );
21
  for (const [k, v] of [
22
    ["q", q],
23
    ["sort", sort],
24
  ]) {
25
    if (v !== undefined && v !== "") {
26
      url.searchParams.append(k, v);
27
    }
28
  }
29
  const response = await fetch(url, {
30
    method: "GET",
31
    headers: {
32
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
33
    },
34
    body: undefined,
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42