0
List attachments for an issue
One script reply has been approved by the moderators Verified

Returns all attachments for this issue.

This returns the files' meta data. This does not return the files' actual contents.

The files are always ordered by their upload date.

Created by hugo697 126 days ago Viewed 19 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 126 days ago
1
type Bitbucket = {
2
  username: string;
3
  password: string;
4
};
5
/**
6
 * List attachments for an issue
7
 * Returns all attachments for this issue.
8

9
This returns the files' meta data. This does not return the files'
10
actual contents.
11

12
The files are always ordered by their upload date.
13
 */
14
export async function main(
15
  auth: Bitbucket,
16
  issue_id: string,
17
  repo_slug: string,
18
  workspace: string
19
) {
20
  const url = new URL(
21
    `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/issues/${issue_id}/attachments`
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