List devcontainer configurations in a repository for the authenticated user

Lists the devcontainer.json files associated with a specified repository and the authenticated user. These files specify launchpoint configurations for codespaces created within the repository. You must authenticate using an access token with the `codespace` scope to use this endpoint. GitHub Apps must have read access to the `codespaces_metadata` repository permission to use this endpoint.

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
 * List devcontainer configurations in a repository for the authenticated user
6
 * Lists the devcontainer.json files associated with a specified repository and the authenticated user. These files
7
specify launchpoint configurations for codespaces created within the repository.
8

9
You must authenticate using an access token with the `codespace` scope to use this endpoint.
10

11
GitHub Apps must have read access to the `codespaces_metadata` repository permission to use this endpoint.
12
 */
13
export async function main(
14
  auth: Github,
15
  owner: string,
16
  repo: string,
17
  per_page: string | undefined,
18
  page: string | undefined
19
) {
20
  const url = new URL(
21
    `https://api.github.com/repos/${owner}/${repo}/codespaces/devcontainers`
22
  );
23
  for (const [k, v] of [
24
    ["per_page", per_page],
25
    ["page", page],
26
  ]) {
27
    if (v !== undefined && v !== "") {
28
      url.searchParams.append(k, v);
29
    }
30
  }
31
  const response = await fetch(url, {
32
    method: "GET",
33
    headers: {
34
      Authorization: "Bearer " + auth.token,
35
    },
36
    body: undefined,
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.json();
43
}
44