Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion cmd/app/merge_mr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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,
}
Expand All @@ -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)

Expand Down
29 changes: 19 additions & 10 deletions doc/gitlab.nvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -308,6 +309,7 @@ you call this function with no values the defaults will be used:
"pipeline",
"branch",
"target_branch",
"auto_merge",
"delete_branch",
"squash",
"labels",
Expand Down Expand Up @@ -382,7 +384,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
Expand Down Expand Up @@ -1025,18 +1027,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
Expand Down Expand Up @@ -1084,7 +1093,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
Expand Down
14 changes: 9 additions & 5 deletions lua/gitlab/actions/merge.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lua/gitlab/actions/summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lua/gitlab/annotations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions lua/gitlab/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -214,6 +215,7 @@ M.settings = {
"pipeline",
"branch",
"target_branch",
"auto_merge",
"delete_branch",
"squash",
"labels",
Expand Down Expand Up @@ -389,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()
Expand Down
Loading