Skip to content

Commit

Permalink
Implement pagination when listing docker image tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
sangaline committed Feb 27, 2024
1 parent ee9bd13 commit bb6a765
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,16 +495,28 @@ export async function getDockerImageTags(
repository: string,
username: string = "sindrilabs",
): Promise<string[]> {
const url = `https://hub.docker.com/v2/repositories/${username}/${repository}/tags/`;
const {
data: { results },
} = await axios.get<{
results: Array<{
last_updated: string;
name: string;
tag_status: string;
}>;
}>(url);
let url: string | undefined =
`https://hub.docker.com/v2/repositories/${username}/${repository}/tags/?page_size=1`;
interface Result {
last_updated: string;
name: string;
tag_status: string;
}
interface Response {
count: number;
next?: string;
previous: string | null;
results: Result[];
}
let results: Result[] = [];

while (url) {
const response: { data: Response } = await axios.get<Response>(url);

results = results.concat(response.data.results);
url = response.data.next; // Update the URL for the next request, or null if no more pages
}

return results
.filter(({ tag_status }) => tag_status === "active")
.filter(({ name }) => name !== "dev")
Expand Down

0 comments on commit bb6a765

Please sign in to comment.