0
Watch an issue
One script reply has been approved by the moderators Verified

Start watching this issue.

To start watching this issue, do an empty PUT. The 204 status code indicates that the operation was successful.

Created by hugo697 396 days ago Viewed 9002 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 396 days ago
1
type Bitbucket = {
2
  username: string;
3
  password: string;
4
};
5
/**
6
 * Watch an issue
7
 * Start watching this issue.
8

9
To start watching this issue, do an empty PUT. The 204 status code
10
indicates that the operation was successful.
11
 */
12
export async function main(
13
  auth: Bitbucket,
14
  issue_id: string,
15
  repo_slug: string,
16
  workspace: string
17
) {
18
  const url = new URL(
19
    `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/issues/${issue_id}/watch`
20
  );
21

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