From 5a210ff9c5278b2abb4794c0c8925c699a3e0906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20F=2E=20Bortl=C3=ADk?= Date: Wed, 18 Feb 2026 01:31:01 +0100 Subject: [PATCH 1/4] style: fix indentation --- doc/gitlab.nvim.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/gitlab.nvim.txt b/doc/gitlab.nvim.txt index 2db9f633..1893f22a 100644 --- a/doc/gitlab.nvim.txt +++ b/doc/gitlab.nvim.txt @@ -1084,7 +1084,7 @@ execute and passed the data as an argument. with each resource as a key-value pair, with the key being it's type. - *gitlab.nvim.refresh_data* + *gitlab.nvim.refresh_data* gitlab.refresh_data() ~ Fetches discussion tree data from Gitlab and refreshes the tree views. It can From fcdb2896076a0203d88c84ea287e56bd41e904bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20F=2E=20Bortl=C3=ADk?= Date: Wed, 18 Feb 2026 01:17:28 +0100 Subject: [PATCH 2/4] feat!: implement AutoMerge option to AcceptMergeRequest #518 This PR also fixes a bug when the `Delete source branch` setting of the MR was not respected due to incorrect reference in `lua/gitlab/actions/merge.lua` to `state.INFO.delete_branch` instead of `state.INFO.force_remove_source_branch`. This PR also changes the behaviour of how the `opts` in `gitlab.merge(opts)` behave: - Before this PR: - when `lua require("gitlab").merge()` was run without parameters, the values visible in the Summary view were used (except for the bug mentioned above). - specifying one of `squash` or `delete_branch` in `opts` caused the other parameter to default to `false` even if Summary view would show it's set to `true`. - After this PR: - running `lua require("gitlab").merge()` without parameters doesn't change. - specifying any of the `opts` values (`auto_merge`, `squash`, `delete_branch`), has no effect on the other options - if not specified in the `gitlab.merge()` call, the values from the Summary are used. This is a breaking change, since theoretically, before, a user could rely on the fact that ignoring one of the options would set it to `false` which now is not guaranteed (the value depends on the existing MR settings). --- cmd/app/merge_mr.go | 10 +++++++++- doc/gitlab.nvim.txt | 26 +++++++++++++++++--------- lua/gitlab/actions/merge.lua | 14 +++++++++----- lua/gitlab/actions/summary.lua | 3 ++- lua/gitlab/annotations.lua | 2 +- lua/gitlab/state.lua | 1 + 6 files changed, 39 insertions(+), 17 deletions(-) diff --git a/cmd/app/merge_mr.go b/cmd/app/merge_mr.go index f4f2e878..eb839622 100644 --- a/cmd/app/merge_mr.go +++ b/cmd/app/merge_mr.go @@ -8,6 +8,7 @@ import ( ) type AcceptMergeRequestRequest struct { + AutoMerge bool `json:"auto_merge"` DeleteBranch bool `json:"delete_branch"` SquashMessage string `json:"squash_message"` Squash bool `json:"squash"` @@ -27,6 +28,7 @@ func (a mergeRequestAccepterService) ServeHTTP(w http.ResponseWriter, r *http.Re payload := r.Context().Value(payload("payload")).(*AcceptMergeRequestRequest) opts := gitlab.AcceptMergeRequestOptions{ + AutoMerge: &payload.AutoMerge, Squash: &payload.Squash, ShouldRemoveSourceBranch: &payload.DeleteBranch, } @@ -47,7 +49,13 @@ func (a mergeRequestAccepterService) ServeHTTP(w http.ResponseWriter, r *http.Re return } - response := SuccessResponse{Message: "MR merged successfully"} + var message string + if payload.AutoMerge { + message = "MR set to be merged when all checks pass" + } else { + message = "MR merged successfully" + } + response := SuccessResponse{Message: message} w.WriteHeader(http.StatusOK) diff --git a/doc/gitlab.nvim.txt b/doc/gitlab.nvim.txt index 1893f22a..f128e1e5 100644 --- a/doc/gitlab.nvim.txt +++ b/doc/gitlab.nvim.txt @@ -9,7 +9,7 @@ Table of Contents *gitlab.nvim.table-of-contents* - Connecting to Gitlab |gitlab.nvim.connecting-to-gitlab| - Configuring the Plugin |gitlab.nvim.configuring-the-plugin| - Usage |gitlab.nvim.usage| - - The Summary view |gitlab.nvim.the-summary-view| + - The Summary view |gitlab.nvim.summary-view| - Reviewing an MR |gitlab.nvim.reviewing-an-mr| - Temporary registers |gitlab.nvim.temp-registers| - Discussions and Notes |gitlab.nvim.discussions-and-notes| @@ -308,6 +308,7 @@ you call this function with no values the defaults will be used: "pipeline", "branch", "target_branch", + "auto_merge", "delete_branch", "squash", "labels", @@ -382,7 +383,7 @@ Then open Neovim. To begin, try running the `summary` command or the `review` command. -THE SUMMARY VIEW *gitlab.nvim.the-summary-view* +THE SUMMARY VIEW *gitlab.nvim.summary-view* The `summary` action will open the MR title and description: >lua @@ -1025,18 +1026,25 @@ Copies the URL of the current MR to system clipboard. *gitlab.nvim.merge* gitlab.merge({opts}) ~ -Merges the merge request into the target branch. When run without any -arguments, the `merge` action will respect the "Squash commits" and "Delete -source branch" settings set by `require("gitlab").create_mr()` or set in -Gitlab online. You can see the current settings in the Summary view, see -|gitlab.nvim.the-summary-view|. +Merges a mergeable merge request into the target branch. The behaviour can be +configured with the `opts` parameter. By default, the `merge` action respects +the "Auto-merge" setting, and the "Squash commits" and "Delete source branch" +settings set by `require("gitlab").create_mr()` (or in Gitlab's "Edit merge +request" page). You can see the current settings in the Summary view, see +|gitlab.nvim.summary-view|. >lua require("gitlab").merge() - require("gitlab").merge({ squash = false, delete_branch = true }) + require("gitlab").merge({ + auto_merge = true, squash = false, delete_branch = false + }) < Parameters: ~ • {opts}: (table|nil) Keyword arguments that can be used to override - default behavior. + individual current settings. + • {auto_merge}: (bool) If true, the merge request is set to merge + automatically when the pipeline succeeds. If false, an immediate + merge is attempted. Currently, the plugin doesn't allow + cancelling the auto-merge. • {delete_branch}: (bool) If true, the source branch will be deleted. • {squash}: (bool) If true, the commits will be squashed. If diff --git a/lua/gitlab/actions/merge.lua b/lua/gitlab/actions/merge.lua index 81eed3f6..5e0e5478 100644 --- a/lua/gitlab/actions/merge.lua +++ b/lua/gitlab/actions/merge.lua @@ -12,19 +12,23 @@ local function create_squash_message_popup() end ---@class MergeOpts +---@field auto_merge boolean? ---@field delete_branch boolean? ---@field squash boolean? ---@field squash_message string? ---@param opts MergeOpts M.merge = function(opts) - local merge_body = { squash = state.INFO.squash, delete_branch = state.INFO.delete_branch } - if opts then - merge_body.squash = opts.squash ~= nil and opts.squash - merge_body.delete_branch = opts.delete_branch ~= nil and opts.delete_branch + local merge_body = { + auto_merge = state.INFO.merge_when_pipeline_succeeds, + squash = state.INFO.squash, + delete_branch = state.INFO.force_remove_source_branch, + } + for key, val in pairs(opts or {}) do + merge_body[key] = val end - if state.INFO.detailed_merge_status ~= "mergeable" then + if state.INFO.detailed_merge_status ~= "mergeable" and not merge_body.auto_merge then u.notify(string.format("MR not mergeable, currently '%s'", state.INFO.detailed_merge_status), vim.log.levels.ERROR) return end diff --git a/lua/gitlab/actions/summary.lua b/lua/gitlab/actions/summary.lua index 87afc832..f4cff0e9 100644 --- a/lua/gitlab/actions/summary.lua +++ b/lua/gitlab/actions/summary.lua @@ -124,6 +124,7 @@ M.build_info_lines = function() branch = { title = "Branch", content = info.source_branch }, labels = { title = "Labels", content = table.concat(info.labels, ", ") }, target_branch = { title = "Target Branch", content = info.target_branch }, + auto_merge = { title = "Auto-merge", content = (info.merge_when_pipeline_succeeds and "Yes" or "No") }, delete_branch = { title = "Delete Source Branch", content = (info.force_remove_source_branch and "Yes" or "No"), @@ -271,7 +272,7 @@ M.color_details = function(bufnr) vim.api.nvim_buf_add_highlight(bufnr, details_namespace, ("label" .. j), i - 1, start_idx - 1, end_idx) end end - elseif v == "delete_branch" or v == "squash" or v == "draft" or v == "conflicts" then + elseif v == "auto_merge" or v == "delete_branch" or v == "squash" or v == "draft" or v == "conflicts" then local line_content = u.get_line_content(bufnr, i) local start_idx, end_idx = line_content:find("%S-$") if start_idx ~= nil and end_idx ~= nil then diff --git a/lua/gitlab/annotations.lua b/lua/gitlab/annotations.lua index e1403249..f7418aaf 100644 --- a/lua/gitlab/annotations.lua +++ b/lua/gitlab/annotations.lua @@ -252,7 +252,7 @@ ---@class InfoSettings ---@field horizontal? boolean -- Display metadata to the left of the summary rather than underneath ----@field fields? ("author" | "created_at" | "updated_at" | "merge_status" | "draft" | "conflicts" | "assignees" | "reviewers" | "pipeline" | "branch" | "target_branch" | "delete_branch" | "squash" | "labels")[] +---@field fields? ("author" | "created_at" | "updated_at" | "merge_status" | "draft" | "conflicts" | "assignees" | "reviewers" | "pipeline" | "branch" | "target_branch" | "auto_merge" | "delete_branch" | "squash" | "labels")[] ---@class DiscussionSettings: table ---@field expanders? ExpanderOpts -- Customize the expander icons in the discussion tree diff --git a/lua/gitlab/state.lua b/lua/gitlab/state.lua index d67e0c06..b0ab09fb 100644 --- a/lua/gitlab/state.lua +++ b/lua/gitlab/state.lua @@ -214,6 +214,7 @@ M.settings = { "pipeline", "branch", "target_branch", + "auto_merge", "delete_branch", "squash", "labels", From 863f36cd2a8fa1d8bd070513131074cc9e468fee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20F=2E=20Bortl=C3=ADk?= Date: Wed, 18 Feb 2026 01:51:41 +0100 Subject: [PATCH 3/4] feat: add default global keymap for auto-merge --- README.md | 1 + doc/gitlab.nvim.txt | 1 + lua/gitlab/state.lua | 7 +++++++ 3 files changed, 9 insertions(+) diff --git a/README.md b/README.md index 12ca0cb7..a4485782 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,7 @@ glrd Delete reviewer glA Approve MR glR Revoke MR approval glM Merge the feature branch to the target branch and close MR +glm Set MR to merge automatically when the pipeline succeeds glC Create a new MR for currently checked-out feature branch glc Chose MR for review glS Start review for the currently checked-out branch diff --git a/doc/gitlab.nvim.txt b/doc/gitlab.nvim.txt index f128e1e5..0f4f421b 100644 --- a/doc/gitlab.nvim.txt +++ b/doc/gitlab.nvim.txt @@ -179,6 +179,7 @@ you call this function with no values the defaults will be used: approve = "glA", -- Approve MR revoke = "glR", -- Revoke MR approval merge = "glM", -- Merge the feature branch to the target branch and close MR + set_auto_merge = "glm", -- Set MR to merge automatically when the pipeline succeeds create_mr = "glC", -- Create a new MR for currently checked-out feature branch choose_merge_request = "glc", -- Chose MR for review (if necessary check out the feature branch) start_review = "glS", -- Start review for the currently checked-out branch diff --git a/lua/gitlab/state.lua b/lua/gitlab/state.lua index b0ab09fb..ce629251 100644 --- a/lua/gitlab/state.lua +++ b/lua/gitlab/state.lua @@ -81,6 +81,7 @@ M.settings = { approve = "glA", revoke = "glR", merge = "glM", + set_auto_merge = "glm", create_mr = "glC", choose_merge_request = "glc", start_review = "glS", @@ -390,6 +391,12 @@ M.set_global_keymaps = function() end, { desc = "Merge MR", nowait = keymaps.global.merge_nowait }) end + if keymaps.global.set_auto_merge then + vim.keymap.set("n", keymaps.global.set_auto_merge, function() + require("gitlab").merge({auto_merge = true}) + end, { desc = "Set MR to auto-merge", nowait = keymaps.global.set_auto_merge_nowait }) + end + if keymaps.global.copy_mr_url then vim.keymap.set("n", keymaps.global.copy_mr_url, function() require("gitlab").copy_mr_url() From 5f2330050d07634984401091a119f054066b8729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20F=2E=20Bortl=C3=ADk?= Date: Wed, 18 Feb 2026 09:47:40 +0100 Subject: [PATCH 4/4] style: apply stylua --- lua/gitlab/state.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/gitlab/state.lua b/lua/gitlab/state.lua index ce629251..bff05338 100644 --- a/lua/gitlab/state.lua +++ b/lua/gitlab/state.lua @@ -393,7 +393,7 @@ M.set_global_keymaps = function() if keymaps.global.set_auto_merge then vim.keymap.set("n", keymaps.global.set_auto_merge, function() - require("gitlab").merge({auto_merge = true}) + require("gitlab").merge({ auto_merge = true }) end, { desc = "Set MR to auto-merge", nowait = keymaps.global.set_auto_merge_nowait }) end