Skip to content

Commit 7db14ea

Browse files
committed
gitlab: Fix other limits issues
As explained in the previous commit, there are instances in which the incorrect number of items were returned. Fix up two other instances of the same issue in the Project snippet and Issue list code. Signed-off-by: Prarit Bhargava <prarit@redhat.com>
1 parent 60d54e2 commit 7db14ea

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

internal/gitlab/gitlab.go

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -669,19 +669,26 @@ func IssueGet(projID interface{}, id int) (*gitlab.Issue, error) {
669669

670670
// IssueList gets a list of issues on a GitLab Project
671671
func IssueList(projID interface{}, opts gitlab.ListProjectIssuesOptions, n int) ([]*gitlab.Issue, error) {
672-
if n == -1 {
673-
n = maxItemsPerPage
674-
}
675-
676672
var list []*gitlab.Issue
677-
for len(list) < n {
678-
opts.PerPage = n - len(list)
673+
for true {
674+
opts.PerPage = maxItemsPerPage
675+
if n != -1 {
676+
opts.PerPage = n - len(list)
677+
if opts.PerPage > maxItemsPerPage {
678+
opts.PerPage = maxItemsPerPage
679+
}
680+
}
681+
679682
issues, resp, err := lab.Issues.ListProjectIssues(projID, &opts)
680683
if err != nil {
681684
return nil, err
682685
}
683686
list = append(list, issues...)
684687

688+
if len(list) == n {
689+
break
690+
}
691+
685692
var ok bool
686693
if opts.Page, ok = hasNextPage(resp); !ok {
687694
break
@@ -996,19 +1003,26 @@ func ProjectSnippetDelete(projID interface{}, id int) error {
9961003

9971004
// ProjectSnippetList lists snippets on a project
9981005
func ProjectSnippetList(projID interface{}, opts gitlab.ListProjectSnippetsOptions, n int) ([]*gitlab.Snippet, error) {
999-
if n == -1 {
1000-
n = maxItemsPerPage
1001-
}
1002-
10031006
var list []*gitlab.Snippet
1004-
for len(list) < n {
1005-
opts.PerPage = n - len(list)
1007+
for true {
1008+
opts.PerPage = maxItemsPerPage
1009+
if n != -1 {
1010+
opts.PerPage = n - len(list)
1011+
if opts.PerPage > maxItemsPerPage {
1012+
opts.PerPage = maxItemsPerPage
1013+
}
1014+
}
1015+
10061016
snips, resp, err := lab.ProjectSnippets.ListSnippets(projID, &opts)
10071017
if err != nil {
10081018
return nil, err
10091019
}
10101020
list = append(list, snips...)
10111021

1022+
if len(list) == n {
1023+
break
1024+
}
1025+
10121026
var ok bool
10131027
if opts.Page, ok = hasNextPage(resp); !ok {
10141028
break

0 commit comments

Comments
 (0)