This reverts commit f15711edab.
This commit is contained in:
committed by
GitHub
parent
f15711edab
commit
ade9f81426
@@ -44,18 +44,18 @@ func (c *Client) ListDiscussions() ([]*gitlab.Discussion, int, error) {
|
|||||||
return nil, res.Response.StatusCode, fmt.Errorf("Listing discussions failed: %w", err)
|
return nil, res.Response.StatusCode, fmt.Errorf("Listing discussions failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var diffNotes []*gitlab.Discussion
|
var realDiscussions []*gitlab.Discussion
|
||||||
for i := 0; i < len(discussions); i++ {
|
for i := 0; i < len(discussions); i++ {
|
||||||
notes := discussions[i].Notes
|
notes := discussions[i].Notes
|
||||||
for j := 0; j < len(notes); j++ {
|
for j := 0; j < len(notes); j++ {
|
||||||
if !notes[j].System {
|
if notes[j].Type == gitlab.NoteTypeValue("DiffNote") {
|
||||||
diffNotes = append(diffNotes, discussions[i])
|
realDiscussions = append(realDiscussions, discussions[i])
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sortedDiscussions := SortableDiscussions(diffNotes)
|
sortedDiscussions := SortableDiscussions(realDiscussions)
|
||||||
sort.Sort(sortedDiscussions)
|
sort.Sort(sortedDiscussions)
|
||||||
|
|
||||||
return sortedDiscussions, http.StatusOK, nil
|
return sortedDiscussions, http.StatusOK, nil
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
local u = require("gitlab.utils")
|
local u = require("gitlab.utils")
|
||||||
local NuiTree = require("nui.tree")
|
local NuiTree = require("nui.tree")
|
||||||
local job = require("gitlab.job")
|
local job = require("gitlab.job")
|
||||||
local state = require("gitlab.state")
|
local state = require("gitlab.state")
|
||||||
local Job = require("plenary.job")
|
local Job = require("plenary.job")
|
||||||
local Popup = require("nui.popup")
|
local Popup = require("nui.popup")
|
||||||
local keymaps = require("gitlab.keymaps")
|
local keymaps = require("gitlab.keymaps")
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local replyPopup = Popup(u.create_popup_state("Reply", "80%", "80%"))
|
local replyPopup = Popup(u.create_popup_state("Reply", "80%", "80%"))
|
||||||
|
|
||||||
M.reply = function()
|
M.reply = function()
|
||||||
if u.base_invalid() then return end
|
if u.base_invalid() then return end
|
||||||
replyPopup:mount()
|
replyPopup:mount()
|
||||||
keymaps.set_popup_keymaps(replyPopup, M.send_reply)
|
keymaps.set_popup_keymaps(replyPopup, M.send_reply)
|
||||||
end
|
end
|
||||||
|
|
||||||
M.send_reply = function(text)
|
M.send_reply = function(text)
|
||||||
local escapedText = string.gsub(text, "\n", "\\n")
|
local escapedText = string.gsub(text, "\n", "\\n")
|
||||||
local json = string.format('{"discussion_id": "%s", "reply": "%s"}', state.ACTIVE_DISCUSSION, escapedText)
|
local json = string.format('{"discussion_id": "%s", "reply": "%s"}', state.ACTIVE_DISCUSSION, escapedText)
|
||||||
job.run_job("reply", "POST", json, function(data)
|
job.run_job("reply", "POST", json, function(data)
|
||||||
@@ -33,15 +33,6 @@ M.send_reply = function(text)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Adds node to discussion tree
|
|
||||||
local function addToDiscussionTree(i, note, discussionChildren)
|
|
||||||
local note_node = M.build_note(note)
|
|
||||||
if i == 1 then
|
|
||||||
note_node:expand()
|
|
||||||
end
|
|
||||||
table.insert(discussionChildren, note_node)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Places all of the discussions into a readable list
|
-- Places all of the discussions into a readable list
|
||||||
M.list_discussions = function()
|
M.list_discussions = function()
|
||||||
if u.base_invalid() then return end
|
if u.base_invalid() then return end
|
||||||
@@ -72,10 +63,11 @@ M.list_discussions = function()
|
|||||||
for i, discussion in ipairs(data.discussions) do
|
for i, discussion in ipairs(data.discussions) do
|
||||||
local discussionChildren = {}
|
local discussionChildren = {}
|
||||||
for _, note in ipairs(discussion.notes) do
|
for _, note in ipairs(discussion.notes) do
|
||||||
if note.position then
|
local note_node = M.build_note(note)
|
||||||
addToDiscussionTree(i, note, discussionChildren)
|
if i == 1 then
|
||||||
else
|
note_node:expand()
|
||||||
end
|
end
|
||||||
|
table.insert(discussionChildren, note_node)
|
||||||
end
|
end
|
||||||
local discussionNode = NuiTree.Node({
|
local discussionNode = NuiTree.Node({
|
||||||
text = discussion.id,
|
text = discussion.id,
|
||||||
@@ -95,6 +87,7 @@ M.list_discussions = function()
|
|||||||
state.tree:render()
|
state.tree:render()
|
||||||
vim.api.nvim_buf_set_option(buf, 'filetype', 'markdown')
|
vim.api.nvim_buf_set_option(buf, 'filetype', 'markdown')
|
||||||
u.darken_metadata(buf, '')
|
u.darken_metadata(buf, '')
|
||||||
|
M.jump_to_file()
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
@@ -105,7 +98,6 @@ M.list_discussions = function()
|
|||||||
}):start()
|
}):start()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
M.jump_to_file = function()
|
M.jump_to_file = function()
|
||||||
local node = state.tree:get_node()
|
local node = state.tree:get_node()
|
||||||
if node == nil then return end
|
if node == nil then return end
|
||||||
@@ -197,22 +189,14 @@ M.build_note = function(note)
|
|||||||
local noteHeader = "@" ..
|
local noteHeader = "@" ..
|
||||||
note.author.username .. " on " .. u.format_date(note.created_at)
|
note.author.username .. " on " .. u.format_date(note.created_at)
|
||||||
|
|
||||||
local file_name
|
local line_number = note.position.new_line or note.position.old_line
|
||||||
local line_number
|
|
||||||
if (type(note.position) == 'table') then
|
|
||||||
line_number = note.position.new_line or note.position.old_line
|
|
||||||
file_name = note.position.new_path
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local note_node = NuiTree.Node(
|
local note_node = NuiTree.Node(
|
||||||
{
|
{
|
||||||
text = noteHeader,
|
text = noteHeader,
|
||||||
id = note.id,
|
id = note.id,
|
||||||
file_name = file_name,
|
file_name = note.position.new_path,
|
||||||
line_number = line_number,
|
line_number = line_number,
|
||||||
is_note = true,
|
is_note = true
|
||||||
is_code_comment = type(note.position) == 'table'
|
|
||||||
}, noteTextNodes)
|
}, noteTextNodes)
|
||||||
|
|
||||||
return note_node
|
return note_node
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
local function jump_to_file(filename, line_number)
|
local function jump_to_file(filename, line_number)
|
||||||
if line_number == nil or filename == nil then return end
|
if line_number == nil then line_number = 1 end
|
||||||
vim.api.nvim_command("wincmd l")
|
vim.api.nvim_command("wincmd l")
|
||||||
local bufnr = vim.fn.bufnr(filename)
|
local bufnr = vim.fn.bufnr(filename)
|
||||||
if bufnr ~= -1 then
|
if bufnr ~= -1 then
|
||||||
|
|||||||
Reference in New Issue
Block a user