added a new file First major commit Successful POST of new comment 🚀 Updated README Updated README 📕 Added more infrastructure Creating async job More setup Getting arguments from Neovim -> Lua -> Golang Moved commands Added getProjectInfo command Adding make comment command Setting up arguments for MakeComment command Removed extraneous comments Setup basic function for adding comments Lint fixes Handling bad requests correctly Better formatting Printing success message Adding utility table print Set comment from popup UI Added mappings for closing and sending text Moved popup into separate file Added comment Cleaned up code and added approve command Initialize project information Removed extraneous import Don't initialize project in non-gitlab directories Setup approve command Set up revoke and approve commands correctly Cleaned up redundant code Moved get current branch command Reorganization of the code First attempt to add step installing Go binary Adjusted path to binary Added install bin check Do Lua method Fixed install step Tweaked binPath + bin Added basic readme information 📗 Removed .luarc.json file Adding diffview command Added string_starts function Made base branch configurable Added note to readme Fixed readme Added diffview dep to readme Update README.md Update README.md Update README.md Update README.md Renamed files Set up developer workflow Updated README Removed dev note Refactor and moving around files Fixed ft/after mappings Setup read command Added read summary command Got rid of filetype bindings and set up commands Set correct filetype for comment buffer Added read() command to README Updated review -> summary Fixed issue with diffview buffers Added command for getting and showing all comments (out of order) Better error message Adding more code to handle showing comments Added ability to jump from comment to specific changed buffer line Initial refactor Added simple comment action Fixed error message More cleanup Fixed bug with M.PROJECT_ID Leaving comment refactor Fixed comment Cleaned up old code Added missing exit command Check gitlab repo status before initialization Better help strings Added ListDiscussions command Added Go code Darkened metadata, filtered out non-real discussions Removed dummy log Sort the discussions by most recent activity Grab hash of current discussion Wired up reply action in Lua code Moved to NUI Table Adding basic jump-to-file ability More tweaks Allow jump anywhere in the tree Ability to reply directly in the buffer window Jump to location in file Don't jump if no refresh is set Cleaned up mappings + other code Get rid of gitlab CLI dependency Fixed discussions bug Don't initialize client on main/master branches Moved comment into separate module Moved lua modules into separate files Modularized library and state Slightly better error/exception handling Added license file Updated readme Moved into todo.md file Added todo file Standardized naming conventions (snake_case in Lua, camelCase in Go) Moved common popup state into utils folder Cleaned up keymapping functions Note on install Changing bin path Updated README Chnaged from success to info Redirect output to /dev/null on build Checking install code Removed print statement Slight reorganization Setting up delete comment Set up confirmation modal Passing in node ID to delete_comment Functioning comment deletion Added delete_comment command Updated README Furhter modularized discussion code Cleaned up and refactored reply code Update README.md Added ability to edit comments Updated todos Fixed main/master base branch issue Set up keybinding rules Updated todo.md Removed diffview dependency Slight cleanup 🧹 Trying something out... Trying something for the binary... Trying again Fixed install for non-lazy users Update README.md Update README.md Update README.md Update README.md Update README.md
208 lines
6.1 KiB
Lua
208 lines
6.1 KiB
Lua
local u = require("gitlab.utils")
|
|
local NuiTree = require("nui.tree")
|
|
local state = require("gitlab.state")
|
|
local Job = require("plenary.job")
|
|
local Popup = require("nui.popup")
|
|
local keymaps = require("gitlab.keymaps")
|
|
|
|
local M = {}
|
|
|
|
local replyPopup = Popup(u.create_popup_state("Reply", "80%", "80%"))
|
|
|
|
M.reply = function()
|
|
if u.base_invalid() then return end
|
|
replyPopup:mount()
|
|
keymaps.set_popup_keymaps(replyPopup, M.send_reply)
|
|
end
|
|
|
|
M.send_reply = function(text)
|
|
Job:new({
|
|
command = state.BIN,
|
|
args = {
|
|
"reply",
|
|
state.PROJECT_ID,
|
|
state.ACTIVE_DISCUSSION,
|
|
text,
|
|
},
|
|
on_stdout = function(_, line)
|
|
local note = vim.json.decode(line)
|
|
if note == nil then
|
|
require("notify")("There was an issue creating the note", "error")
|
|
return
|
|
end
|
|
|
|
local note_node = M.build_note(note)
|
|
note_node:expand()
|
|
|
|
state.tree:add_node(note_node, "-" .. state.ACTIVE_DISCUSSION)
|
|
vim.schedule(function()
|
|
state.tree:render()
|
|
local buf = vim.api.nvim_get_current_buf()
|
|
u.darken_metadata(buf, '')
|
|
require("notify")("Sent reply!")
|
|
end)
|
|
end,
|
|
on_stderr = u.print_error
|
|
}):start()
|
|
end
|
|
|
|
-- Places all of the discussions into a readable list
|
|
M.list_discussions = function()
|
|
if u.base_invalid() then return end
|
|
Job:new({
|
|
command = state.BIN,
|
|
args = { "listDiscussions", state.PROJECT_ID },
|
|
on_stdout = function(_, line)
|
|
local discussions = vim.json.decode(line)
|
|
M.discussions = discussions
|
|
vim.schedule(function()
|
|
vim.cmd.tabnew()
|
|
local buf = vim.api.nvim_create_buf(false, true)
|
|
vim.api.nvim_command("vsplit")
|
|
vim.api.nvim_buf_set_option(buf, 'filetype', 'markdown')
|
|
vim.api.nvim_set_current_buf(buf)
|
|
if discussions == nil then
|
|
require("notify")("No discussions found for this MR", "warn")
|
|
else
|
|
local allDiscussions = {}
|
|
for i, discussion in ipairs(discussions) do
|
|
local discussionChildren = {}
|
|
for _, note in ipairs(discussion.notes) do
|
|
local note_node = M.build_note(note)
|
|
if i == 1 then
|
|
note_node:expand()
|
|
end
|
|
table.insert(discussionChildren, note_node)
|
|
end
|
|
local discussionNode = NuiTree.Node({
|
|
text = discussion.id,
|
|
id = discussion.id,
|
|
is_discussion = true
|
|
},
|
|
discussionChildren)
|
|
if i == 1 then
|
|
discussionNode:expand()
|
|
end
|
|
table.insert(allDiscussions, discussionNode)
|
|
end
|
|
state.tree = NuiTree({ nodes = allDiscussions, bufnr = buf })
|
|
|
|
M.set_tree_keymaps(buf)
|
|
|
|
state.tree:render()
|
|
vim.api.nvim_buf_set_option(buf, 'filetype', 'markdown')
|
|
u.darken_metadata(buf, '')
|
|
if not is_refresh then
|
|
M.jump_to_file()
|
|
end
|
|
end
|
|
end)
|
|
end,
|
|
on_stderr = u.print_error,
|
|
}):start()
|
|
end
|
|
|
|
M.jump_to_file = function()
|
|
local node = state.tree:get_node()
|
|
if node == nil then return end
|
|
|
|
local childrenIds = node:get_child_ids()
|
|
-- We have selected a note node
|
|
if node.file_name ~= nil then
|
|
u.jump_to_file(node.file_name, node.line_number)
|
|
elseif node.is_body then
|
|
local parentId = node:get_parent_id()
|
|
local parent = state.tree:get_node(parentId)
|
|
if parent == nil then return end
|
|
u.jump_to_file(parent.file_name, parent.line_number)
|
|
else
|
|
local firstChild = state.tree:get_node(childrenIds[1])
|
|
if firstChild == nil then return end
|
|
u.jump_to_file(firstChild.file_name, firstChild.line_number)
|
|
end
|
|
end
|
|
|
|
M.set_tree_keymaps = function(buf)
|
|
-- Jump to file location where comment was left
|
|
vim.keymap.set('n', state.keymaps.discussion_tree.jump_to_location, function()
|
|
M.jump_to_file()
|
|
end, { buffer = true })
|
|
|
|
vim.keymap.set('n', state.keymaps.discussion_tree.edit_comment, function()
|
|
require("gitlab.comment").edit_comment()
|
|
end, { buffer = true })
|
|
|
|
vim.keymap.set('n', state.keymaps.discussion_tree.delete_comment, function()
|
|
require("gitlab.comment").delete_comment()
|
|
end)
|
|
|
|
-- Expand/collapse the current node
|
|
vim.keymap.set('n', state.keymaps.discussion_tree.toggle_node, function()
|
|
local node = state.tree:get_node()
|
|
if node == nil then return end
|
|
local children = node:get_child_ids()
|
|
if node == nil then return end
|
|
if node:is_expanded() then
|
|
node:collapse()
|
|
for _, child in ipairs(children) do
|
|
state.tree:get_node(child):collapse()
|
|
end
|
|
else
|
|
for _, child in ipairs(children) do
|
|
state.tree:get_node(child):expand()
|
|
end
|
|
node:expand()
|
|
end
|
|
|
|
|
|
state.tree:render()
|
|
u.darken_metadata(buf, '')
|
|
end,
|
|
{ buffer = true })
|
|
|
|
vim.keymap.set('n', 'r', function()
|
|
local node = state.tree:get_node()
|
|
if node == nil then return end
|
|
|
|
-- Get closest discussion parent
|
|
if node.is_body then
|
|
local parentId = node:get_parent_id()
|
|
local parent = state.tree:get_node(parentId)
|
|
if parent == nil then return end
|
|
parentId = parent:get_parent_id()
|
|
parent = state.tree:get_node(parentId)
|
|
if parent == nil then return end
|
|
node = parent
|
|
elseif node.is_note then
|
|
local parentId = node:get_parent_id()
|
|
local parent = state.tree:get_node(parentId)
|
|
if parent == nil then return end
|
|
node = parent
|
|
end
|
|
|
|
state.ACTIVE_DISCUSSION = node.id
|
|
M.reply()
|
|
end, { buffer = true })
|
|
end
|
|
|
|
M.build_note = function(note)
|
|
local noteTextNodes = {}
|
|
for bodyLine in note.body:gmatch("[^\n]+") do
|
|
table.insert(noteTextNodes, NuiTree.Node({ text = bodyLine, is_body = true }, {}))
|
|
end
|
|
local noteHeader = "@" ..
|
|
note.author.username .. " on " .. u.format_date(note.created_at)
|
|
local note_node = NuiTree.Node(
|
|
{
|
|
text = noteHeader,
|
|
id = note.id,
|
|
file_name = note.position.new_path,
|
|
line_number = note.position.new_line,
|
|
is_note = true
|
|
}, noteTextNodes)
|
|
|
|
return note_node
|
|
end
|
|
|
|
return M
|