Update a team

To edit a team, the authenticated user must either be an organization owner or a team maintainer. **Note:** You can also specify a team by `org_id` and `team_id` using the route `PATCH /organizations/{org_id}/team/{team_id}`.

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
 * Update a team
6
 * To edit a team, the authenticated user must either be an organization owner or a team maintainer.
7

8
**Note:** You can also specify a team by `org_id` and `team_id` using the route `PATCH /organizations/{org_id}/team/{team_id}`.
9
 */
10
export async function main(
11
  auth: Github,
12
  org: string,
13
  team_slug: string,
14
  body: {
15
    description?: string;
16
    name?: string;
17
    parent_team_id?: number;
18
    permission?: "pull" | "push" | "admin";
19
    privacy?: "secret" | "closed";
20
    [k: string]: unknown;
21
  }
22
) {
23
  const url = new URL(`https://api.github.com/orgs/${org}/teams/${team_slug}`);
24

25
  const response = await fetch(url, {
26
    method: "PATCH",
27
    headers: {
28
      "Content-Type": "application/json",
29
      Authorization: "Bearer " + auth.token,
30
    },
31
    body: JSON.stringify(body),
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