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

Update an application property value stored against a pull request.

Created by hugo697 174 days ago Viewed 3739 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 174 days ago
1
type Bitbucket = {
2
  username: string;
3
  password: string;
4
};
5
/**
6
 * Update a pull request application property
7
 * Update an application property value stored against a pull request.
8
 */
9
export async function main(
10
  auth: Bitbucket,
11
  workspace: string,
12
  repo_slug: string,
13
  pullrequest_id: 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}/pullrequests/${pullrequest_id}/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