0
Update a build status for a commit
One script reply has been approved by the moderators Verified

Used to update the current status of a build status object on the specific commit.

This operation can also be used to change other properties of the build status:

  • state
  • name
  • description
  • url
  • refname

The key cannot be changed.

Created by hugo697 197 days ago Viewed 5845 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 197 days ago
1
type Bitbucket = {
2
  username: string;
3
  password: string;
4
};
5
/**
6
 * Update a build status for a commit
7
 * Used to update the current status of a build status object on the
8
specific commit.
9

10
This operation can also be used to change other properties of the
11
build status:
12

13
* `state`
14
* `name`
15
* `description`
16
* `url`
17
* `refname`
18

19
The `key` cannot be changed.
20
 */
21
export async function main(
22
  auth: Bitbucket,
23
  commit: string,
24
  key: string,
25
  repo_slug: string,
26
  workspace: string,
27
  body: { type: string; [k: string]: unknown } & {
28
    links?: {
29
      self?: { href?: string; name?: string };
30
      commit?: { href?: string; name?: string };
31
    };
32
    uuid?: string;
33
    key?: string;
34
    refname?: string;
35
    url?: string;
36
    state?: "FAILED" | "INPROGRESS" | "STOPPED" | "SUCCESSFUL";
37
    name?: string;
38
    description?: string;
39
    created_on?: string;
40
    updated_on?: string;
41
    [k: string]: unknown;
42
  }
43
) {
44
  const url = new URL(
45
    `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/commit/${commit}/statuses/build/${key}`
46
  );
47

48
  const response = await fetch(url, {
49
    method: "PUT",
50
    headers: {
51
      "Content-Type": "application/json",
52
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
53
    },
54
    body: JSON.stringify(body),
55
  });
56
  if (!response.ok) {
57
    const text = await response.text();
58
    throw new Error(`${response.status} ${text}`);
59
  }
60
  return await response.json();
61
}
62