Feat: Upload Files (#59)

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.
This commit is contained in:
Harrison (Harry) Cramer
2023-09-08 10:02:01 -04:00
committed by GitHub
parent 45329f4d69
commit 4e473dab7e
11 changed files with 166 additions and 11 deletions

View File

@@ -1,5 +1,7 @@
local state = require("gitlab.state")
local M = {}
local state = require("gitlab.state")
local u = require("gitlab.utils")
local job = require("gitlab.job")
local M = {}
M.open_in_browser = function()
local url = state.INFO.web_url
@@ -16,4 +18,33 @@ M.open_in_browser = function()
end
end
M.attach_file = function()
local attachment_dir = state.settings.attachment_dir
if not attachment_dir or attachment_dir == '' then
vim.notify("Must provide valid attachment_dir in plugin setup", vim.log.levels.ERROR)
return
end
local files = u.list_files_in_folder(attachment_dir)
if files == nil then
vim.notify(string.format("Could not list files in %s", attachment_dir), vim.log.levels.ERROR)
return
end
vim.ui.select(files, {
prompt = 'Choose attachment',
}, function(choice)
if not choice then return end
local full_path = attachment_dir .. (u.is_windows() and "\\" or "/") .. choice
local body = { file_path = full_path, file_name = choice }
job.run_job("/mr/attachment", "POST", body, function(data)
local markdown = data.markdown
local current_line = u.get_current_line_number()
local bufnr = vim.api.nvim_get_current_buf()
vim.api.nvim_buf_set_lines(bufnr, current_line - 1, current_line, false, { markdown })
end)
end)
end
return M