Check resource should be able to grab multiple tags for the same commit

This commit is contained in:
Ed
2018-12-21 15:47:15 -05:00
parent fa27800311
commit c9d66cbc88

View File

@@ -100,32 +100,61 @@ func (g *GitlabClient) ListTags() ([]*gitlab.Tag, error) {
func (g *GitlabClient) ListTagsUntil(tag_name string) ([]*gitlab.Tag, error) { func (g *GitlabClient) ListTagsUntil(tag_name string) ([]*gitlab.Tag, error) {
var allTags []*gitlab.Tag var allTags []*gitlab.Tag
pageSize := 100
opt := &gitlab.ListTagsOptions{ opt := &gitlab.ListTagsOptions{
ListOptions: gitlab.ListOptions{ ListOptions: gitlab.ListOptions{
PerPage: 100, PerPage: pageSize,
Page: 1, Page: 1,
}, },
OrderBy: gitlab.String("updated"), OrderBy: gitlab.String("updated"),
Sort: gitlab.String("desc"), Sort: gitlab.String("desc"),
} }
var foundTag *gitlab.Tag
for { for {
tags, res, err := g.client.Tags.ListTags(g.repository, opt) tags, res, err := g.client.Tags.ListTags(g.repository, opt)
if err != nil { if err != nil {
return []*gitlab.Tag{}, err return []*gitlab.Tag{}, err
} }
foundTag := false skipToNextPage := false
for i, tag := range tags { for i, tag := range tags {
// Some tags might have the same date - if they all have the same date, take
// all of them
if foundTag != nil {
if foundTag.Commit.CommittedDate.Equal(*tag.Commit.CommittedDate) {
allTags = append(allTags, tag)
if i == (pageSize - 1) {
skipToNextPage = true
break
} else {
continue
}
} else {
break
}
}
if tag.Name == tag_name { if tag.Name == tag_name {
allTags = append(allTags, tags[:i+1]...) allTags = append(allTags, tags[:i+1]...)
foundTag = true foundTag = tag
continue
}
}
if skipToNextPage {
if opt.Page >= res.TotalPages {
break break
} }
opt.Page = res.NextPage
continue
} }
if foundTag {
if foundTag != nil {
break break
} }
allTags = append(allTags, tags...) allTags = append(allTags, tags...)
if opt.Page >= res.TotalPages { if opt.Page >= res.TotalPages {