Get an environment

**Note:** To get information about name patterns that branches must match in order to deploy to this environment, see "Get a deployment branch policy." 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

by hugo697 ยท 10/25/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 366 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Get an environment
6
 * **Note:** To get information about name patterns that branches must match in order to deploy to this environment, see "Get a deployment branch policy."
7

8
Anyone with read access to the repository can use this endpoint. If the
9
repository is private, you must use an access token with the `repo` scope. GitHub
10
Apps must have the `actions:read` permission to use this endpoint.
11
 */
12
export async function main(
13
  auth: Github,
14
  owner: string,
15
  repo: string,
16
  environment_name: string
17
) {
18
  const url = new URL(
19
    `https://api.github.com/repos/${owner}/${repo}/environments/${environment_name}`
20
  );
21

22
  const response = await fetch(url, {
23
    method: "GET",
24
    headers: {
25
      Authorization: "Bearer " + auth.token,
26
    },
27
    body: undefined,
28
  });
29
  if (!response.ok) {
30
    const text = await response.text();
31
    throw new Error(`${response.status} ${text}`);
32
  }
33
  return await response.json();
34
}
35