Use job wrapper for INFO call
This commit is contained in:
@@ -104,6 +104,7 @@ func (c *Client) handleError(w http.ResponseWriter, err error, message string, s
|
|||||||
response := ErrorResponse{
|
response := ErrorResponse{
|
||||||
Message: message,
|
Message: message,
|
||||||
Details: err.Error(),
|
Details: err.Error(),
|
||||||
|
Status: status,
|
||||||
}
|
}
|
||||||
json.NewEncoder(w).Encode(response)
|
json.NewEncoder(w).Encode(response)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ func InfoHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
msg, err := c.Info()
|
msg, err := c.Info()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.handleError(w, err, "Could not get info", http.StatusBadRequest)
|
c.handleError(w, err, "Could not get project info and initialize gitlab.nvim plugin", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,38 +44,21 @@ M.setup = function(args)
|
|||||||
.. " "
|
.. " "
|
||||||
.. state.LOG_PATH
|
.. state.LOG_PATH
|
||||||
|
|
||||||
vim.fn.jobstart(
|
|
||||||
command,
|
vim.fn.jobstart(command, {
|
||||||
{
|
on_stdout = function(job_id)
|
||||||
on_stdout = function(job_id)
|
if job_id <= 0 then
|
||||||
if job_id <= 0 then
|
vim.notify("Could not start gitlab.nvim binary", vim.log.levels.ERROR)
|
||||||
vim.notify("Could not start gitlab.nvim binary", vim.log.levels.ERROR)
|
return
|
||||||
return
|
else
|
||||||
else
|
job.run_job("info", "GET", nil, function(data)
|
||||||
local response_ok, response = pcall(
|
|
||||||
curl.get,
|
|
||||||
"localhost:" .. state.PORT .. "/info",
|
|
||||||
{ timeout = 750 }
|
|
||||||
)
|
|
||||||
if response == nil or not response_ok then
|
|
||||||
vim.notify("The gitlab.nvim server did not respond", vim.log.levels.ERROR)
|
|
||||||
print("Ran command: " .. command)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local body = response.body
|
|
||||||
local parsed_ok, data = pcall(vim.json.decode, body)
|
|
||||||
if parsed_ok ~= true then
|
|
||||||
vim.notify("The gitlab.nvim server returned an invalid response to the /info endpoint",
|
|
||||||
vim.log.levels.ERROR)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
state.INFO = data
|
state.INFO = data
|
||||||
keymaps.set_keymap_keys(args.keymaps)
|
keymaps.set_keymap_keys(args.keymaps)
|
||||||
keymaps.set_keymaps()
|
keymaps.set_keymaps()
|
||||||
end
|
end)
|
||||||
end,
|
end
|
||||||
}
|
end,
|
||||||
)
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Builds the Go binary
|
-- Builds the Go binary
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ M.run_job = function(endpoint, method, body, callback)
|
|||||||
vim.notify(message, vim.log.levels.INFO)
|
vim.notify(message, vim.log.levels.INFO)
|
||||||
else
|
else
|
||||||
local message = string.format("%s: %s", data.message, data.details)
|
local message = string.format("%s: %s", data.message, data.details)
|
||||||
vim.notify(message, vim.log.levels.DEBUG)
|
vim.notify(message, vim.log.levels.ERROR)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
vim.notify("Could not parse command output!", vim.log.levels.ERROR)
|
vim.notify("Could not parse command output!", vim.log.levels.ERROR)
|
||||||
|
|||||||
Reference in New Issue
Block a user