0

List git repositories linked to namespace by provider

by
Published Apr 8, 2025

Lists git repositories linked to a namespace `id` for a supported provider. A specific namespace `id` can be obtained via the `git-namespaces` endpoint. Supported providers are `github`, `gitlab` and `bitbucket`. If the provider or namespace 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 repositories linked to namespace by provider
7
 * Lists git repositories linked to a namespace `id` for a supported provider. A specific namespace `id` can be obtained via the `git-namespaces`  endpoint. Supported providers are `github`, `gitlab` and `bitbucket`. If the provider or namespace 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
  query: string | undefined,
12
  namespaceId: string | undefined,
13
  provider:
14
    | "github"
15
    | "github-custom-host"
16
    | "gitlab"
17
    | "bitbucket"
18
    | undefined,
19
  installationId: string | undefined,
20
  host: string | undefined,
21
  teamId: string | undefined,
22
  slug: string | undefined,
23
) {
24
  const url = new URL(`https://api.vercel.com/v1/integrations/search-repo`);
25
  for (const [k, v] of [
26
    ["query", query],
27
    ["namespaceId", namespaceId],
28
    ["provider", provider],
29
    ["installationId", installationId],
30
    ["host", host],
31
    ["teamId", teamId],
32
    ["slug", slug],
33
  ]) {
34
    if (v !== undefined && v !== "" && k !== undefined) {
35
      url.searchParams.append(k, v);
36
    }
37
  }
38
  const response = await fetch(url, {
39
    method: "GET",
40
    headers: {
41
      Authorization: "Bearer " + auth.token,
42
    },
43
    body: undefined,
44
  });
45
  if (!response.ok) {
46
    const text = await response.text();
47
    throw new Error(`${response.status} ${text}`);
48
  }
49
  return await response.json();
50
}
51