0

Request a GitHub Pages build

by
Published Oct 25, 2023

You can request that your site be built from the latest revision on the default branch.

Script github Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 398 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Request a GitHub Pages build
6
 * You can request that your site be built from the latest revision on the default branch.
7
 */
8
export async function main(auth: Github, owner: string, repo: string) {
9
  const url = new URL(
10
    `https://api.github.com/repos/${owner}/${repo}/pages/builds`
11
  );
12

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