Skip to content

Commit

Permalink
Support pagination for tags
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Oct 23, 2022
1 parent efad427 commit 43f6d88
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions registry/tags.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
package registry

import "context"
import (
"context"
"net/url"

"github.com/peterhellberg/link"
)

type tagsResponse struct {
Tags []string `json:"tags"`
}

// Tags returns the tags for a specific repository.
func (r *Registry) Tags(ctx context.Context, repository string) ([]string, error) {
url := r.url("/v2/%s/tags/list", repository)
r.Logf("registry.tags url=%s repository=%s", url, repository)
u := r.url("/v2/%s/tags/list", repository)
r.Logf("registry.tags url=%s repository=%s", u, repository)

var response tagsResponse
if _, err := r.getJSON(ctx, url, &response); err != nil {
h, err := r.getJSON(ctx, u, &response)
if err != nil {
return nil, err
}
tags := response.Tags

for _, l := range link.ParseHeader(h) {
if l.Rel == "next" {
unescaped, _ := url.QueryUnescape(l.URI)
h, err = r.getJSON(ctx, unescaped, &response)
if err != nil {
return nil, err
}
tags = append(tags, response.Tags...)
}
}

return response.Tags, nil
return tags, nil
}

0 comments on commit 43f6d88

Please sign in to comment.