Edits history of script submission #2245 for ' Get a user migration status (github)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Github = {
      token: string;
    };
    /**
     * 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).
     */
    export async function main(
      auth: Github,
      migration_id: string,
      exclude: string | undefined
    ) {
      const url = new URL(`https://api.github.com/user/migrations/${migration_id}`);
      for (const [k, v] of [["exclude", exclude]]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 367 days ago

  • nativets
    type Github = {
      token: string;
    };
    /**
     * 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).
     */
    export async function main(
      auth: Github,
      migration_id: string,
      exclude: string | undefined
    ) {
      const url = new URL(`https://api.github.com/user/migrations/${migration_id}`);
      for (const [k, v] of [["exclude", exclude]]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 927 days ago