BREAKING CHANGE: Setup refactor and code cleanup

This MR makes several major tweaks to the codebase. Primarily it adjusts
the setup steps for the application so that rather than providing just
the project ID in the `.gitlab.nvim` file, users can also provide a
vareity of other settings, such as auth_token, base_branch, and so
forth. This is to make the project more extensible in the future.

This MR also fixes a variety of issues with error handling in the code,
primarily in the request/response model between the Lua jobs and the
Golang server.

BREAKING CHANGE: Modifies `.gitlab.nvim` and setup steps
This commit is contained in:
Harrison (Harry) Cramer
2023-08-06 11:21:39 -04:00
committed by Harrison Cramer
parent ade9f81426
commit 4f0d4b49ef
16 changed files with 281 additions and 293 deletions

View File

@@ -9,25 +9,31 @@ M.run_job = function(endpoint, method, body, callback)
table.insert(args, 1, "-d")
table.insert(args, 2, body)
end
-- This handler will handle all responses from the Go server. Anything with a successful
-- status will call the callback (if it is supplied for the job). Otherwise, it will print out the
-- success message or error message and details from the Go server.
Job:new({
command = "curl",
args = args,
on_stdout = function(_, output)
local data_ok, data = pcall(vim.json.decode, output)
if data_ok and data ~= nil then
local status = (data.status >= 200 and data.status < 300) and "success" or "error"
if callback ~= nil then
callback(data)
vim.defer_fn(function()
local data_ok, data = pcall(vim.json.decode, output)
if data_ok and data ~= nil then
local status = (data.status >= 200 and data.status < 300) and "success" or "error"
if status == "success" and callback ~= nil then
callback(data)
elseif status == "success" then
local message = string.format("%s", data.message)
vim.notify(message, vim.log.levels.INFO)
else
local message = string.format("%s: %s", data.message, data.details)
vim.notify(message, vim.log.levels.DEBUG)
end
else
vim.defer_fn(function()
vim.notify(data.message, vim.log.levels.DEBUG)
end, 0)
end
else
vim.defer_fn(function()
vim.notify("Could not parse command output!", vim.log.levels.ERROR)
end, 0)
end
end
end, 0)
end,
on_stderr = function(_, output)
vim.defer_fn(function()