Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking: Deprecate Delta Reviewer #81

Merged
merged 10 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 5 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ https://github.com/harrisoncramer/gitlab.nvim/assets/32515581/50f44eaf-5f99-4cb3
## Quick Start

1. Install Go
2. Install reviewer: <a href="https://github.com/dandavison/delta">delta</a> or <a href="https://github.com/sindrets/diffview.nvim">diffview</a>
3. Add configuration (see Installation section)
4. Checkout your feature branch: `git checkout feature-branch`
5. Open Neovim
Expand All @@ -36,12 +35,13 @@ return {
dependencies = {
"MunifTanjim/nui.nvim",
"nvim-lua/plenary.nvim",
"sindrets/diffview.nvim",
"stevearc/dressing.nvim", -- Recommended but not required. Better UI for pickers.
enabled = true,
},
build = function () require("gitlab.server").build(true) end, -- Builds the Go binary
config = function()
require("gitlab").setup() -- Uses delta reviewer by default
require("gitlab").setup()
end,
}
```
Expand All @@ -54,6 +54,7 @@ use {
requires = {
"MunifTanjim/nui.nvim",
"nvim-lua/plenary.nvim"
"sindrets/diffview.nvim",
},
run = function() require("gitlab.server").build(true) end,
config = function()
Expand Down Expand Up @@ -87,7 +88,6 @@ require("gitlab").setup({
port = nil, -- The port of the Go server, which runs in the background, if omitted or `nil` the port will be chosen automatically
log_path = vim.fn.stdpath("cache") .. "/gitlab.nvim.log", -- Log path for the Go server
debug = { go_request = false, go_response = false }, -- Which values to log
reviewer = "delta", -- The reviewer type ("delta" or "diffview")
attachment_dir = nil, -- The local directory for files (see the "summary" section)
popup = { -- The popup for comment creation, editing, and replying
exit = "<Esc>",
Expand All @@ -109,19 +109,6 @@ require("gitlab").setup({
resolved = '✓', -- Symbol to show next to resolved discussions
unresolved = '✖', -- Symbol to show next to unresolved discussions
},
review_pane = { -- Specific settings for different reviewers
delta = {
added_file = "", -- The symbol to show next to added files
modified_file = "", -- The symbol to show next to modified files
removed_file = "", -- The symbol to show next to removed files
}
},
dialogue = { -- The confirmation dialogue for deleting comments
focus_next = { "j", "<Down>", "<Tab>" },
focus_prev = { "k", "<Up>", "<S-Tab>" },
close = { "<Esc>", "<C-c>" },
submit = { "<CR>", "<Space>" },
},
pipeline = {
created = "",
pending = "",
Expand Down Expand Up @@ -170,14 +157,12 @@ The `review` action will open a diff of the changes. You can leave comments usin
```lua
require("gitlab").review()
require("gitlab").create_comment()
require("gitlab").create_multiline_comment() -- Only supported for diffview reviewer
require("gitlab").create_comment_suggestion() -- Only supported for diffview reviewer
require("gitlab").create_multiline_comment()
require("gitlab").create_comment_suggestion()
```

For suggesting changes you can use `create_comment_suggestion` in visual mode which works similar to `create_multiline_comment` but prefills the comment window with gitlab [suggest changes](https://docs.gitlab.com/ee/user/project/merge_requests/reviews/suggestions.html) code block with prefilled code from visual selection.

The reviewer is Delta by default, but you can configure the plugin to use Diffview instead.

### Discussions and Notes

Gitlab groups threads of comments together into "discussions."
Expand Down
4 changes: 2 additions & 2 deletions lua/gitlab/actions/assignees_and_reviewers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ M.add_popup = function(type)
table.insert(current_ids, choice.id)
local body = { ids = current_ids }
job.run_job("/mr/" .. type, "PUT", body, function(data)
vim.notify(data.message, vim.log.levels.INFO)
u.notify(data.message, vim.log.levels.INFO)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this prefixes all messages with gitlab.nvim: which is great for usability IMO

state.INFO[plural] = data[plural]
end)
end)
Expand All @@ -59,7 +59,7 @@ M.delete_popup = function(type)
local ids = u.extract(M.filter_eligible(current, { choice }), "id")
local body = { ids = ids }
job.run_job("/mr/" .. type, "PUT", body, function(data)
vim.notify(data.message, vim.log.levels.INFO)
u.notify(data.message, vim.log.levels.INFO)
state.INFO[plural] = data[plural]
end)
end)
Expand Down
13 changes: 4 additions & 9 deletions lua/gitlab/actions/comment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ M.create_comment_suggestion = function()
local backticks = "```"
local selected_lines = reviewer.get_lines(start_line, end_line)

if selected_lines == nil then
-- TODO: remove when delta is supported
return
end

for line in ipairs(selected_lines) do
if string.match(line, "^```$") then
backticks = "````"
Expand All @@ -65,7 +60,7 @@ M.create_comment_suggestion = function()
suggestion_start = backticks .. "suggestion:-" .. range .. "+0"
else
-- This should never happen afaik
vim.notify("Unexpected suggestion position", vim.log.levels.ERROR)
u.notify("Unexpected suggestion position", vim.log.levels.ERROR)
return
end
suggestion_start = suggestion_start
Expand Down Expand Up @@ -117,14 +112,14 @@ end
---@param unlinked boolean | nil if true, the comment is not linked to a line
M.confirm_create_comment = function(text, range, unlinked)
if text == nil then
vim.notify("Reviewer did not provide text of change", vim.log.levels.ERROR)
u.notify("Reviewer did not provide text of change", vim.log.levels.ERROR)
return
end

if unlinked then
local body = { comment = text }
job.run_job("/comment", "POST", body, function(data)
vim.notify("Note created!", vim.log.levels.INFO)
u.notify("Note created!", vim.log.levels.INFO)
discussions.add_discussion({ data = data, unlinked = true })
end)
return
Expand All @@ -149,7 +144,7 @@ M.confirm_create_comment = function(text, range, unlinked)
}

job.run_job("/comment", "POST", body, function(data)
vim.notify("Comment created!", vim.log.levels.INFO)
u.notify("Comment created!", vim.log.levels.INFO)
discussions.add_discussion({ data = data, unlinked = false })
end)
end
Expand Down
105 changes: 39 additions & 66 deletions lua/gitlab/actions/discussions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
-- and marking discussions as resolved/unresolved.
local Split = require("nui.split")
local Popup = require("nui.popup")
local Menu = require("nui.menu")
local NuiTree = require("nui.tree")
local Layout = require("nui.layout")
local job = require("gitlab.job")
Expand Down Expand Up @@ -40,7 +39,7 @@ M.toggle = function()

job.run_job("/discussions", "POST", { blacklist = state.settings.discussion_tree.blacklist }, function(data)
if type(data.discussions) ~= "table" and type(data.unlinked_discussions) ~= "table" then
vim.notify("No discussions or notes for this MR", vim.log.levels.WARN)
u.notify("No discussions or notes for this MR", vim.log.levels.WARN)
return
end

Expand Down Expand Up @@ -86,82 +85,56 @@ 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)
vim.notify("Sent reply!", vim.log.levels.INFO)
u.notify("Sent reply!", vim.log.levels.INFO)
M.add_reply_to_tree(tree, data.note, discussion_id)
end)
end
end

-- This function (settings.discussion_tree.delete_comment) will trigger a popup prompting you to delete the current comment
M.delete_comment = function(tree, unlinked)
local menu = Menu({
position = "50%",
size = {
width = 25,
},
border = {
style = "single",
text = {
top = "Delete Comment?",
top_align = "center",
},
},
win_options = {
winhighlight = "Normal:Normal,FloatBorder:Normal",
},
}, {
lines = {
Menu.item("Confirm"),
Menu.item("Cancel"),
},
max_width = 20,
keymap = {
focus_next = state.settings.dialogue.focus_next,
focus_prev = state.settings.dialogue.focus_prev,
close = state.settings.dialogue.close,
submit = state.settings.dialogue.submit,
},
on_submit = function(item)
M.send_deletion(tree, item, unlinked)
end,
})
menu:mount()
vim.ui.select({ "Confirm", "Cancel" }, {
prompt = "Delete comment?",
}, function(choice)
if choice == "Cancel" then
return
end
M.send_deletion(tree, unlinked)
end)
end

-- This function will actually send the deletion to Gitlab
-- when you make a selection, and re-render the tree
M.send_deletion = function(tree, item, unlinked)
if item.text == "Confirm" then
local current_node = tree:get_node()
M.send_deletion = function(tree, unlinked)
local current_node = tree:get_node()

local note_node = M.get_note_node(tree, current_node)
local root_node = M.get_root_node(tree, current_node)
local note_id = note_node.is_root and root_node.root_note_id or note_node.id
local note_node = M.get_note_node(tree, current_node)
local root_node = M.get_root_node(tree, current_node)
local note_id = note_node.is_root and root_node.root_note_id or note_node.id

local body = { discussion_id = root_node.id, note_id = note_id }
local body = { discussion_id = root_node.id, note_id = note_id }

job.run_job("/comment", "DELETE", body, function(data)
vim.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
tree:render()
job.run_job("/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
tree:render()
else
if unlinked then
M.unlinked_discussions = u.remove_first_value(M.unlinked_discussions)
M.rebuild_unlinked_discussion_tree()
else
if unlinked then
M.unlinked_discussions = u.remove_first_value(M.unlinked_discussions)
M.rebuild_unlinked_discussion_tree()
else
M.discussions = u.remove_first_value(M.discussions)
M.rebuild_discussion_tree()
end
M.discussions = u.remove_first_value(M.discussions)
M.rebuild_discussion_tree()
end
M.switch_can_edit_bufs(true)
M.add_empty_titles({
{ M.linked_section_bufnr, M.discussions, "No Discussions for this MR" },
{ M.unlinked_section_bufnr, M.unlinked_discussions, "No Notes (Unlinked Discussions) for this MR" },
})
M.switch_can_edit_bufs(false)
end)
end
end
M.switch_can_edit_bufs(true)
M.add_empty_titles({
{ M.linked_section_bufnr, M.discussions, "No Discussions for this MR" },
{ M.unlinked_section_bufnr, M.unlinked_discussions, "No Notes (Unlinked Discussions) for this MR" },
})
M.switch_can_edit_bufs(false)
end)
end

-- This function (settings.discussion_tree.edit_comment) will open the edit popup for the current comment in the discussion tree
Expand Down Expand Up @@ -199,7 +172,7 @@ M.send_edits = function(discussion_id, note_id, unlinked)
comment = text,
}
job.run_job("/comment", "PATCH", body, function(data)
vim.notify(data.message, vim.log.levels.INFO)
u.notify(data.message, vim.log.levels.INFO)
if unlinked then
M.unlinked_discussions = M.replace_text(M.unlinked_discussions, discussion_id, note_id, text)
M.rebuild_unlinked_discussion_tree()
Expand All @@ -225,7 +198,7 @@ M.toggle_resolved = function(tree)
}

job.run_job("/comment", "PATCH", body, function(data)
vim.notify(data.message, vim.log.levels.INFO)
u.notify(data.message, vim.log.levels.INFO)
M.redraw_resolved_status(tree, note, not note.resolved)
end)
end
Expand All @@ -234,7 +207,7 @@ end
M.jump_to_reviewer = function(tree)
local file_name, new_line, old_line, error = M.get_note_location(tree)
if error ~= nil then
vim.notify(error, vim.log.levels.ERROR)
u.notify(error, vim.log.levels.ERROR)
return
end
reviewer.jump(file_name, new_line, old_line)
Expand All @@ -244,7 +217,7 @@ end
M.jump_to_file = function(tree)
local file_name, new_line, old_line, error = M.get_note_location(tree)
if error ~= nil then
vim.notify(error, vim.log.levels.ERROR)
u.notify(error, vim.log.levels.ERROR)
return
end
vim.cmd.tabnew()
Expand Down
8 changes: 4 additions & 4 deletions lua/gitlab/actions/miscellaneous.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@ local M = {}
M.open_in_browser = function()
local url = state.INFO.web_url
if url == nil then
vim.notify("Could not get Gitlab URL", vim.log.levels.ERROR)
u.notify("Could not get Gitlab URL", vim.log.levels.ERROR)
return
end
if vim.fn.has("mac") == 1 then
vim.fn.jobstart({ "open", url })
elseif vim.fn.has("unix") == 1 then
vim.fn.jobstart({ "xdg-open", url })
else
vim.notify("Opening a Gitlab URL is not supported on this OS!", vim.log.levels.ERROR)
u.notify("Opening a Gitlab URL is not supported on this OS!", vim.log.levels.ERROR)
end
end

M.attach_file = function()
local attachment_dir = state.settings.attachment_dir
if not attachment_dir or attachment_dir == "" then
vim.notify("Must provide valid attachment_dir in plugin setup", vim.log.levels.ERROR)
u.notify("Must provide valid attachment_dir in plugin setup", vim.log.levels.ERROR)
return
end

local files = u.list_files_in_folder(attachment_dir)

if files == nil then
vim.notify(string.format("Could not list files in %s", attachment_dir), vim.log.levels.ERROR)
u.notify(string.format("Could not list files in %s", attachment_dir), vim.log.levels.ERROR)
return
end

Expand Down
Loading