Fix MR Selection, Go Code Refactor (#358)

refactor: Refactors the Go codebase into a more modular and idiomatic approach
fix: require selection of specific MR when there are multiple targets for a given source branch
feat: Allows for the passing of Gitlab's filter options when choosing an MR, improves MR selection
feat: API to choose an MR from a list based on the provided username's involvement as an assignee/reviewer/author

This is a #MINOR release
This commit is contained in:
Harrison (Harry) Cramer
2024-09-08 16:45:09 -04:00
committed by GitHub
parent 6500ef1f2c
commit ea2b2b2f5c
81 changed files with 2559 additions and 3035 deletions

View File

@@ -45,6 +45,7 @@ M.choose_merge_request = function(opts)
end
vim.schedule(function()
state.chosen_target_branch = choice.target_branch
require("gitlab.server").restart(function()
if opts.open_reviewer then
require("gitlab").review()

View File

@@ -26,6 +26,7 @@ local project_members = state.dependencies.project_members
local latest_pipeline = state.dependencies.latest_pipeline
local revisions = state.dependencies.revisions
local merge_requests_dep = state.dependencies.merge_requests
local merge_requests_by_username_dep = state.dependencies.merge_requests_by_username
local draft_notes_dep = state.dependencies.draft_notes
local discussion_data = state.dependencies.discussion_data
@@ -102,6 +103,10 @@ return {
data = data.data,
print_settings = state.print_settings,
choose_merge_request = async.sequence({ merge_requests_dep }, merge_requests.choose_merge_request),
choose_merge_request_by_username = async.sequence(
{ project_members, merge_requests_by_username_dep },
merge_requests.choose_merge_request
),
open_in_browser = async.sequence({ info }, function()
local web_url = u.get_web_url()
if web_url ~= nil then

View File

@@ -66,6 +66,14 @@ M.open = function()
u.notify("This merge request has conflicts!", vim.log.levels.WARN)
end
if state.INFO.state == "closed" then
u.notify(string.format("This MR was closed on %s", u.format_date(state.INFO.closed_at)), vim.log.levels.WARN)
end
if state.INFO.state == "merged" then
u.notify(string.format("This MR was merged on %s", u.format_date(state.INFO.merged_at)), vim.log.levels.WARN)
end
if state.settings.discussion_diagnostic ~= nil or state.settings.discussion_sign ~= nil then
u.notify(
"Diagnostics are now configured as settings.discussion_signs, see :h gitlab.nvim.signs-and-diagnostics",

View File

@@ -20,8 +20,11 @@ M.start = function(callback)
debug = state.settings.debug,
log_path = state.settings.log_path,
connection_settings = state.settings.connection_settings,
chosen_target_branch = state.chosen_target_branch,
}
state.chosen_target_branch = nil -- Do not let this interfere with subsequent reviewer.open() calls
local settings = vim.json.encode(go_server_settings)
local command = string.format("%s '%s'", state.settings.bin, settings)
@@ -117,7 +120,7 @@ M.shutdown = function(cb)
end)
end
-- Restarts the Go server and clears out all gitlab.nvim state
---Restarts the Go server and clears out all gitlab.nvim state
M.restart = function(cb)
if not state.go_server_running then
vim.notify("The gitlab.nvim server is not running", vim.log.levels.ERROR)

View File

@@ -5,6 +5,7 @@
local git = require("gitlab.git")
local u = require("gitlab.utils")
local List = require("gitlab.utils.list")
local M = {}
M.emoji_map = nil
@@ -43,6 +44,7 @@ end
--- These are the default settings for the plugin
M.settings = {
auth_provider = M.default_auth_provider,
file_separator = u.path_separator,
port = nil, -- choose random port
debug = {
go_request = false,
@@ -247,6 +249,10 @@ M.unlinked_discussion_tree = {
unresolved_expanded = false,
}
-- Used to set a specific target when choosing a merge request, due to the fact
-- that it's technically possible to have multiple target branches
M.chosen_target_branch = nil
-- These keymaps are set globally when the plugin is initialized
M.set_global_keymaps = function()
local keymaps = M.settings.keymaps
@@ -381,7 +387,6 @@ end
---@return Settings
M.merge_settings = function(args)
M.settings = u.merge(M.settings, args)
M.settings.file_separator = (u.is_windows() and "\\" or "/")
return M.settings
end
@@ -561,18 +566,35 @@ M.dependencies = {
refresh = true,
method = "POST",
body = function(opts)
local listArgs = {
label = opts and opts.label or {},
notlabel = opts and opts.notlabel or {},
}
for k, v in pairs(listArgs) do
listArgs[k] = v
if opts then
opts.open_reviewer_field = nil
end
return listArgs
if opts and opts.notlabel then -- Legacy: Migrate use of notlabel to not[label], per API
opts["not[label]"] = opts.notlabel
opts.notlabel = nil
end
return opts or vim.json.decode("{}")
end,
},
merge_requests_by_username = {
endpoint = "/merge_requests_by_username",
key = "merge_requests",
state = "MERGE_REQUESTS",
refresh = true,
method = "POST",
body = function(opts)
local members = List.new(M.PROJECT_MEMBERS)
local user = members:find(function(usr)
return usr.username == opts.username
end)
if user == nil then
error("Invalid payload, user could not be found!")
end
opts.user_id = user.id
return opts
end,
},
discussion_data = {
-- key is missing here...
endpoint = "/mr/discussions/list",
state = "DISCUSSION_DATA",
refresh = false,