Update a project
One script reply has been approved by the moderators Verified

Updates a project board's information. Returns a 404 Not Found status if projects are disabled. If you do not have sufficient privileges to perform this action, a 401 Unauthorized or 410 Gone status is returned.

Created by hugo697 864 days ago
Submitted by hugo697 Typescript (fetch-only)
Verified 304 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Update a project
6
 * Updates a project board's information. Returns a `404 Not Found` status if projects are disabled. If you do not have sufficient privileges to perform this action, a `401 Unauthorized` or `410 Gone` status is returned.
7
 */
8
export async function main(
9
  auth: Github,
10
  project_id: string,
11
  body: {
12
    body?: string;
13
    name?: string;
14
    organization_permission?: "read" | "write" | "admin" | "none";
15
    private?: boolean;
16
    state?: string;
17
    [k: string]: unknown;
18
  }
19
) {
20
  const url = new URL(`https://api.github.com/projects/${project_id}`);
21

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