Skip to content
Open
Show file tree
Hide file tree
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
15 changes: 7 additions & 8 deletions cmd/app/list_discussions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
"net/http"
"slices"
"sort"
"sync"
"time"
Expand Down Expand Up @@ -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
Expand All @@ -124,7 +123,7 @@ func (a discussionsListerService) ServeHTTP(w http.ResponseWriter, r *http.Reque

/* Collect IDs in order to fetch emojis */
var noteIds []int64
for _, discussion := range discussions {
for _, discussion := range slices.Concat(linkedDiscussions, unlinkedDiscussions) {
for _, note := range discussion.Notes {
noteIds = append(noteIds, note.ID)
}
Expand Down
11 changes: 0 additions & 11 deletions cmd/app/list_discussions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,6 @@ func TestListDiscussions(t *testing.T) {
data, _ := getFailData(t, svc, request)
checkErrorFromGitlab(t, data, "Could not list discussions")
})
t.Run("Handles non-200s from Gitlab client", func(t *testing.T) {
request := makeRequest(t, http.MethodPost, "/mr/discussions/list", DiscussionsRequest{Blacklist: []string{}})
svc := middleware(
discussionsListerService{testProjectData, fakeDiscussionsLister{testBase: testBase{status: http.StatusSeeOther}}},
withMr(testProjectData, fakeMergeRequestLister{}),
withPayloadValidation(methodToPayload{http.MethodPost: newPayload[DiscussionsRequest]}),
withMethodCheck(http.MethodPost),
)
data, _ := getFailData(t, svc, request)
checkNon200(t, data, "Could not list discussions", "/mr/discussions/list")
})
Comment on lines -130 to -140
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gitlab.Scan handles errors differently, i.e., it doesn't set a non-200 status code on the response, so this test is no longer valid.

t.Run("Handles error from emoji service", func(t *testing.T) {
request := makeRequest(t, http.MethodPost, "/mr/discussions/list", DiscussionsRequest{Blacklist: []string{}})
svc := middleware(
Expand Down