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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user