0
Get the branching model config for a project
One script reply has been approved by the moderators Verified

Return the branching model configuration for a project.

Created by hugo697 277 days ago Viewed 8979 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 277 days ago
1
type Bitbucket = {
2
  username: string;
3
  password: string;
4
};
5
/**
6
 * Get the branching model config for a project
7
 * Return the branching model configuration for a project.
8
 */
9
export async function main(
10
  auth: Bitbucket,
11
  project_key: string,
12
  workspace: string
13
) {
14
  const url = new URL(
15
    `https://api.bitbucket.org/2.0/workspaces/${workspace}/projects/${project_key}/branching-model/settings`
16
  );
17

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