Enable or disable a security feature for an organization

Enables or disables the specified security feature for all repositories in an organization.

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
 * Enable or disable a security feature for an organization
6
 * Enables or disables the specified security feature for all repositories in an organization.
7
 */
8
export async function main(
9
  auth: Github,
10
  org: string,
11
  security_product:
12
    | "dependency_graph"
13
    | "dependabot_alerts"
14
    | "dependabot_security_updates"
15
    | "advanced_security"
16
    | "secret_scanning"
17
    | "secret_scanning_push_protection",
18
  enablement: "enable_all" | "disable_all"
19
) {
20
  const url = new URL(
21
    `https://api.github.com/orgs/${org}/${security_product}/${enablement}`
22
  );
23

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