From 439337a7ab19b945e7eb6f03aa04b71b84a30c0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niko=20K=C3=B6ser?= Date: Thu, 4 Jun 2020 20:22:25 +0200 Subject: [PATCH] fix: GitLab LoadTreeEntries not loading whole tree Requested only the first page of the API results so we only got those entries that were on the first page. Now we use the Next-Page entry from the header to iterate over all pages. Increased the amount of loaded items per call from 20 to 100 too. --- pkg/proji/repo/gitlab/gitlab.go | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/pkg/proji/repo/gitlab/gitlab.go b/pkg/proji/repo/gitlab/gitlab.go index f1290586..eaa1a7f0 100644 --- a/pkg/proji/repo/gitlab/gitlab.go +++ b/pkg/proji/repo/gitlab/gitlab.go @@ -75,13 +75,32 @@ func (g *GitLab) FilePathToRawURI(filePath string) string { // GetTreeEntries gets the paths and types of the repo tree func (g *GitLab) LoadTreeEntries() error { + // Reset tree entries + g.TreeEntries = make([]*gl.TreeNode, 0) pid := g.OwnerName + "/" + g.RepoName rec := true - treeNodes, _, err := g.client.Repositories.ListTree(pid, &gl.ListTreeOptions{Recursive: &rec, Ref: &g.BranchName}) - if err != nil { - return err + nextPage := 1 + + for { + treeNodes, resp, err := g.client.Repositories.ListTree(pid, &gl.ListTreeOptions{ + Recursive: &rec, + Ref: &g.BranchName, + ListOptions: gl.ListOptions{ + Page: nextPage, + PerPage: 100, + }, + }) + if err != nil { + return err + } + g.TreeEntries = append(g.TreeEntries, treeNodes...) + + // Break if no next page + if resp.NextPage == 0 { + break + } + nextPage = resp.NextPage } - g.TreeEntries = treeNodes return nil }