Feat: Create Merge Request (#149)
- Adds the ability to create MRs to the plugin - Adds the ability to jump to specific discussions/notes in the browser - Fixes stale icons - Adds debug keybinding for discussion tree for developers
This commit is contained in:
committed by
GitHub
parent
35f0bc16a5
commit
37a53842d0
@@ -37,7 +37,7 @@ local M = {
|
||||
---callback with data
|
||||
---@param callback (fun(data: DiscussionData): nil)?
|
||||
M.load_discussions = function(callback)
|
||||
job.run_job("/discussions/list", "POST", { blacklist = state.settings.discussion_tree.blacklist }, function(data)
|
||||
job.run_job("/mr/discussions/list", "POST", { blacklist = state.settings.discussion_tree.blacklist }, function(data)
|
||||
M.discussions = data.discussions ~= vim.NIL and data.discussions or {}
|
||||
M.unlinked_discussions = data.unlinked_discussions ~= vim.NIL and data.unlinked_discussions or {}
|
||||
if type(callback) == "function" then
|
||||
@@ -52,7 +52,7 @@ M.initialize_discussions = function()
|
||||
-- Setup callback to refresh discussion data, discussion signs and diagnostics whenever the reviewed file changes.
|
||||
reviewer.set_callback_for_file_changed(M.refresh_discussion_data)
|
||||
-- Setup callback to clear signs and diagnostics whenever reviewer is left.
|
||||
reviewer.set_callback_for_reviewer_leave(signs.clear_signs_and_discussions)
|
||||
reviewer.set_callback_for_reviewer_leave(signs.clear_signs_and_diagnostics)
|
||||
end
|
||||
|
||||
---Refresh discussion data, signs, diagnostics, and winbar with new data from API
|
||||
@@ -209,7 +209,7 @@ end
|
||||
M.send_reply = function(tree, discussion_id)
|
||||
return function(text)
|
||||
local body = { discussion_id = discussion_id, reply = text }
|
||||
job.run_job("/reply", "POST", body, function(data)
|
||||
job.run_job("/mr/reply", "POST", body, function(data)
|
||||
u.notify("Sent reply!", vim.log.levels.INFO)
|
||||
M.add_reply_to_tree(tree, data.note, discussion_id)
|
||||
M.load_discussions()
|
||||
@@ -239,7 +239,7 @@ M.send_deletion = function(tree, unlinked)
|
||||
|
||||
local body = { discussion_id = root_node.id, note_id = tonumber(note_id) }
|
||||
|
||||
job.run_job("/comment", "DELETE", body, function(data)
|
||||
job.run_job("/mr/comment", "DELETE", body, function(data)
|
||||
u.notify(data.message, vim.log.levels.INFO)
|
||||
if not note_node.is_root then
|
||||
tree:remove_node("-" .. note_id) -- Note is not a discussion root, safe to remove
|
||||
@@ -301,7 +301,7 @@ M.send_edits = function(discussion_id, note_id, unlinked)
|
||||
note_id = note_id,
|
||||
comment = text,
|
||||
}
|
||||
job.run_job("/comment", "PATCH", body, function(data)
|
||||
job.run_job("/mr/comment", "PATCH", body, function(data)
|
||||
u.notify(data.message, vim.log.levels.INFO)
|
||||
M.rebuild_discussion_tree()
|
||||
if unlinked then
|
||||
@@ -327,7 +327,7 @@ M.toggle_discussion_resolved = function(tree)
|
||||
resolved = not note.resolved,
|
||||
}
|
||||
|
||||
job.run_job("/discussions/resolve", "PUT", body, function(data)
|
||||
job.run_job("/mr/discussions/resolve", "PUT", body, function(data)
|
||||
u.notify(data.message, vim.log.levels.INFO)
|
||||
M.redraw_resolved_status(tree, note, not note.resolved)
|
||||
M.refresh_discussion_data()
|
||||
@@ -572,6 +572,12 @@ M.set_tree_keymaps = function(tree, bufnr, unlinked)
|
||||
end
|
||||
end, { buffer = bufnr, desc = "Jump to reviewer" })
|
||||
end
|
||||
vim.keymap.set("n", state.settings.discussion_tree.open_in_browser, function()
|
||||
M.open_in_browser(tree)
|
||||
end, { buffer = bufnr, desc = "Open the note in your browser" })
|
||||
vim.keymap.set("n", "<leader>p", function()
|
||||
M.print_node(tree)
|
||||
end, { buffer = bufnr, desc = "dev_ Print current node (for debugging)" })
|
||||
end
|
||||
|
||||
M.redraw_resolved_status = function(tree, note, mark_resolved)
|
||||
@@ -683,4 +689,26 @@ M.get_note_location = function(tree)
|
||||
nil
|
||||
end
|
||||
|
||||
---@param tree NuiTree
|
||||
M.open_in_browser = function(tree)
|
||||
local current_node = tree:get_node()
|
||||
local note_node = M.get_note_node(tree, current_node)
|
||||
if note_node == nil then
|
||||
return
|
||||
end
|
||||
local url = note_node.url
|
||||
if url == nil then
|
||||
u.notify("Could not get URL of note", vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
|
||||
u.open_in_browser(url)
|
||||
end
|
||||
|
||||
-- For developers!
|
||||
M.print_node = function(tree)
|
||||
local current_node = tree:get_node()
|
||||
vim.print(current_node)
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user