Release 2.5.1 (#271)
* feat: Support for custom authentication provider functions (#270) * feat: Support for adding "draft" notes to the review, and publishing them, either individually or all at once. Addresses feature request #223. * feat: Lets users select + checkout a merge request directly within Neovim, without exiting to the terminal * fix: Checks that the remote feature branch exists and is up-to-date before creating a MR, starting a review, or opening the MR summary (#278) * docs: We require some state from Diffview, this shows how to load that state prior to installing w/ Packer. Fixes #94. This is a #MINOR release. --------- Co-authored-by: Jakub F. Bortlík <jakub.bortlik@proton.me> Co-authored-by: sunfuze <sunfuze.1989@gmail.com> Co-authored-by: Patrick Pichler <mail@patrickpichler.dev>
This commit is contained in:
committed by
GitHub
parent
f10c4ebb8f
commit
cf6ccddce3
@@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -11,28 +10,8 @@ import (
|
||||
)
|
||||
|
||||
type PostCommentRequest struct {
|
||||
Comment string `json:"comment"`
|
||||
FileName string `json:"file_name"`
|
||||
NewLine *int `json:"new_line,omitempty"`
|
||||
OldLine *int `json:"old_line,omitempty"`
|
||||
HeadCommitSHA string `json:"head_commit_sha"`
|
||||
BaseCommitSHA string `json:"base_commit_sha"`
|
||||
StartCommitSHA string `json:"start_commit_sha"`
|
||||
Type string `json:"type"`
|
||||
LineRange *LineRange `json:"line_range,omitempty"`
|
||||
}
|
||||
|
||||
/* LineRange represents the range of a note. */
|
||||
type LineRange struct {
|
||||
StartRange *LinePosition `json:"start"`
|
||||
EndRange *LinePosition `json:"end"`
|
||||
}
|
||||
|
||||
/* LinePosition represents a position in a line range. Unlike the Gitlab struct, this does not contain LineCode with a sha1 of the filename */
|
||||
type LinePosition struct {
|
||||
Type string `json:"type"`
|
||||
OldLine int `json:"old_line"`
|
||||
NewLine int `json:"new_line"`
|
||||
Comment string `json:"comment"`
|
||||
PositionData
|
||||
}
|
||||
|
||||
type DeleteCommentRequest struct {
|
||||
@@ -53,6 +32,15 @@ type CommentResponse struct {
|
||||
Discussion *gitlab.Discussion `json:"discussion"`
|
||||
}
|
||||
|
||||
/* CommentWithPosition is a comment with an (optional) position data value embedded in it. The position data will be non-nil for range-based comments. */
|
||||
type CommentWithPosition struct {
|
||||
PositionData PositionData
|
||||
}
|
||||
|
||||
func (comment CommentWithPosition) GetPositionData() PositionData {
|
||||
return comment.PositionData
|
||||
}
|
||||
|
||||
/* commentHandler creates, edits, and deletes discussions (comments, multi-line comments) */
|
||||
func (a *api) commentHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
@@ -133,46 +121,10 @@ func (a *api) postComment(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
/* If we are leaving a comment on a line, leave position. Otherwise,
|
||||
we are leaving a note (unlinked comment) */
|
||||
var friendlyName = "Note"
|
||||
if postCommentRequest.FileName != "" {
|
||||
friendlyName = "Comment"
|
||||
opt.Position = &gitlab.PositionOptions{
|
||||
PositionType: &postCommentRequest.Type,
|
||||
StartSHA: &postCommentRequest.StartCommitSHA,
|
||||
HeadSHA: &postCommentRequest.HeadCommitSHA,
|
||||
BaseSHA: &postCommentRequest.BaseCommitSHA,
|
||||
NewPath: &postCommentRequest.FileName,
|
||||
OldPath: &postCommentRequest.FileName,
|
||||
NewLine: postCommentRequest.NewLine,
|
||||
OldLine: postCommentRequest.OldLine,
|
||||
}
|
||||
|
||||
if postCommentRequest.LineRange != nil {
|
||||
friendlyName = "Multiline Comment"
|
||||
shaFormat := "%x_%d_%d"
|
||||
startFilenameSha := fmt.Sprintf(
|
||||
shaFormat,
|
||||
sha1.Sum([]byte(postCommentRequest.FileName)),
|
||||
postCommentRequest.LineRange.StartRange.OldLine,
|
||||
postCommentRequest.LineRange.StartRange.NewLine,
|
||||
)
|
||||
endFilenameSha := fmt.Sprintf(
|
||||
shaFormat,
|
||||
sha1.Sum([]byte(postCommentRequest.FileName)),
|
||||
postCommentRequest.LineRange.EndRange.OldLine,
|
||||
postCommentRequest.LineRange.EndRange.NewLine,
|
||||
)
|
||||
opt.Position.LineRange = &gitlab.LineRangeOptions{
|
||||
Start: &gitlab.LinePositionOptions{
|
||||
Type: &postCommentRequest.LineRange.StartRange.Type,
|
||||
LineCode: &startFilenameSha,
|
||||
},
|
||||
End: &gitlab.LinePositionOptions{
|
||||
Type: &postCommentRequest.LineRange.EndRange.Type,
|
||||
LineCode: &endFilenameSha,
|
||||
},
|
||||
}
|
||||
}
|
||||
if postCommentRequest.FileName != "" {
|
||||
commentWithPositionData := CommentWithPosition{postCommentRequest.PositionData}
|
||||
opt.Position = buildCommentPosition(commentWithPositionData)
|
||||
}
|
||||
|
||||
discussion, res, err := a.client.CreateMergeRequestDiscussion(a.projectInfo.ProjectId, a.projectInfo.MergeId, &opt)
|
||||
@@ -190,7 +142,7 @@ func (a *api) postComment(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
response := CommentResponse{
|
||||
SuccessResponse: SuccessResponse{
|
||||
Message: fmt.Sprintf("%s created successfully", friendlyName),
|
||||
Message: "Comment created successfully",
|
||||
Status: http.StatusOK,
|
||||
},
|
||||
Comment: discussion.Notes[0],
|
||||
|
||||
Reference in New Issue
Block a user