Files
gitlab.nvim/lua/gitlab/actions/assignees_and_reviewers.lua
Harrison (Harry) Cramer 19468a3d2d BREAKING CHANGE: Delta Pager + Large Refactor (#43)
BREAKING CHANGE: This MR addresses an underlying issue with the original implementation in regards to detecting line numbers for comments. 

As such, this is a major breaking change. The setup function signature has changed, please review the `README.md` for the new arguments. The delta pager has also been added as a dependency: https://github.com/dandavison/delta

There will be future work to implement a native solution for parsing changes and line numbers.
2023-08-27 17:26:54 -04:00

74 lines
2.1 KiB
Lua

-- This module is responsible for the assignment of reviewers
-- and assignees in Gitlab, those who must review an MR.
local u = require("gitlab.utils")
local job = require("gitlab.job")
local state = require("gitlab.state")
local M = {}
M.add_assignee = function()
M.add_popup('assignee')
end
M.delete_assignee = function()
M.delete_popup('assignee')
end
M.add_reviewer = function()
M.add_popup('reviewer')
end
M.delete_reviewer = function()
M.delete_popup('reviewer')
end
M.add_popup = function(type)
local plural = type .. 's'
local current = state.INFO[plural]
local eligible = M.filter_eligible(state.PROJECT_MEMBERS, current)
vim.ui.select(eligible, {
prompt = 'Choose ' .. type .. ' to add',
format_item = function(user)
return user.username .. " (" .. user.name .. ")"
end
}, function(choice)
if not choice then return end
local current_ids = u.extract(current, 'id')
table.insert(current_ids, choice.id)
local json = vim.json.encode({ ids = current_ids })
job.run_job("/mr/" .. type, "PUT", json, function(data)
vim.notify(data.message, vim.log.levels.INFO)
state.INFO[plural] = data[plural]
end)
end)
end
M.delete_popup = function(type)
local plural = type .. 's'
local current = state.INFO[plural]
vim.ui.select(current, {
prompt = 'Choose ' .. type .. ' to delete',
format_item = function(user)
return user.username .. " (" .. user.name .. ")"
end
}, function(choice)
if not choice then return end
local ids = u.extract(M.filter_eligible(current, { choice }), 'id')
local json = vim.json.encode({ ids = ids })
job.run_job("/mr/" .. type, "PUT", json, function(data)
vim.notify(data.message, vim.log.levels.INFO)
state.INFO[plural] = data[plural]
end)
end)
end
M.filter_eligible = function(current, to_remove)
local ids = u.extract(to_remove, 'id')
local res = {}
for _, member in ipairs(current) do
if not u.contains(ids, member.id) then table.insert(res, member) end
end
return res
end
return M