Update information about a GitHub Pages site

Updates information for a GitHub Pages site. For more information, see "About GitHub Pages. To use this endpoint, you must be a repository administrator, maintainer, or have the 'manage GitHub Pages settings' permission. A token with the `repo` scope or Pages write permission is required. GitHub Apps must have the `administration:write` and `pages:write` permissions.

Script github Verified

by hugo697 ยท 10/25/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 367 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Update information about a GitHub Pages site
6
 * Updates information for a GitHub Pages site. For more information, see "About GitHub Pages.
7

8
To use this endpoint, you must be a repository administrator, maintainer, or have the 'manage GitHub Pages settings' permission. A token with the `repo` scope or Pages write permission is required. GitHub Apps must have the `administration:write` and `pages:write` permissions.
9
 */
10
export async function main(
11
  auth: Github,
12
  owner: string,
13
  repo: string,
14
  body: { [k: string]: unknown } & {
15
    build_type?: "legacy" | "workflow";
16
    cname?: string;
17
    https_enforced?: boolean;
18
    source?:
19
      | ("gh-pages" | "master" | "master /docs")
20
      | { branch: string; path: "/" | "/docs"; [k: string]: unknown };
21
    [k: string]: unknown;
22
  }
23
) {
24
  const url = new URL(`https://api.github.com/repos/${owner}/${repo}/pages`);
25

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