Get a user migration status

Fetches a single user migration. The response includes the `state` of the migration, which can be one of the following values: * `pending` - the migration hasn't started yet. * `exporting` - the migration is in progress. * `exported` - the migration finished successfully. * `failed` - the migration failed. Once the migration has been `exported` you can [download the migration archive](https://docs.github.com/rest/migrations/users#download-a-user-migration-archive).

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 a user migration status
6
 * Fetches a single user migration. The response includes the `state` of the migration, which can be one of the following values:
7

8
*   `pending` - the migration hasn't started yet.
9
*   `exporting` - the migration is in progress.
10
*   `exported` - the migration finished successfully.
11
*   `failed` - the migration failed.
12

13
Once the migration has been `exported` you can [download the migration archive](https://docs.github.com/rest/migrations/users#download-a-user-migration-archive).
14
 */
15
export async function main(
16
  auth: Github,
17
  migration_id: string,
18
  exclude: string | undefined
19
) {
20
  const url = new URL(`https://api.github.com/user/migrations/${migration_id}`);
21
  for (const [k, v] of [["exclude", exclude]]) {
22
    if (v !== undefined && v !== "") {
23
      url.searchParams.append(k, v);
24
    }
25
  }
26
  const response = await fetch(url, {
27
    method: "GET",
28
    headers: {
29
      Authorization: "Bearer " + auth.token,
30
    },
31
    body: undefined,
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