Set selected repositories enabled for GitHub Actions in an organization

Replaces the list of selected repositories that are enabled for GitHub Actions in an organization.

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
 * Set selected repositories enabled for GitHub Actions in an organization
6
 * Replaces the list of selected repositories that are enabled for GitHub Actions in an organization.
7
 */
8
export async function main(
9
  auth: Github,
10
  org: string,
11
  body: { selected_repository_ids: number[]; [k: string]: unknown }
12
) {
13
  const url = new URL(
14
    `https://api.github.com/orgs/${org}/actions/permissions/repositories`
15
  );
16

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