0

List git namespaces by provider

by
Published Apr 8, 2025

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.

Script vercel Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Vercel = {
3
  token: string;
4
};
5
/**
6
 * List git namespaces by provider
7
 * 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.
8
 */
9
export async function main(
10
  auth: Vercel,
11
  host: string | undefined,
12
  provider:
13
    | "github"
14
    | "github-custom-host"
15
    | "gitlab"
16
    | "bitbucket"
17
    | undefined,
18
) {
19
  const url = new URL(`https://api.vercel.com/v1/integrations/git-namespaces`);
20
  for (const [k, v] of [
21
    ["host", host],
22
    ["provider", provider],
23
  ]) {
24
    if (v !== undefined && v !== "" && k !== undefined) {
25
      url.searchParams.append(k, v);
26
    }
27
  }
28
  const response = await fetch(url, {
29
    method: "GET",
30
    headers: {
31
      Authorization: "Bearer " + auth.token,
32
    },
33
    body: undefined,
34
  });
35
  if (!response.ok) {
36
    const text = await response.text();
37
    throw new Error(`${response.status} ${text}`);
38
  }
39
  return await response.json();
40
}
41