Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue comments: implement pagination & show all comments #264

Merged
merged 1 commit into from
Dec 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions internal/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,30 @@ func IssueListDiscussions(project string, issueNum int) ([]*gitlab.Discussion, e
return nil, err
}

discussions, _, err := lab.Discussions.ListIssueDiscussions(p.ID, issueNum, &gitlab.ListIssueDiscussionsOptions{})
if err != nil {
return nil, err
discussions := []*gitlab.Discussion{}
opt := &gitlab.ListIssueDiscussionsOptions{
// 100 is the maximum allowed by the API
PerPage: 100,
Page: 1,
}

for {
// get a page of discussions from the API ...
d, resp, err := lab.Discussions.ListIssueDiscussions(p.ID, issueNum, opt)
if err != nil {
return nil, err
}

// ... and add them to our collection of discussions
discussions = append(discussions, d...)

// if we've seen all the pages, then we can break here
if opt.Page >= resp.TotalPages {
break
}

// otherwise, update the page number to get the next page.
opt.Page = resp.NextPage
}

return discussions, nil
Expand Down