0

Export the to a Git repository

by
Published Oct 17, 2025
Script gitbook Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Gitbook = {
3
  token: string;
4
};
5
/**
6
 * Export the to a Git repository
7
 *
8
 */
9
export async function main(
10
  auth: Gitbook,
11
  spaceId: string,
12
  body: {
13
    url: string;
14
    ref: string;
15
    commitMessage: string;
16
    repoCacheID?: string;
17
    repoTreeURL?: string;
18
    repoCommitURL?: string;
19
    repoProjectDirectory?: string;
20
    timestamp?: string;
21
    force?: false | true;
22
    gitInfo?: { provider?: "github" | "gitlab"; url?: string };
23
  },
24
) {
25
  const url = new URL(`https://api.gitbook.com/v1/spaces/${spaceId}/git/export`);
26

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