This MR adds the ability to add files to comments, notes, replys, and MR descriptions via a picker. The file will get uploaded to Gitlab and the filepath will be automatically added into the current popup buffer at the current line. You can then save the changes with the normal save functionality.
41 lines
1.5 KiB
Lua
41 lines
1.5 KiB
Lua
-- This module is responsible for the MR description
|
|
-- This lets the user open the description in a popup and
|
|
-- send edits to the description back to Gitlab
|
|
local Popup = require("nui.popup")
|
|
local job = require("gitlab.job")
|
|
local state = require("gitlab.state")
|
|
local miscellaneous = require("gitlab.actions.miscellaneous")
|
|
local u = require("gitlab.utils")
|
|
local M = {}
|
|
|
|
local descriptionPopup = Popup(u.create_popup_state("Loading Description...", "80%", "80%"))
|
|
|
|
-- The function will render the MR description in a popup
|
|
M.summary = function()
|
|
descriptionPopup:mount()
|
|
local currentBuffer = vim.api.nvim_get_current_buf()
|
|
local title = state.INFO.title
|
|
local description = state.INFO.description
|
|
local lines = {}
|
|
for line in description:gmatch("[^\n]+") do
|
|
table.insert(lines, line)
|
|
table.insert(lines, "")
|
|
end
|
|
vim.schedule(function()
|
|
vim.api.nvim_buf_set_lines(currentBuffer, 0, -1, false, lines)
|
|
descriptionPopup.border:set_text("top", title, "center")
|
|
state.set_popup_keymaps(descriptionPopup, M.edit_description, miscellaneous.attach_file)
|
|
end)
|
|
end
|
|
|
|
-- This function will PUT the new description to the Go server
|
|
M.edit_description = function(text)
|
|
local body = { description = text }
|
|
job.run_job("/mr/description", "PUT", body, function(data)
|
|
vim.notify(data.message, vim.log.levels.INFO)
|
|
state.INFO.description = data.mr.description
|
|
end)
|
|
end
|
|
|
|
return M
|