Don't error when there are no discussions
This commit is contained in:
@@ -55,6 +55,10 @@ M.list_discussions = function()
|
|||||||
args = { "listDiscussions", state.PROJECT_ID },
|
args = { "listDiscussions", state.PROJECT_ID },
|
||||||
on_stdout = function(_, line)
|
on_stdout = function(_, line)
|
||||||
local discussions = vim.json.decode(line)
|
local discussions = vim.json.decode(line)
|
||||||
|
if (type(discussions) == 'userdata') then
|
||||||
|
notify("No discussions found for this MR", "warn")
|
||||||
|
return
|
||||||
|
end
|
||||||
M.discussions = discussions
|
M.discussions = discussions
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
vim.cmd.tabnew()
|
vim.cmd.tabnew()
|
||||||
@@ -62,41 +66,35 @@ M.list_discussions = function()
|
|||||||
vim.api.nvim_command("vsplit")
|
vim.api.nvim_command("vsplit")
|
||||||
vim.api.nvim_buf_set_option(buf, 'filetype', 'markdown')
|
vim.api.nvim_buf_set_option(buf, 'filetype', 'markdown')
|
||||||
vim.api.nvim_set_current_buf(buf)
|
vim.api.nvim_set_current_buf(buf)
|
||||||
if discussions == nil then
|
local allDiscussions = {}
|
||||||
notify("No discussions found for this MR", "warn")
|
for i, discussion in ipairs(discussions) do
|
||||||
else
|
local discussionChildren = {}
|
||||||
local allDiscussions = {}
|
for _, note in ipairs(discussion.notes) do
|
||||||
for i, discussion in ipairs(discussions) do
|
local note_node = M.build_note(note)
|
||||||
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
|
if i == 1 then
|
||||||
discussionNode:expand()
|
note_node:expand()
|
||||||
end
|
end
|
||||||
table.insert(allDiscussions, discussionNode)
|
table.insert(discussionChildren, note_node)
|
||||||
end
|
end
|
||||||
state.tree = NuiTree({ nodes = allDiscussions, bufnr = buf })
|
local discussionNode = NuiTree.Node({
|
||||||
|
text = discussion.id,
|
||||||
M.set_tree_keymaps(buf)
|
id = discussion.id,
|
||||||
|
is_discussion = true
|
||||||
state.tree:render()
|
},
|
||||||
vim.api.nvim_buf_set_option(buf, 'filetype', 'markdown')
|
discussionChildren)
|
||||||
u.darken_metadata(buf, '')
|
if i == 1 then
|
||||||
if not is_refresh then
|
discussionNode:expand()
|
||||||
M.jump_to_file()
|
|
||||||
end
|
end
|
||||||
|
table.insert(allDiscussions, discussionNode)
|
||||||
end
|
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, '')
|
||||||
|
M.jump_to_file()
|
||||||
end)
|
end)
|
||||||
end,
|
end,
|
||||||
on_stderr = u.print_error,
|
on_stderr = u.print_error,
|
||||||
|
|||||||
Reference in New Issue
Block a user