Skip to content

Commit 43f6d88

Browse files
Support pagination for tags
1 parent efad427 commit 43f6d88

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

registry/tags.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,38 @@
11
package registry
22

3-
import "context"
3+
import (
4+
"context"
5+
"net/url"
6+
7+
"github.com/peterhellberg/link"
8+
)
49

510
type tagsResponse struct {
611
Tags []string `json:"tags"`
712
}
813

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

1419
var response tagsResponse
15-
if _, err := r.getJSON(ctx, url, &response); err != nil {
20+
h, err := r.getJSON(ctx, u, &response)
21+
if err != nil {
1622
return nil, err
1723
}
24+
tags := response.Tags
25+
26+
for _, l := range link.ParseHeader(h) {
27+
if l.Rel == "next" {
28+
unescaped, _ := url.QueryUnescape(l.URI)
29+
h, err = r.getJSON(ctx, unescaped, &response)
30+
if err != nil {
31+
return nil, err
32+
}
33+
tags = append(tags, response.Tags...)
34+
}
35+
}
1836

19-
return response.Tags, nil
37+
return tags, nil
2038
}

0 commit comments

Comments
 (0)