Slight cleanup + simplification of init state

This commit is contained in:
Harrison Cramer
2023-08-18 19:07:43 -04:00
parent 57b3f12a2f
commit 2846dd3239
2 changed files with 7 additions and 27 deletions

View File

@@ -73,7 +73,6 @@ M.start_server = function(callback)
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
elseif callback ~= nil then elseif callback ~= nil then
callback() callback()
end end
@@ -125,24 +124,16 @@ M.setPluginConfiguration = function(args)
end end
local file = assert(io.open(config_file_path, "r")) local file = assert(io.open(config_file_path, "r"))
local property = {} local properties = {}
for line in file:lines() do for line in file:lines() do
for key, value in string.gmatch(line, "(.-)=(.-)$") do for key, value in string.gmatch(line, "(.-)=(.-)$") do
property[key] = value properties[key] = value
end end
end end
local project_id = property["project_id"] state.PROJECT_ID = properties.project_id
local gitlab_url = property["gitlab_url"] state.AUTH_TOKEN = properties.auth_token or os.getenv("GITLAB_TOKEN")
local auth_token = property["auth_token"] state.GITLAB_URL = properties.gitlab_url or "https://gitlab.com"
state.PROJECT_ID = project_id
state.AUTH_TOKEN = auth_token or os.getenv("GITLAB_TOKEN")
state.GITLAB_URL = gitlab_url or "https://gitlab.com"
if state.AUTH_TOKEN == nil then
error("Missing authentication token for Gitlab")
end
if state.AUTH_TOKEN == nil then if state.AUTH_TOKEN == nil then
error("Missing authentication token for Gitlab") error("Missing authentication token for Gitlab")
@@ -177,8 +168,8 @@ end
-- Root Module Scope -- Root Module Scope
M.summary = M.ensureState(summary.summary) M.summary = M.ensureState(summary.summary)
M.approve = M.ensureState(job.approve) M.approve = M.ensureState(function() job.run_job("approve", "POST") end)
M.revoke = M.ensureState(job.revoke) M.revoke = M.ensureState(function() job.run_job("revoke", "POST") end)
M.list_discussions = M.ensureState(discussions.list_discussions) M.list_discussions = M.ensureState(discussions.list_discussions)
M.create_comment = M.ensureState(comment.create_comment) M.create_comment = M.ensureState(comment.create_comment)
M.edit_comment = M.ensureState(comment.edit_comment) M.edit_comment = M.ensureState(comment.edit_comment)

View File

@@ -41,15 +41,4 @@ M.run_job = function(endpoint, method, body, callback)
}):start() }):start()
end end
-- Approves the current merge request
M.approve = function()
M.run_job("approve", "POST")
end
-- Revokes approval for the current merge request
M.revoke = function()
M.run_job("revoke", "POST")
end
return M return M