Skip to content

Commit

Permalink
fix: GitLab LoadTreeEntries not loading whole tree
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nikoksr committed Jun 4, 2020
1 parent ada481a commit 439337a
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions pkg/proji/repo/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 439337a

Please sign in to comment.