Get an organization migration status

Fetches the status of a migration. The `state` of a migration can be one of the following values: * `pending`, which means the migration hasn't started yet. * `exporting`, which means the migration is in progress. * `exported`, which means the migration finished successfully. * `failed`, which means the migration failed.

Script github Verified

by hugo697 ยท 10/25/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 366 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Get an organization migration status
6
 * Fetches the status of a migration.
7

8
The `state` of a migration can be one of the following values:
9

10
*   `pending`, which means the migration hasn't started yet.
11
*   `exporting`, which means the migration is in progress.
12
*   `exported`, which means the migration finished successfully.
13
*   `failed`, which means the migration failed.
14
 */
15
export async function main(
16
  auth: Github,
17
  org: string,
18
  migration_id: string,
19
  exclude: string | undefined
20
) {
21
  const url = new URL(
22
    `https://api.github.com/orgs/${org}/migrations/${migration_id}`
23
  );
24
  for (const [k, v] of [["exclude", exclude]]) {
25
    if (v !== undefined && v !== "") {
26
      url.searchParams.append(k, v);
27
    }
28
  }
29
  const response = await fetch(url, {
30
    method: "GET",
31
    headers: {
32
      Authorization: "Bearer " + auth.token,
33
    },
34
    body: undefined,
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42