Start an organization migration

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

26
  const response = await fetch(url, {
27
    method: "POST",
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.json();
39
}
40