From 9c7a5557b3b8d9bb5992396ccd9de23be9a7c5a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paulius=20Jarmalavi=C4=8Dius?= Date: Wed, 10 Aug 2022 03:18:12 +0300 Subject: [PATCH] ListTags fetch all pages (#214) --- repository.go | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/repository.go b/repository.go index 79a4a52..0cc22f4 100644 --- a/repository.go +++ b/repository.go @@ -482,16 +482,11 @@ func (r *Repository) ListTags(rbo *RepositoryTagOptions) (*RepositoryTags, error } urlStr := r.c.requestUrl("/repositories/%s/%s/refs/tags?%s", rbo.Owner, rbo.RepoSlug, params.Encode()) - response, err := r.c.executeRaw("GET", urlStr, "") - if err != nil { - return nil, err - } - bodyBytes, err := ioutil.ReadAll(response) + response, err := r.c.executePaginated("GET", urlStr, "") if err != nil { return nil, err } - bodyString := string(bodyBytes) - return decodeRepositoryTags(bodyString) + return decodeRepositoryTags(response) } func (r *Repository) CreateTag(rbo *RepositoryTagCreationOptions) (*RepositoryTag, error) { @@ -1202,19 +1197,13 @@ func decodeRepositoryTagCreated(tagResponseStr string) (*RepositoryTag, error) { return &responseTagCreated, nil } -func decodeRepositoryTags(tagResponseStr string) (*RepositoryTags, error) { - - var tagResponseMap map[string]interface{} - err := json.Unmarshal([]byte(tagResponseStr), &tagResponseMap) - if err != nil { - return nil, err - } - +func decodeRepositoryTags(tagResponse interface{}) (*RepositoryTags, error) { + tagResponseMap := tagResponse.(map[string]interface{}) tagArray := tagResponseMap["values"].([]interface{}) var tags []RepositoryTag for _, tagEntry := range tagArray { var tag RepositoryTag - err = mapstructure.Decode(tagEntry, &tag) + err := mapstructure.Decode(tagEntry, &tag) if err == nil { tags = append(tags, tag) }