Update a deployment branch policy

Updates a deployment branch policy for an environment. You must authenticate using an access token with the `repo` scope to use this endpoint. GitHub Apps must have the `administration:write` permission for the repository 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
 * Update a deployment branch policy
6
 * Updates a deployment branch policy for an environment.
7

8
You must authenticate using an access token with the `repo` scope to use this endpoint. GitHub Apps must have the `administration:write` permission for the repository to use this endpoint.
9
 */
10
export async function main(
11
  auth: Github,
12
  owner: string,
13
  repo: string,
14
  environment_name: string,
15
  branch_policy_id: string,
16
  body: { name: string; [k: string]: unknown }
17
) {
18
  const url = new URL(
19
    `https://api.github.com/repos/${owner}/${repo}/environments/${environment_name}/deployment-branch-policies/${branch_policy_id}`
20
  );
21

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