Add/Remove Reviewers and Assignees (#38)

Adds APIs for the ability to add or remove reviewers and assignees to a merge request. The eligible reviewers and assignees are pulled from the current members of a project.
This commit is contained in:
Harrison (Harry) Cramer
2023-08-16 21:42:53 -04:00
committed by GitHub
parent 6274746d4b
commit 844e093294
10 changed files with 368 additions and 44 deletions

View File

@@ -1,13 +1,18 @@
local state = require("gitlab.state")
local discussions = require("gitlab.discussions")
local summary = require("gitlab.summary")
local keymaps = require("gitlab.keymaps")
local comment = require("gitlab.comment")
local job = require("gitlab.job")
local u = require("gitlab.utils")
local state = require("gitlab.state")
local discussions = require("gitlab.discussions")
local summary = require("gitlab.summary")
local assignees_and_reviewers = require("gitlab.assignees_and_reviewers")
local keymaps = require("gitlab.keymaps")
local comment = require("gitlab.comment")
local job = require("gitlab.job")
local u = require("gitlab.utils")
-- Ensures the plugin's state is initialized prior to running other calls. This state contains the basic information about the current merge request, like description, author, etc
local ensureState = function(callback)
-- Function names prefixed with "ensure" will ensure the plugin's state
-- is initialized prior to running other calls. These functions run
-- API calls if the state isn't initialized, which will set state containing
-- information that's necessary for other API calls, like description,
-- author, reviewer, etc.
local ensureState = function(callback)
return function()
if type(state.INFO) ~= "table" then
job.run_job("info", "GET", nil, function(data)
@@ -20,20 +25,37 @@ local ensureState = function(callback)
end
end
local ensureProjectMembers = function(callback)
return function()
if type(state.PROJECT_MEMBERS) ~= "table" then
job.run_job("members", "GET", nil, function(data)
state.PROJECT_MEMBERS = data.ProjectMembers
callback()
end)
else
callback()
end
end
end
-- Root Module Scope
local M = {}
M.summary = ensureState(summary.summary)
M.approve = ensureState(job.approve)
M.revoke = ensureState(job.revoke)
M.create_comment = ensureState(comment.create_comment)
M.list_discussions = ensureState(discussions.list_discussions)
M.edit_comment = ensureState(comment.edit_comment)
M.delete_comment = ensureState(comment.delete_comment)
M.reply = ensureState(discussions.reply)
M.state = state
local M = {}
M.summary = ensureState(summary.summary)
M.approve = ensureState(job.approve)
M.revoke = ensureState(job.revoke)
M.create_comment = ensureState(comment.create_comment)
M.list_discussions = ensureState(discussions.list_discussions)
M.edit_comment = ensureState(comment.edit_comment)
M.delete_comment = ensureState(comment.delete_comment)
M.add_reviewer = ensureProjectMembers(ensureState(assignees_and_reviewers.add_reviewer))
M.delete_reviewer = ensureProjectMembers(ensureState(assignees_and_reviewers.delete_reviewer))
M.add_assignee = ensureProjectMembers(ensureState(assignees_and_reviewers.add_assignee))
M.delete_assignee = ensureProjectMembers(ensureState(assignees_and_reviewers.delete_assignee))
M.reply = ensureState(discussions.reply)
M.state = state
-- Builds the binary (if not built); starts the Go server; sets the keymaps
M.setup = function(args)
M.setup = function(args)
if args == nil then args = {} end
local file_path = u.current_file_path()
local parent_dir = vim.fn.fnamemodify(file_path, ":h:h:h:h")
@@ -75,7 +97,7 @@ M.setup = function(args)
end
-- Builds the Go binary
M.build = function()
M.build = function()
local command = string.format("cd %s && make", state.BIN_PATH)
local installCode = os.execute(command .. "> /dev/null")
if installCode ~= 0 then
@@ -87,7 +109,7 @@ end
-- Initializes state for the project based on the arguments
-- provided in the `.gitlab.nvim` file per project, and the args provided in the setup function
M.setPluginConfiguration = function(args)
M.setPluginConfiguration = function(args)
local config_file_path = vim.fn.getcwd() .. "/.gitlab.nvim"
local config_file_content = u.read_file(config_file_path)
if config_file_content == nil then