From 3c9d95d25b75d1942de9bdfa85dea113a9307e18 Mon Sep 17 00:00:00 2001 From: "Harrison (Harry) Cramer" <32515581+harrisoncramer@users.noreply.github.com> Date: Wed, 26 Jun 2024 07:30:05 -0700 Subject: [PATCH] Release (#313) * Fix docs: choose_merge_request's open_reviewer default value is true (#316) * Fix: Only set autocommands for select popups (#315) * Docs: Small improvements to README and docs * Feat: Add branch info to choose_merge_request menu (#318) This is a PATCH release. --- README.md | 3 ++ doc/gitlab.nvim.txt | 70 ++++++++++++++------------- lua/gitlab/actions/create_mr.lua | 2 - lua/gitlab/actions/merge_requests.lua | 2 +- lua/gitlab/actions/summary.lua | 18 +++++-- lua/gitlab/state.lua | 28 +++++++---- 6 files changed, 72 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index abd907b..5b04bd2 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,9 @@ To view these help docs and to get more detailed help information, please run `: This will checkout the branch locally, and open the plugin's reviewer pane. +NOTE: At the moment, the plugin assumes that the remote where you want to merge your feature branch +is called "origin". + For more detailed information about the Lua APIs please run `:h gitlab.nvim.api` ## Installation diff --git a/doc/gitlab.nvim.txt b/doc/gitlab.nvim.txt index e99e223..dda4f7b 100644 --- a/doc/gitlab.nvim.txt +++ b/doc/gitlab.nvim.txt @@ -55,6 +55,9 @@ QUICK START *gitlab.nvim.quick-start* This will checkout the branch locally, and up the plugin's reviewer pane. +NOTE: At the moment, the plugin assumes that the remote where you want to +merge your feature branch is called "origin". + INSTALLATION *gitlab.nvim.installation* @@ -78,25 +81,25 @@ With Lazy: < And with Packer: >lua - use { - "harrisoncramer/gitlab.nvim", - requires = { - "MunifTanjim/nui.nvim", - "nvim-lua/plenary.nvim", - "sindrets/diffview.nvim" - "stevearc/dressing.nvim", -- Recommended but not required. Better UI for pickers. - "nvim-tree/nvim-web-devicons", -- Recommended but not required. Icons in discussion tree. - }, - build = function() - require("gitlab.server").build() - end, - branch = "develop", - config = function() - require("diffview") -- We require some global state from diffview - local gitlab = require("gitlab") - gitlab.setup() - end, - } + use { + "harrisoncramer/gitlab.nvim", + requires = { + "MunifTanjim/nui.nvim", + "nvim-lua/plenary.nvim", + "sindrets/diffview.nvim", + "stevearc/dressing.nvim", -- Recommended but not required. Better UI for pickers. + "nvim-tree/nvim-web-devicons", -- Recommended but not required. Icons in discussion tree. + }, + build = function() + require("gitlab.server").build() + end, + branch = "develop", + config = function() + require("diffview") -- We require some global state from diffview + local gitlab = require("gitlab") + gitlab.setup() + end, + } < CONNECTING TO GITLAB *gitlab.nvim.connecting-to-gitlab* @@ -418,18 +421,18 @@ SIGNS AND DIAGNOSTICS *gitlab.nvim.signs-and-diagnostics* By default when reviewing files, you will see diagnostics for comments that have been added to a review. These are the default settings: >lua - discussion_signs = { - enabled = true, -- Show diagnostics for gitlab comments in the reviewer - skip_resolved_discussion = false, -- Show diagnostics for resolved discussions - severity = vim.diagnostic.severity.INFO, -- ERROR, WARN, INFO, or HINT - virtual_text = false, -- Whether to show the comment text inline as floating virtual text - use_diagnostic_signs = true, -- Show diagnostic sign (depending on the `severity` setting, e.g., I for INFO) along with the comment icon - priority = 100, -- Higher will override LSP warnings, etc - icons = { - comment = "→|", - range = " |", + discussion_signs = { + enabled = true, -- Show diagnostics for gitlab comments in the reviewer + skip_resolved_discussion = false, -- Show diagnostics for resolved discussions + severity = vim.diagnostic.severity.INFO, -- ERROR, WARN, INFO, or HINT + virtual_text = false, -- Whether to show the comment text inline as floating virtual text + use_diagnostic_signs = true, -- Show diagnostic sign (depending on the `severity` setting, e.g., I for INFO) along with the comment icon + priority = 100, -- Higher will override LSP warnings, etc + icons = { + comment = "→|", + range = " |", + }, }, - }, When the cursor is on a diagnostic line you can view the discussion thread by using `vim.diagnostic.show()`. @@ -630,9 +633,10 @@ default arguments outlined under "Configuring the Plugin". *gitlab.nvim.choose_merge_request* gitlab.choose_merge_request({opts}) ~ -Choose a merge request from a list of those open in your current project to review. -This command will automatically check out that branch locally, and optionally -open the reviewer pane. This is the default behavior. +Choose a merge request from a list of those open in your current project to +review. This command will automatically check out the feature branch locally, +and by default also open the reviewer pane (this can be overridden with the +`open_reviewer` parameter). >lua require("gitlab").choose_merge_request() require("gitlab").choose_merge_request({ open_reviewer = false }) diff --git a/lua/gitlab/actions/create_mr.lua b/lua/gitlab/actions/create_mr.lua index efe94a7..9f49f97 100644 --- a/lua/gitlab/actions/create_mr.lua +++ b/lua/gitlab/actions/create_mr.lua @@ -316,8 +316,6 @@ M.create_mr = function() forked_project_id = forked_project_id, } - vim.print(body) - job.run_job("/create_mr", "POST", body, function(data) u.notify(data.message, vim.log.levels.INFO) M.reset_state() diff --git a/lua/gitlab/actions/merge_requests.lua b/lua/gitlab/actions/merge_requests.lua index 127d380..81f4c2d 100644 --- a/lua/gitlab/actions/merge_requests.lua +++ b/lua/gitlab/actions/merge_requests.lua @@ -25,7 +25,7 @@ M.choose_merge_request = function(opts) vim.ui.select(state.MERGE_REQUESTS, { prompt = "Choose Merge Request", format_item = function(mr) - return string.format("%s (%s)", mr.title, mr.author.name) + 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 diff --git a/lua/gitlab/actions/summary.lua b/lua/gitlab/actions/summary.lua index 1876109..613b4df 100644 --- a/lua/gitlab/actions/summary.lua +++ b/lua/gitlab/actions/summary.lua @@ -63,10 +63,20 @@ M.summary = function() description_popup, M.edit_summary, miscellaneous.attach_file, - { cb = exit, action_before_close = true, save_to_temp_register = true } + { cb = exit, action_before_close = true, action_before_exit = true, save_to_temp_register = true } + ) + state.set_popup_keymaps( + title_popup, + M.edit_summary, + nil, + { cb = exit, action_before_close = true, action_before_exit = true } + ) + state.set_popup_keymaps( + info_popup, + M.edit_summary, + nil, + { cb = exit, action_before_close = true, action_before_exit = true } ) - state.set_popup_keymaps(title_popup, M.edit_summary, nil, { cb = exit, action_before_close = true }) - state.set_popup_keymaps(info_popup, M.edit_summary, nil, { cb = exit, action_before_close = true }) miscellaneous.set_cycle_popups_keymaps(popups) vim.api.nvim_set_current_buf(description_popup.bufnr) @@ -151,8 +161,6 @@ M.edit_summary = function() u.notify(data.message, vim.log.levels.INFO) state.INFO.description = data.mr.description state.INFO.title = data.mr.title - M.layout:unmount() - M.layout_visible = false end) end diff --git a/lua/gitlab/state.lua b/lua/gitlab/state.lua index 2de9e8b..63601b8 100644 --- a/lua/gitlab/state.lua +++ b/lua/gitlab/state.lua @@ -295,9 +295,9 @@ M.set_popup_keymaps = function(popup, action, linewise_action, opts) local text = u.get_buffer_text(popup.bufnr) if opts.action_before_close then action(text, popup.bufnr) - vim.api.nvim_buf_delete(popup.bufnr, {}) + exit(popup, opts) else - vim.api.nvim_buf_delete(popup.bufnr, {}) + exit(popup, opts) action(text, popup.bufnr) end end, { buffer = popup.bufnr, desc = "Perform action" }) @@ -312,18 +312,26 @@ M.set_popup_keymaps = function(popup, action, linewise_action, opts) end, { buffer = popup.bufnr, desc = "Perform linewise action" }) end - vim.api.nvim_create_autocmd("BufWinLeave", { - buffer = popup.bufnr, - callback = function() - if opts.save_to_temp_register then + if opts.save_to_temp_register then + vim.api.nvim_create_autocmd("BufWinLeave", { + buffer = popup.bufnr, + callback = function() local text = u.get_buffer_text(popup.bufnr) for _, register in ipairs(M.settings.popup.temp_registers) do vim.fn.setreg(register, text) end - end - exit(popup, opts) - end, - }) + end, + }) + end + + if opts.action_before_exit then + vim.api.nvim_create_autocmd("BufWinLeave", { + buffer = popup.bufnr, + callback = function() + exit(popup, opts) + end, + }) + end end -- Dependencies