Adding Support for Resolving/Unresolving Discussions (#39)
This MR adds the ability to mark discussions as resolved or unresolved. This is important to the review process.
This commit is contained in:
committed by
GitHub
parent
1676992266
commit
d25c62ae9f
@@ -35,7 +35,7 @@ M.list_discussions = function()
|
||||
return
|
||||
end
|
||||
|
||||
local splitState = state.DISCUSSION_SPLIT
|
||||
local splitState = state.DISCUSSION.SPLIT
|
||||
splitState.buf_options = { modifiable = false }
|
||||
local split = NuiSplit(splitState)
|
||||
split:mount()
|
||||
@@ -84,6 +84,10 @@ M.set_tree_keymaps = function(buf)
|
||||
require("gitlab.comment").delete_comment()
|
||||
end, { buffer = true })
|
||||
|
||||
vim.keymap.set('n', state.keymaps.discussion_tree.toggle_resolved, function()
|
||||
require("gitlab.comment").toggle_resolved()
|
||||
end, { buffer = true })
|
||||
|
||||
-- Expand/collapse the current node
|
||||
vim.keymap.set('n', state.keymaps.discussion_tree.toggle_node, function()
|
||||
local node = state.tree:get_node()
|
||||
@@ -134,7 +138,7 @@ M.get_note_node = function(node)
|
||||
end
|
||||
end
|
||||
|
||||
M.build_note_body = function(note)
|
||||
M.build_note_body = function(note, resolve_info)
|
||||
local text_nodes = {}
|
||||
for bodyLine in note.body:gmatch("[^\n]+") do
|
||||
local line = u.attach_uuid(bodyLine)
|
||||
@@ -145,23 +149,26 @@ M.build_note_body = function(note)
|
||||
}, {}))
|
||||
end
|
||||
|
||||
local noteHeader = "@" ..
|
||||
note.author.username .. " " .. u.format_date(note.created_at)
|
||||
local resolve_symbol = ''
|
||||
if resolve_info ~= nil and resolve_info.resolvable then
|
||||
resolve_symbol = resolve_info.resolved and state.SYMBOLS.resolved or state.SYMBOLS.unresolved
|
||||
end
|
||||
|
||||
local noteHeader = "@" .. note.author.username .. " " .. u.format_date(note.created_at) .. " " .. resolve_symbol
|
||||
|
||||
return noteHeader, text_nodes
|
||||
end
|
||||
|
||||
M.build_note = function(note)
|
||||
local text, text_nodes = M.build_note_body(note)
|
||||
M.build_note = function(note, resolve_info)
|
||||
local text, text_nodes = M.build_note_body(note, resolve_info)
|
||||
local line_number = note.position.new_line or note.position.old_line
|
||||
local note_node = NuiTree.Node(
|
||||
{
|
||||
text = text,
|
||||
id = note.id,
|
||||
file_name = note.position.new_path,
|
||||
line_number = line_number,
|
||||
is_note = true
|
||||
}, text_nodes)
|
||||
local note_node = NuiTree.Node({
|
||||
text = text,
|
||||
id = note.id,
|
||||
file_name = note.position.new_path,
|
||||
line_number = line_number,
|
||||
is_note = true,
|
||||
}, text_nodes)
|
||||
|
||||
return note_node, text, text_nodes
|
||||
end
|
||||
@@ -212,14 +219,18 @@ M.add_discussions_to_table = function(discussions)
|
||||
local root_file_name = ''
|
||||
local root_id = 0
|
||||
local root_text_nodes = {}
|
||||
local resolvable = false
|
||||
local resolved = false
|
||||
|
||||
for j, note in ipairs(discussion.notes) do
|
||||
if j == 1 then
|
||||
__, root_text, root_text_nodes = M.build_note(note)
|
||||
__, root_text, root_text_nodes = M.build_note(note, { resolved = note.resolved, resolvable = note.resolvable })
|
||||
root_file_name = note.position.new_path
|
||||
root_line_number = note.position.new_line or note.position.old_line
|
||||
root_id = discussion.id
|
||||
root_note_id = note.id
|
||||
resolvable = note.resolvable
|
||||
resolved = note.resolved
|
||||
else -- Otherwise insert it as a child node...
|
||||
local note_node = M.build_note(note)
|
||||
table.insert(discussion_children, note_node)
|
||||
@@ -236,6 +247,8 @@ M.add_discussions_to_table = function(discussions)
|
||||
root_note_id = root_note_id,
|
||||
file_name = root_file_name,
|
||||
line_number = root_line_number,
|
||||
resolvable = resolvable,
|
||||
resolved = resolved
|
||||
}, body)
|
||||
|
||||
table.insert(t, root_node)
|
||||
|
||||
Reference in New Issue
Block a user