From 2846dd32391a27f6c4a08b6ca5b6e966013275a4 Mon Sep 17 00:00:00 2001 From: Harrison Cramer Date: Fri, 18 Aug 2023 19:07:43 -0400 Subject: [PATCH] Slight cleanup + simplification of init state --- lua/gitlab/init.lua | 23 +++++++---------------- lua/gitlab/job.lua | 11 ----------- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/lua/gitlab/init.lua b/lua/gitlab/init.lua index d39b29a..db11137 100644 --- a/lua/gitlab/init.lua +++ b/lua/gitlab/init.lua @@ -73,7 +73,6 @@ M.start_server = function(callback) on_stdout = function(job_id) if job_id <= 0 then vim.notify("Could not start gitlab.nvim binary", vim.log.levels.ERROR) - return elseif callback ~= nil then callback() end @@ -125,24 +124,16 @@ M.setPluginConfiguration = function(args) end local file = assert(io.open(config_file_path, "r")) - local property = {} + local properties = {} for line in file:lines() do for key, value in string.gmatch(line, "(.-)=(.-)$") do - property[key] = value + properties[key] = value end end - local project_id = property["project_id"] - local gitlab_url = property["gitlab_url"] - local auth_token = property["auth_token"] - - 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 + state.PROJECT_ID = properties.project_id + state.AUTH_TOKEN = properties.auth_token or os.getenv("GITLAB_TOKEN") + state.GITLAB_URL = properties.gitlab_url or "https://gitlab.com" if state.AUTH_TOKEN == nil then error("Missing authentication token for Gitlab") @@ -177,8 +168,8 @@ end -- Root Module Scope M.summary = M.ensureState(summary.summary) -M.approve = M.ensureState(job.approve) -M.revoke = M.ensureState(job.revoke) +M.approve = M.ensureState(function() job.run_job("approve", "POST") end) +M.revoke = M.ensureState(function() job.run_job("revoke", "POST") end) M.list_discussions = M.ensureState(discussions.list_discussions) M.create_comment = M.ensureState(comment.create_comment) M.edit_comment = M.ensureState(comment.edit_comment) diff --git a/lua/gitlab/job.lua b/lua/gitlab/job.lua index 7c42d0a..a5d8be9 100644 --- a/lua/gitlab/job.lua +++ b/lua/gitlab/job.lua @@ -41,15 +41,4 @@ M.run_job = function(endpoint, method, body, callback) }):start() 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