0
Update a commit application property
One script reply has been approved by the moderators Verified

Update an application property value stored against a commit.

Created by hugo697 425 days ago Viewed 9140 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 425 days ago
1
type Bitbucket = {
2
  username: string;
3
  password: string;
4
};
5
/**
6
 * Update a commit application property
7
 * Update an application property value stored against a commit.
8
 */
9
export async function main(
10
  auth: Bitbucket,
11
  workspace: string,
12
  repo_slug: string,
13
  commit: string,
14
  app_key: string,
15
  property_name: string,
16
  body: { _attributes?: ("public" | "read_only")[]; [k: string]: unknown }
17
) {
18
  const url = new URL(
19
    `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/commit/${commit}/properties/${app_key}/${property_name}`
20
  );
21

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