Get an explicit group permission for a repository

Returns the group permission for a given group slug and repository Only users with admin permission for the repository may access this resource. Permissions can be: * `admin` * `write` * `read` * `none`

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
 * Get an explicit group permission for a repository
7
 * Returns the group permission for a given group slug and repository
8

9
Only users with admin permission for the repository may access this resource.
10

11
Permissions can be:
12

13
* `admin`
14
* `write`
15
* `read`
16
* `none`
17
 */
18
export async function main(
19
  auth: Bitbucket,
20
  group_slug: string,
21
  repo_slug: string,
22
  workspace: string
23
) {
24
  const url = new URL(
25
    `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/permissions-config/groups/${group_slug}`
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