Start a user migration

Initiates the generation of a user migration archive.

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
 * Start a user migration
6
 * Initiates the generation of a user migration archive.
7
 */
8
export async function main(
9
  auth: Github,
10
  body: {
11
    exclude?: "repositories"[];
12
    exclude_attachments?: boolean;
13
    exclude_git_data?: boolean;
14
    exclude_metadata?: boolean;
15
    exclude_owner_projects?: boolean;
16
    exclude_releases?: boolean;
17
    lock_repositories?: boolean;
18
    org_metadata_only?: boolean;
19
    repositories: string[];
20
    [k: string]: unknown;
21
  }
22
) {
23
  const url = new URL(`https://api.github.com/user/migrations`);
24

25
  const response = await fetch(url, {
26
    method: "POST",
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