0
Fork a gist
One script reply has been approved by the moderators Verified
Created by hugo697 176 days ago Viewed 3959 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 176 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Fork a gist
6
 *
7
 */
8
export async function main(auth: Github, gist_id: string) {
9
  const url = new URL(`https://api.github.com/gists/${gist_id}/forks`);
10

11
  const response = await fetch(url, {
12
    method: "POST",
13
    headers: {
14
      Authorization: "Bearer " + auth.token,
15
    },
16
    body: undefined,
17
  });
18
  if (!response.ok) {
19
    const text = await response.text();
20
    throw new Error(`${response.status} ${text}`);
21
  }
22
  return await response.json();
23
}
24