Files
gitlab.nvim/lua/gitlab/actions/merge_requests.lua
Harrison (Harry) Cramer 495e64c8bc Release (#440)
* Feat: Enable sorting discussions by original comment (#422)
* Feat: Improve popup UX (#426)
* Feat: Automatically update MR summary details (#427)
* Feat: Show update progress in winbar (#432)
* Feat: Abbreviate winbar (#439)
* Fix: Note Creation Bug (#441)
* Fix: Checking whether comment can be created (#434)
* Fix: Syntax in discussion tree (#433)
* fix: improve indication of resolved threads and drafts (#442)
* Docs: Various minor improvements (#445)

---------

Co-authored-by: Jakub F. Bortlík <jakub.bortlik@proton.me>
2024-12-11 14:21:50 -05:00

65 lines
1.7 KiB
Lua

local state = require("gitlab.state")
local reviewer = require("gitlab.reviewer")
local git = require("gitlab.git")
local u = require("gitlab.utils")
local M = {}
---@class ChooseMergeRequestOptions
---@field open_reviewer? boolean
---@field label? string[]
---@field notlabel? string[]
---Opens up a select menu that lets you choose a different merge request.
---@param opts ChooseMergeRequestOptions|nil
M.choose_merge_request = function(opts)
if opts == nil then
opts = state.settings.choose_merge_request
end
vim.ui.select(state.MERGE_REQUESTS, {
prompt = "Choose Merge Request",
format_item = function(mr)
return string.format("%s [%s -> %s] (%s)", mr.title, mr.source_branch, mr.target_branch, mr.author.name)
end,
}, function(choice)
if not choice then
return
end
if reviewer.is_open then
reviewer.close()
end
if choice.source_branch ~= git.get_current_branch() then
local has_clean_tree, clean_tree_err = git.has_clean_tree()
if clean_tree_err ~= nil then
return
elseif not has_clean_tree then
u.notify(
"Cannot switch branch when working tree has changes, please stash or commit and push",
vim.log.levels.ERROR
)
return
end
end
vim.schedule(function()
local _, branch_switch_err = git.switch_branch(choice.source_branch)
if branch_switch_err ~= nil then
return
end
vim.schedule(function()
state.chosen_mr_iid = choice.iid
require("gitlab.server").restart(function()
if opts.open_reviewer then
require("gitlab").review()
end
end)
end)
end)
end)
end
return M