Update a milestone

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 milestone
6
 *
7
 */
8
export async function main(
9
  auth: Github,
10
  owner: string,
11
  repo: string,
12
  milestone_number: string,
13
  body: {
14
    description?: string;
15
    due_on?: string;
16
    state?: "open" | "closed";
17
    title?: string;
18
    [k: string]: unknown;
19
  }
20
) {
21
  const url = new URL(
22
    `https://api.github.com/repos/${owner}/${repo}/milestones/${milestone_number}`
23
  );
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