Edits history of script submission #13805 for ' List git namespaces by provider (vercel)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Vercel = {
      token: string;
    };
    /**
     * List git namespaces by provider
     * Lists git namespaces for a supported provider. Supported providers are `github`, `gitlab` and `bitbucket`. If the provider is not provided, it will try to obtain it from the user that authenticated the request.
     */
    export async function main(
      auth: Vercel,
      host: string | undefined,
      provider:
        | "github"
        | "github-custom-host"
        | "gitlab"
        | "bitbucket"
        | undefined,
    ) {
      const url = new URL(`https://api.vercel.com/v1/integrations/git-namespaces`);
      for (const [k, v] of [
        ["host", host],
        ["provider", provider],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          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 428 days ago