0

List deployment branch policies

by
Published Oct 25, 2023

Lists the deployment branch policies for an environment. Anyone with read access to the repository can use this endpoint. If the repository is private, you must use an access token with the `repo` scope. GitHub Apps must have the `actions:read` permission to use this endpoint.

Script github Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 398 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * List deployment branch policies
6
 * Lists the deployment branch policies for an environment.
7

8
Anyone with read access to the repository can use this endpoint. If the repository is private, you must use an access token with the `repo` scope. GitHub Apps must have the `actions:read` permission to use this endpoint.
9
 */
10
export async function main(
11
  auth: Github,
12
  owner: string,
13
  repo: string,
14
  environment_name: string,
15
  per_page: string | undefined,
16
  page: string | undefined
17
) {
18
  const url = new URL(
19
    `https://api.github.com/repos/${owner}/${repo}/environments/${environment_name}/deployment-branch-policies`
20
  );
21
  for (const [k, v] of [
22
    ["per_page", per_page],
23
    ["page", page],
24
  ]) {
25
    if (v !== undefined && v !== "") {
26
      url.searchParams.append(k, v);
27
    }
28
  }
29
  const response = await fetch(url, {
30
    method: "GET",
31
    headers: {
32
      Authorization: "Bearer " + auth.token,
33
    },
34
    body: undefined,
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42