0

Set interaction restrictions for an organization

by
Published Oct 25, 2023

Temporarily restricts interactions to a certain type of GitHub user in any public repository in the given organization. You must be an organization owner to set these restrictions. Setting the interaction limit at the organization level will overwrite any interaction limits that are set for individual repositories owned by the 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
 * Set interaction restrictions for an organization
6
 * Temporarily restricts interactions to a certain type of GitHub user in any public repository in the given organization. You must be an organization owner to set these restrictions. Setting the interaction limit at the organization level will overwrite any interaction limits that are set for individual repositories owned by the organization.
7
 */
8
export async function main(
9
  auth: Github,
10
  org: string,
11
  body: {
12
    expiry?: "one_day" | "three_days" | "one_week" | "one_month" | "six_months";
13
    limit: "existing_users" | "contributors_only" | "collaborators_only";
14
    [k: string]: unknown;
15
  }
16
) {
17
  const url = new URL(`https://api.github.com/orgs/${org}/interaction-limits`);
18

19
  const response = await fetch(url, {
20
    method: "PUT",
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