Approve a commit

Approve the specified commit as the authenticated user. This operation is only available to users that have explicit access to the repository. In contrast, just the fact that a repository is publicly accessible to users does not give them the ability to approve commits.

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
 * Approve a commit
7
 * Approve the specified commit as the authenticated user.
8

9
This operation is only available to users that have explicit access to
10
the repository. In contrast, just the fact that a repository is
11
publicly accessible to users does not give them the ability to approve
12
commits.
13
 */
14
export async function main(
15
  auth: Bitbucket,
16
  commit: string,
17
  repo_slug: string,
18
  workspace: string
19
) {
20
  const url = new URL(
21
    `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/commit/${commit}/approve`
22
  );
23

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