Skip to content

Commit 9bdd077

Browse files
authored
feat: Copy web url of MR to clipboard (#258)
feat: Add API and keymap for copying web URL to clipboard
1 parent d92bc09 commit 9bdd077

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed

doc/gitlab.nvim.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ in normal mode):
522522
vim.keymap.set("n", "glp", gitlab.pipeline)
523523
vim.keymap.set("n", "glo", gitlab.open_in_browser)
524524
vim.keymap.set("n", "glM", gitlab.merge)
525+
vim.keymap.set("n", "glu", gitlab.copy_mr_url)
525526
<
526527

527528
TROUBLESHOOTING *gitlab.nvim.troubleshooting*
@@ -633,7 +634,7 @@ After the comment is typed, submit it to Gitlab via the |settings.popup.perform_
633634
keybinding, by default |<leader>l|
634635

635636
*gitlab.nvim.create_mr*
636-
create_mr({opts}) ~
637+
gitlab.create_mr({opts}) ~
637638

638639
Starts the process of creating an MR for the currently checked out branch.
639640
>lua
@@ -753,6 +754,13 @@ gitlab.open_in_browser() ~
753754
Opens the current MR in your default web browser.
754755
>lua
755756
require("gitlab").open_in_browser()
757+
<
758+
*gitlab.nvim.copy_mr_url*
759+
gitlab.copy_mr_url() ~
760+
761+
Copies the URL of the current MR to system clipboard.
762+
>lua
763+
require("gitlab").copy_mr_url()
756764
<
757765
*gitlab.nvim.merge*
758766
gitlab.merge({opts}) ~

lua/gitlab/actions/discussions/init.lua

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -973,20 +973,18 @@ end
973973
---@param tree NuiTree
974974
M.open_in_browser = function(tree)
975975
local url = M.get_url(tree)
976-
if url == nil then
977-
return
976+
if url ~= nil then
977+
u.open_in_browser(url)
978978
end
979-
u.open_in_browser(url)
980979
end
981980

982981
---@param tree NuiTree
983982
M.copy_node_url = function(tree)
984983
local url = M.get_url(tree)
985-
if url == nil then
986-
return
984+
if url ~= nil then
985+
vim.fn.setreg("+", url)
986+
u.notify("Copied '" .. url .. "' to clipboard", vim.log.levels.INFO)
987987
end
988-
u.notify("Copied '" .. url .. "' to clipboard", vim.log.levels.INFO)
989-
vim.fn.setreg("+", url)
990988
end
991989

992990
M.add_emoji_to_note = function(tree, unlinked)

lua/gitlab/init.lua

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,16 @@ return {
7373
data = data.data,
7474
print_settings = state.print_settings,
7575
open_in_browser = async.sequence({ info }, function()
76-
if state.INFO.web_url == nil then
77-
u.notify("Could not get Gitlab URL", vim.log.levels.ERROR)
78-
return
76+
local web_url = u.get_web_url()
77+
if web_url ~= nil then
78+
u.open_in_browser(web_url)
79+
end
80+
end),
81+
copy_mr_url = async.sequence({ info }, function()
82+
local web_url = u.get_web_url()
83+
if web_url ~= nil then
84+
vim.fn.setreg("+", web_url)
85+
u.notify("Copied '" .. web_url .. "' to clipboard", vim.log.levels.INFO)
7986
end
80-
u.open_in_browser(state.INFO.web_url)
8187
end),
8288
}

lua/gitlab/utils/init.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,14 @@ M.basename = function(str)
661661
return name
662662
end
663663

664+
M.get_web_url = function()
665+
local web_url = require("gitlab.state").INFO.web_url
666+
if web_url ~= nil then
667+
return web_url
668+
end
669+
M.notify("Could not get Gitlab URL", vim.log.levels.ERROR)
670+
end
671+
664672
---@param url string?
665673
M.open_in_browser = function(url)
666674
if vim.fn.has("mac") == 1 then

0 commit comments

Comments
 (0)