0

List selected repositories for an organization variable

by
Published Oct 25, 2023

Lists all repositories that can access an organization variable that is available to selected repositories. You must authenticate using an access token with the `admin:org` scope to use this endpoint. GitHub Apps must have the `organization_actions_variables:read` organization permission to use this endpoint.

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 for an organization variable
6
 * Lists all repositories that can access an organization variable that is available to selected repositories. You must authenticate using an access token with the `admin:org` scope to use this endpoint. GitHub Apps must have the `organization_actions_variables:read` organization permission to use this endpoint.
7
 */
8
export async function main(
9
  auth: Github,
10
  org: string,
11
  name: string,
12
  page: string | undefined,
13
  per_page: string | undefined
14
) {
15
  const url = new URL(
16
    `https://api.github.com/orgs/${org}/actions/variables/${name}/repositories`
17
  );
18
  for (const [k, v] of [
19
    ["page", page],
20
    ["per_page", per_page],
21
  ]) {
22
    if (v !== undefined && v !== "") {
23
      url.searchParams.append(k, v);
24
    }
25
  }
26
  const response = await fetch(url, {
27
    method: "GET",
28
    headers: {
29
      Authorization: "Bearer " + auth.token,
30
    },
31
    body: undefined,
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39