0

List All Container Registry Repository Tags

by
Published Dec 20, 2024

To list all tags in your container registry repository, send a GET request to `/v2/registry/$REGISTRY_NAME/repositories/$REPOSITORY_NAME/tags`. Note that if your repository name contains `/` characters, it must be URL-encoded in the request URL. For example, to list tags for `registry.digitalocean.com/example/my/repo`, the path would be `/v2/registry/example/repositories/my%2Frepo/tags`.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * List All Container Registry Repository Tags
7
 * To list all tags in your container registry repository, send a GET
8
request to `/v2/registry/$REGISTRY_NAME/repositories/$REPOSITORY_NAME/tags`.
9

10
Note that if your repository name contains `/` characters, it must be
11
URL-encoded in the request URL. For example, to list tags for
12
`registry.digitalocean.com/example/my/repo`, the path would be
13
`/v2/registry/example/repositories/my%2Frepo/tags`.
14

15
 */
16
export async function main(
17
  auth: Digitalocean,
18
  registry_name: string,
19
  repository_name: string,
20
  per_page: string | undefined,
21
  page: string | undefined,
22
) {
23
  const url = new URL(
24
    `https://api.digitalocean.com/v2/registry/${registry_name}/repositories/${repository_name}/tags`,
25
  );
26
  for (const [k, v] of [
27
    ["per_page", per_page],
28
    ["page", page],
29
  ]) {
30
    if (v !== undefined && v !== "" && k !== undefined) {
31
      url.searchParams.append(k, v);
32
    }
33
  }
34
  const response = await fetch(url, {
35
    method: "GET",
36
    headers: {
37
      Authorization: "Bearer " + auth.token,
38
    },
39
    body: undefined,
40
  });
41
  if (!response.ok) {
42
    const text = await response.text();
43
    throw new Error(`${response.status} ${text}`);
44
  }
45
  return await response.json();
46
}
47