Check issue import status

When using GET, this endpoint reports the status of the current import task. After the job has been scheduled, but before it starts executing, the endpoint returns a 202 response with status `ACCEPTED`. Once it starts running, it is a 202 response with status `STARTED` and progress filled. After it is finished, it becomes a 200 response with status `SUCCESS` or `FAILURE`.

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
 * Check issue import status
7
 * When using GET, this endpoint reports the status of the current import task.
8

9
After the job has been scheduled, but before it starts executing, the endpoint
10
returns a 202 response with status `ACCEPTED`.
11

12
Once it starts running, it is a 202 response with status `STARTED` and progress filled.
13

14
After it is finished, it becomes a 200 response with status `SUCCESS` or `FAILURE`.
15
 */
16
export async function main(
17
  auth: Bitbucket,
18
  repo_slug: string,
19
  workspace: string
20
) {
21
  const url = new URL(
22
    `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/issues/import`
23
  );
24

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