Adding Support for Resolving/Unresolving Discussions (#39)

This MR adds the ability to mark discussions as resolved or unresolved. This is important to the review process.
This commit is contained in:
Harrison (Harry) Cramer
2023-08-17 12:42:36 -04:00
committed by GitHub
parent 1676992266
commit d25c62ae9f
7 changed files with 130 additions and 35 deletions

View File

@@ -42,6 +42,7 @@ type EditCommentRequest struct {
Comment string `json:"comment"`
NoteId int `json:"note_id"`
DiscussionId string `json:"discussion_id"`
Resolved bool `json:"resolved"`
}
type CommentResponse struct {
@@ -158,26 +159,34 @@ func EditComment(w http.ResponseWriter, r *http.Request) {
return
}
options := gitlab.UpdateMergeRequestDiscussionNoteOptions{
Body: gitlab.String(editCommentRequest.Comment),
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)
}
note, res, err := c.git.Discussions.UpdateMergeRequestDiscussionNote(c.projectId, c.mergeId, editCommentRequest.DiscussionId, editCommentRequest.NoteId, &options)
if err != nil {
c.handleError(w, err, "Could not edit comment", res.StatusCode)
c.handleError(w, err, "Could not "+msg, res.StatusCode)
return
}
w.WriteHeader(res.StatusCode)
if res.StatusCode != http.StatusOK {
c.handleError(w, errors.New("Non-200 status code recieved"), "Could not edit comment", res.StatusCode)
c.handleError(w, errors.New("Non-200 status code recieved"), "Could not "+msg, res.StatusCode)
}
response := CommentResponse{
SuccessResponse: SuccessResponse{
Message: "Comment edited succesfully",
Message: "Comment updated succesfully",
Status: http.StatusOK,
},
Comment: note,