0

List selected repositories enabled for GitHub Actions in an organization

by
Published Oct 25, 2023

Lists the selected repositories that are enabled for GitHub Actions in an organization.

Script github Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 398 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * List selected repositories enabled for GitHub Actions in an organization
6
 * Lists the selected repositories that are enabled for GitHub Actions in an organization.
7
 */
8
export async function main(
9
  auth: Github,
10
  org: string,
11
  per_page: string | undefined,
12
  page: string | undefined
13
) {
14
  const url = new URL(
15
    `https://api.github.com/orgs/${org}/actions/permissions/repositories`
16
  );
17
  for (const [k, v] of [
18
    ["per_page", per_page],
19
    ["page", page],
20
  ]) {
21
    if (v !== undefined && v !== "") {
22
      url.searchParams.append(k, v);
23
    }
24
  }
25
  const response = await fetch(url, {
26
    method: "GET",
27
    headers: {
28
      Authorization: "Bearer " + auth.token,
29
    },
30
    body: undefined,
31
  });
32
  if (!response.ok) {
33
    const text = await response.text();
34
    throw new Error(`${response.status} ${text}`);
35
  }
36
  return await response.json();
37
}
38