Check resource should be able to grab multiple tags for the same commit
This commit is contained in:
39
gitlab.go
39
gitlab.go
@@ -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
|
||||||
break
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if foundTag {
|
if skipToNextPage {
|
||||||
|
if opt.Page >= res.TotalPages {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
opt.Page = res.NextPage
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if foundTag != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
allTags = append(allTags, tags...)
|
allTags = append(allTags, tags...)
|
||||||
|
|
||||||
if opt.Page >= res.TotalPages {
|
if opt.Page >= res.TotalPages {
|
||||||
|
Reference in New Issue
Block a user