feat: implement pagination for MR discussions

This uses the gitlab.Scan function to iterate over all discussions and
handle errors after the iterator is exhausted. The test for non-200s is
no longer needed as the Scan function transforms such responses to
standard errors.
This commit is contained in:
Jakub F. Bortlík
2026-02-17 18:31:05 +01:00
parent 3d2828a950
commit 129b83bef4
2 changed files with 6 additions and 18 deletions

View File

@@ -2,6 +2,7 @@ package app
import (
"net/http"
"slices"
"sort"
"sync"
"time"
@@ -90,18 +91,16 @@ func (a discussionsListerService) ServeHTTP(w http.ResponseWriter, r *http.Reque
},
}
discussions, res, err := a.client.ListMergeRequestDiscussions(a.projectInfo.ProjectId, a.projectInfo.MergeId, &mergeRequestDiscussionOptions)
it, hasErr := gitlab.Scan(func(p gitlab.PaginationOptionFunc) ([]*gitlab.Discussion, *gitlab.Response, error) {
return a.client.ListMergeRequestDiscussions(a.projectInfo.ProjectId, a.projectInfo.MergeId, &mergeRequestDiscussionOptions, p)
})
discussions := slices.Collect(it)
if err != nil {
if err := hasErr(); err != nil {
handleError(w, err, "Could not list discussions", http.StatusInternalServerError)
return
}
if res.StatusCode >= 300 {
handleError(w, GenericError{r.URL.Path}, "Could not list discussions", res.StatusCode)
return
}
/* Filter out any discussions started by a blacklisted user
and system discussions, then return them sorted by created date */
var unlinkedDiscussions []*gitlab.Discussion