Set up comment to allow for comments on unmodified lines
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/xanzy/go-gitlab"
|
"github.com/xanzy/go-gitlab"
|
||||||
@@ -55,24 +56,60 @@ func (c *Client) Comment() error {
|
|||||||
|
|
||||||
time := time.Now()
|
time := time.Now()
|
||||||
|
|
||||||
options := gitlab.CreateMergeRequestDiscussionOptions{
|
/* This is necessary since we do not know whether the comment is on a line that
|
||||||
Body: &comment,
|
has been changed or not. Making all three of these API calls will let us leave
|
||||||
CreatedAt: &time,
|
the comment regardless. See the Gitlab documentation: https://docs.gitlab.com/ee/api/discussions.html#create-a-new-thread-in-the-merge-request-diff */
|
||||||
Position: &gitlab.NotePosition{
|
wg := sync.WaitGroup{}
|
||||||
PositionType: "text",
|
wg.Add(3)
|
||||||
BaseSHA: diffVersionInfo[0].BaseCommitSHA,
|
|
||||||
HeadSHA: diffVersionInfo[0].HeadCommitSHA,
|
resultChannel := make(chan *gitlab.Discussion, 3)
|
||||||
StartSHA: diffVersionInfo[0].StartCommitSHA,
|
|
||||||
NewPath: fileName,
|
for i := 0; i < 3; i++ {
|
||||||
OldPath: fileName,
|
ii := i
|
||||||
NewLine: lineNumberInt,
|
go func() {
|
||||||
},
|
defer wg.Done()
|
||||||
|
options := gitlab.CreateMergeRequestDiscussionOptions{
|
||||||
|
Body: &comment,
|
||||||
|
CreatedAt: &time,
|
||||||
|
Position: &gitlab.NotePosition{
|
||||||
|
PositionType: "text",
|
||||||
|
BaseSHA: diffVersionInfo[0].BaseCommitSHA,
|
||||||
|
HeadSHA: diffVersionInfo[0].HeadCommitSHA,
|
||||||
|
StartSHA: diffVersionInfo[0].StartCommitSHA,
|
||||||
|
NewPath: fileName,
|
||||||
|
OldPath: fileName,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if ii == 0 {
|
||||||
|
options.Position.NewLine = lineNumberInt
|
||||||
|
} else if ii == 1 {
|
||||||
|
options.Position.OldLine = lineNumberInt
|
||||||
|
} else {
|
||||||
|
options.Position.NewLine = lineNumberInt
|
||||||
|
options.Position.OldLine = lineNumberInt
|
||||||
|
}
|
||||||
|
|
||||||
|
discussion, _, _ := c.git.Discussions.CreateMergeRequestDiscussion(c.projectId, c.mergeId, &options)
|
||||||
|
resultChannel <- discussion
|
||||||
|
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _, err = c.git.Discussions.CreateMergeRequestDiscussion(c.projectId, c.mergeId, &options)
|
go func() {
|
||||||
|
wg.Wait()
|
||||||
|
close(resultChannel)
|
||||||
|
}()
|
||||||
|
|
||||||
if err != nil {
|
var createdDiscussion *gitlab.Discussion
|
||||||
return fmt.Errorf("Could not leave comment: %w", err)
|
for discussion := range resultChannel {
|
||||||
|
if discussion != nil {
|
||||||
|
createdDiscussion = discussion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if createdDiscussion == nil {
|
||||||
|
return fmt.Errorf("Could not leave comment")
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Left Comment: " + comment[0:min(len(comment), 25)] + "...")
|
fmt.Println("Left Comment: " + comment[0:min(len(comment), 25)] + "...")
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ local M = {}
|
|||||||
local commentPopup = Popup(u.create_popup_state("Comment", "40%", "60%"))
|
local commentPopup = Popup(u.create_popup_state("Comment", "40%", "60%"))
|
||||||
local editPopup = Popup(u.create_popup_state("Edit Comment", "80%", "80%"))
|
local editPopup = Popup(u.create_popup_state("Edit Comment", "80%", "80%"))
|
||||||
|
|
||||||
|
M.line_status = nil
|
||||||
|
|
||||||
M.create_comment = function()
|
M.create_comment = function()
|
||||||
if u.base_invalid() then return end
|
if u.base_invalid() then return end
|
||||||
commentPopup:mount()
|
commentPopup:mount()
|
||||||
|
|||||||
@@ -42,9 +42,6 @@ M.setup = function(args, build_only)
|
|||||||
state.BIN = parent_dir .. "/bin"
|
state.BIN = parent_dir .. "/bin"
|
||||||
|
|
||||||
if args == nil then args = {} end
|
if args == nil then args = {} end
|
||||||
if args.dev == true then
|
|
||||||
M.build(args)
|
|
||||||
end
|
|
||||||
|
|
||||||
local binExists = io.open(state.BIN, "r")
|
local binExists = io.open(state.BIN, "r")
|
||||||
if not binExists or args.dev == true then
|
if not binExists or args.dev == true then
|
||||||
@@ -65,7 +62,7 @@ M.setup = function(args, build_only)
|
|||||||
|
|
||||||
-- Override project_id in setup call if configuration file is present
|
-- Override project_id in setup call if configuration file is present
|
||||||
local config_file_path = vim.fn.getcwd() .. "/.gitlab.nvim"
|
local config_file_path = vim.fn.getcwd() .. "/.gitlab.nvim"
|
||||||
local config_file_content = read_file(config_file_path)
|
local config_file_content = u.read_file(config_file_path)
|
||||||
if config_file_content ~= nil then
|
if config_file_content ~= nil then
|
||||||
args.project_id = config_file_content
|
args.project_id = config_file_content
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ M.merge_tables = function(defaults, overrides)
|
|||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
function read_file(file_path)
|
local read_file = function(file_path)
|
||||||
local file = io.open(file_path, "r")
|
local file = io.open(file_path, "r")
|
||||||
if file == nil then
|
if file == nil then
|
||||||
return nil
|
return nil
|
||||||
@@ -232,5 +232,6 @@ M.print_success = print_success
|
|||||||
M.print_error = print_error
|
M.print_error = print_error
|
||||||
M.create_popup_state = create_popup_state
|
M.create_popup_state = create_popup_state
|
||||||
M.exit = exit
|
M.exit = exit
|
||||||
|
M.read_file = read_file
|
||||||
M.P = P
|
M.P = P
|
||||||
return M
|
return M
|
||||||
|
|||||||
Reference in New Issue
Block a user