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

Return the branching model configuration for a repository. The returned object:

  1. Always has a development property for the development branch.
  2. Always a production property for the production branch. The production branch can be disabled.
  3. The branch_types contains all the branch types.

This is the raw configuration for the branching model. A client wishing to see the branching model with its actual current branches may find the active model API more useful.

Created by hugo697 174 days ago Viewed 3736 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 174 days ago
1
type Bitbucket = {
2
  username: string;
3
  password: string;
4
};
5
/**
6
 * Get the branching model config for a repository
7
 * Return the branching model configuration for a repository. The returned
8
object:
9

10
1. Always has a `development` property for the development branch.
11
2. Always a `production` property for the production branch. The
12
   production branch can be disabled.
13
3. The `branch_types` contains all the branch types.
14

15
This is the raw configuration for the branching model. A client
16
wishing to see the branching model with its actual current branches may
17
find the active model API more useful.
18
 */
19
export async function main(
20
  auth: Bitbucket,
21
  repo_slug: string,
22
  workspace: string
23
) {
24
  const url = new URL(
25
    `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/branching-model/settings`
26
  );
27

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