Fixes: Resolve entire discussion thread (#95)
This MR adjusts the comment/discussion resolution action to resolve the entire discussion thread, rather than an individual comment, which is the expected behavior during an MR review.
This commit is contained in:
@@ -214,15 +214,8 @@ func EditComment(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
options := gitlab.UpdateMergeRequestDiscussionNoteOptions{}
|
||||
|
||||
/* The PATCH can either be to the resolved status of
|
||||
the discussion or or the text of the comment */
|
||||
msg := "edit comment"
|
||||
if editCommentRequest.Comment == "" {
|
||||
options.Resolved = &editCommentRequest.Resolved
|
||||
msg = "update discussion status"
|
||||
} else {
|
||||
options.Body = gitlab.String(editCommentRequest.Comment)
|
||||
}
|
||||
options.Body = gitlab.String(editCommentRequest.Comment)
|
||||
|
||||
note, res, err := c.git.Discussions.UpdateMergeRequestDiscussionNote(c.projectId, c.mergeId, editCommentRequest.DiscussionId, editCommentRequest.NoteId, &options)
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ func main() {
|
||||
m.Handle("/revoke", withGitlabContext(http.HandlerFunc(RevokeHandler), c))
|
||||
m.Handle("/info", withGitlabContext(http.HandlerFunc(InfoHandler), c))
|
||||
m.Handle("/discussions", withGitlabContext(http.HandlerFunc(ListDiscussionsHandler), c))
|
||||
m.Handle("/discussion/resolve", withGitlabContext(http.HandlerFunc(DiscussionResolveHandler), c))
|
||||
m.Handle("/comment", withGitlabContext(http.HandlerFunc(CommentHandler), c))
|
||||
m.Handle("/reply", withGitlabContext(http.HandlerFunc(ReplyHandler), c))
|
||||
m.Handle("/members", withGitlabContext(http.HandlerFunc(ProjectMembersHandler), c))
|
||||
|
||||
69
cmd/resolve_discussion.go
Normal file
69
cmd/resolve_discussion.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
)
|
||||
|
||||
type DiscussionResolveRequest struct {
|
||||
DiscussionID string `json:"discussion_id"`
|
||||
Resolved bool `json:"resolved"`
|
||||
}
|
||||
|
||||
func DiscussionResolveHandler(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodPut:
|
||||
DiscussionResolve(w, r)
|
||||
default:
|
||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||
}
|
||||
}
|
||||
func DiscussionResolve(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
c := r.Context().Value("client").(Client)
|
||||
|
||||
body, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
c.handleError(w, err, "Could not read request body", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
defer r.Body.Close()
|
||||
var resolveDiscussionRequest DiscussionResolveRequest
|
||||
err = json.Unmarshal(body, &resolveDiscussionRequest)
|
||||
if err != nil {
|
||||
c.handleError(w, err, "Could not read JSON from request", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
_, res, err := c.git.Discussions.ResolveMergeRequestDiscussion(
|
||||
c.projectId,
|
||||
c.mergeId,
|
||||
resolveDiscussionRequest.DiscussionID,
|
||||
&gitlab.ResolveMergeRequestDiscussionOptions{Resolved: &resolveDiscussionRequest.Resolved},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
c.handleError(w, err, "Could not update resolve status of discussion", res.StatusCode)
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
var message string
|
||||
if resolveDiscussionRequest.Resolved {
|
||||
message = "Discussion resolved"
|
||||
} else {
|
||||
message = "Discussion unresolved"
|
||||
}
|
||||
response := SuccessResponse{
|
||||
Message: message,
|
||||
Status: http.StatusOK,
|
||||
}
|
||||
|
||||
err = json.NewEncoder(w).Encode(response)
|
||||
if err != nil {
|
||||
c.handleError(w, err, "Could not encode response", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user