Change to HTTP Model (#5)

This commit is contained in:
Harrison (Harry) Cramer
2023-05-19 17:28:58 -07:00
committed by GitHub
parent fe0d09d582
commit 63fc025070
21 changed files with 689 additions and 430 deletions

View File

@@ -1,19 +1,18 @@
local Job = require("plenary.job")
local curl = require("plenary.curl")
local state = require("gitlab.state")
local notify = require("notify")
local discussions = require("gitlab.discussions")
local summary = require("gitlab.summary")
local keymaps = require("gitlab.keymaps")
local comment = require("gitlab.comment")
local approve = require("gitlab.approve")
local revoke = require("gitlab.revoke")
local job = require("gitlab.job")
local u = require("gitlab.utils")
-- Root Module Scope
local M = {}
M.summary = summary.summary
M.approve = approve.approve
M.revoke = revoke.revoke
M.approve = job.approve
M.revoke = job.revoke
M.create_comment = comment.create_comment
M.list_discussions = discussions.list_discussions
M.edit_comment = comment.edit_comment
@@ -21,8 +20,6 @@ M.delete_comment = comment.delete_comment
M.reply = discussions.reply
-- Builds the Go binary, initializes the plugin, fetches MR info
local projectData = {}
M.build = function(args)
if args == nil then args = {} end
local command = string.format("cd %s && make", state.BIN_PATH)
@@ -42,6 +39,9 @@ M.setup = function(args, build_only)
state.BIN = parent_dir .. "/bin"
if args == nil then args = {} end
if args.dev == true then
M.build(args)
end
local binExists = io.open(state.BIN, "r")
if not binExists or args.dev == true then
@@ -78,29 +78,34 @@ M.setup = function(args, build_only)
state.BASE_BRANCH = args.base_branch
end
local error_message = "Failed to set up gitlab.nvim, could not get project information."
if u.is_gitlab_repo() then
Job:new({
command = state.BIN,
args = { "info", state.PROJECT_ID },
on_stdout = function(_, line)
table.insert(projectData, line)
end,
on_stderr = u.print_error,
on_exit = function()
if projectData[1] ~= nil then
local parsed_ok, data = pcall(vim.json.decode, projectData[1])
if parsed_ok ~= true then
notify("Failed calling setup. Could not get project data.", "error")
else
state.INFO = data
local port = args.port or 21036
vim.fn.jobstart(state.BIN .. " " .. state.PROJECT_ID .. " " .. port, {
on_stdout = function(job_id)
if job_id <= 0 then
notify(error_message, "error")
return
else
local response_ok, response = pcall(curl.get, "localhost:" .. port .. "/info",
{ timeout = 750 })
if response == nil or not response_ok then
notify(error_message, "error")
return
end
local body = response.body
local parsed_ok, data = pcall(vim.json.decode, body)
if parsed_ok ~= true then
notify(error_message, "error")
return
end
state.INFO = data
keymaps.set_keymap_keys(args.keymaps)
keymaps.set_keymaps()
end
end,
}):start()
end
})
end
keymaps.set_keymap_keys(args.keymaps)
keymaps.set_keymaps()
end
M.current_file_path = function()