Skip to content

Commit

Permalink
ListTags fetch all pages (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjarmalavicius authored Aug 10, 2022
1 parent f6ce0f7 commit 9c7a555
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 9c7a555

Please sign in to comment.