Remove status check contexts

Protected branches are available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server. For more information, see [GitHub's products](https://docs.github.com/github/getting-started-with-github/githubs-products) in the GitHub Help documentation.

Script github Verified

by hugo697 ยท 10/25/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 367 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Remove status check contexts
6
 * Protected branches are available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server. For more information, see [GitHub's products](https://docs.github.com/github/getting-started-with-github/githubs-products) in the GitHub Help documentation.
7
 */
8
export async function main(
9
  auth: Github,
10
  owner: string,
11
  repo: string,
12
  branch: string,
13
  body: { contexts: string[]; [k: string]: unknown } | string[]
14
) {
15
  const url = new URL(
16
    `https://api.github.com/repos/${owner}/${repo}/branches/${branch}/protection/required_status_checks/contexts`
17
  );
18

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