Feat: Edit PR Description (#22)

This MR makes it possible to edit the description. Non-breaking, will happen within the normal description popup.
This commit is contained in:
Harrison (Harry) Cramer
2023-08-14 20:37:36 -04:00
committed by GitHub
parent 35d5b619ce
commit 2028be2154
6 changed files with 107 additions and 20 deletions

View File

@@ -45,6 +45,7 @@ M.setup = function(args)
if not M.setPluginConfiguration(args) then return end -- Return if not a valid gitlab project
local command = state.BIN
.. " "
.. state.PROJECT_ID

View File

@@ -1,13 +1,14 @@
local state = require("gitlab.state")
local Popup = require("nui.popup")
local u = require("gitlab.utils")
local keymaps = require("gitlab.keymaps")
local summaryPopup = Popup(u.create_popup_state("Loading Summary...", "80%", "80%"))
local M = {}
local job = require("gitlab.job")
local state = require("gitlab.state")
local Popup = require("nui.popup")
local u = require("gitlab.utils")
local keymaps = require("gitlab.keymaps")
local descriptionPopup = Popup(u.create_popup_state("Loading Description...", "80%", "80%"))
local M = {}
M.summary = function()
M.summary = function()
if u.base_invalid() then return end
summaryPopup:mount()
descriptionPopup:mount()
local currentBuffer = vim.api.nvim_get_current_buf()
local title = state.INFO.title
local description = state.INFO.description
@@ -18,9 +19,17 @@ M.summary = function()
end
vim.schedule(function()
vim.api.nvim_buf_set_lines(currentBuffer, 0, -1, false, lines)
vim.api.nvim_buf_set_option(currentBuffer, "modifiable", false)
summaryPopup.border:set_text("top", title, "center")
keymaps.set_popup_keymaps(summaryPopup)
descriptionPopup.border:set_text("top", title, "center")
keymaps.set_popup_keymaps(descriptionPopup, M.edit_description)
end)
end
M.edit_description = function(text)
local jsonTable = { description = text }
local json = vim.json.encode(jsonTable)
job.run_job("mr", "PUT", json, function(data)
vim.notify(data.message, vim.log.levels.INFO)
state.INFO.description = data.mr.description
end)
end

View File

@@ -187,6 +187,7 @@ local create_popup_state = function(title, width, height)
buf_options = {
filetype = 'markdown'
},
relative = "editor",
enter = true,
focusable = true,
border = {