Skip to content

Commit 60d54e2

Browse files
committed
gitlab: Fix 'mr list' limits
The command 'lab mr list --author $author_name --state merged' was returning a list of 100 for each engineer on a project. Evidence in the git tree showed that this was not the case (most had more than 100). This was due to a calcluational error in the MRList() code. Implement a new algorithm that correctly returns all MRs instead of the last 100. Signed-off-by: Prarit Bhargava <prarit@redhat.com>
1 parent 4622fad commit 60d54e2

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

internal/gitlab/gitlab.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -433,19 +433,26 @@ func MRGet(projID interface{}, id int) (*gitlab.MergeRequest, error) {
433433

434434
// MRList lists the MRs on a GitLab project
435435
func MRList(projID interface{}, opts gitlab.ListProjectMergeRequestsOptions, n int) ([]*gitlab.MergeRequest, error) {
436-
if n == -1 {
437-
n = maxItemsPerPage
438-
}
439-
440436
var list []*gitlab.MergeRequest
441-
for len(list) < n {
442-
opts.PerPage = n - len(list)
437+
for true {
438+
opts.PerPage = maxItemsPerPage
439+
if n != -1 {
440+
opts.PerPage = n - len(list)
441+
if opts.PerPage > maxItemsPerPage {
442+
opts.PerPage = maxItemsPerPage
443+
}
444+
}
445+
443446
mrs, resp, err := lab.MergeRequests.ListProjectMergeRequests(projID, &opts)
444447
if err != nil {
445448
return nil, err
446449
}
447450
list = append(list, mrs...)
448451

452+
if len(list) == n {
453+
break
454+
}
455+
449456
var ok bool
450457
if opts.Page, ok = hasNextPage(resp); !ok {
451458
break

0 commit comments

Comments
 (0)