From 3cd359762c76f7b7ebe82942dc6b0d6be030f367 Mon Sep 17 00:00:00 2001 From: legobt <6wbvkn0j@anonaddy.me> Date: Sun, 3 Nov 2024 05:03:56 +0000 Subject: [PATCH 1/4] feat: match patterns in ssh_aliases --- README.md | 4 ++-- lua/octo/utils.lua | 4 ++-- lua/tests/plenary/utils_spec.lua | 4 ++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c2f09e64..f359c546 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ require"octo".setup({ enable_builtin = false, -- shows a list of builtin actions when no action is provided default_remote = {"upstream", "origin"}; -- order to try remotes default_merge_method = "commit", -- default merge method which should be used when calling `Octo pr merge`, could be `commit`, `rebase` or `squash` - ssh_aliases = {}, -- SSH aliases. e.g. `ssh_aliases = {["github.com-work"] = "github.com"}` + ssh_aliases = {}, -- SSH aliases. e.g. `ssh_aliases = {["github.com-work"] = "github.com"}`. The key part will be interpreted as an anchored Lua pattern. picker = "telescope", -- or "fzf-lua" picker_config = { use_emojis = false, -- only used by "fzf-lua" picker for now @@ -411,7 +411,7 @@ If no command is passed, the argument to `Octo` is treated as a URL from where a - ``: Append Gist to buffer [Available keys](https://cli.github.com/manual/gh_gist_list): `repo`\|`public`\|`secret` -5. Users in the assignee and reviewer commands: +5. Users in the assignee and reviewer commands: - `search`: Dynamically search all GitHub users - `mentionable`: List of *mentionable* users in current repo diff --git a/lua/octo/utils.lua b/lua/octo/utils.lua index ec264b65..38c7a6d5 100644 --- a/lua/octo/utils.lua +++ b/lua/octo/utils.lua @@ -174,8 +174,8 @@ function M.parse_remote_url(url, aliases) repo = chunks[#chunks] end - if aliases[host] then - host = aliases[host] + for alias, rhost in pairs(aliases) do + host = host:gsub("^" .. alias .. "$", rhost, 1) end if not M.is_blank(host) and not M.is_blank(repo) then return { diff --git a/lua/tests/plenary/utils_spec.lua b/lua/tests/plenary/utils_spec.lua index 145121ed..18b4bdca 100644 --- a/lua/tests/plenary/utils_spec.lua +++ b/lua/tests/plenary/utils_spec.lua @@ -10,9 +10,11 @@ describe("Utils module:", function() "git@github.com:pwntester/octo.nvim.git", "git@github.com:pwntester/octo.nvim.git", "hub.com:pwntester/octo.nvim.git", + "hub.com-alias:pwntester/octo.nvim.git", } local aliases = { ["hub.com"] = "github.com", + ["hub.com-.*"] = "github.com", } eq(this.parse_remote_url(remote_urls[1], aliases).host, "github.com") eq(this.parse_remote_url(remote_urls[1], aliases).repo, "pwntester/octo.nvim") @@ -24,6 +26,8 @@ describe("Utils module:", function() eq(this.parse_remote_url(remote_urls[4], aliases).repo, "pwntester/octo.nvim") eq(this.parse_remote_url(remote_urls[5], aliases).host, "github.com") eq(this.parse_remote_url(remote_urls[5], aliases).repo, "pwntester/octo.nvim") + eq(this.parse_remote_url(remote_urls[6], aliases).host, "github.com") + eq(this.parse_remote_url(remote_urls[6], aliases).repo, "pwntester/octo.nvim") end) it("convert_vim_mapping_to_fzf changes vim mappings to fzf mappings", function() From 9be615df177b03c14aeb72b8c6c9a88fadd3cb9d Mon Sep 17 00:00:00 2001 From: legobt <6wbvkn0j@anonaddy.me> Date: Sun, 3 Nov 2024 05:04:17 +0000 Subject: [PATCH 2/4] differentiate between failing and missing actions in error message --- lua/octo/commands.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lua/octo/commands.lua b/lua/octo/commands.lua index 69855128..529fca51 100644 --- a/lua/octo/commands.lua +++ b/lua/octo/commands.lua @@ -434,10 +434,15 @@ function M.octo(object, action, ...) end local a = o[action] or o - if not pcall(a, ...) then + if not a then utils.error(action and "Incorrect action: " .. action or "No action specified") return end + res = pcall(a, ...) + if not res then + utils.error(action and "Failed action: " .. action) + return + end end end From ca0ccc565cdb8a9a144e61ce8e44e87271b361b9 Mon Sep 17 00:00:00 2001 From: legobt <6wbvkn0j@anonaddy.me> Date: Sun, 3 Nov 2024 05:04:36 +0000 Subject: [PATCH 3/4] fix: handle local filesystem remotes --- lua/octo/utils.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lua/octo/utils.lua b/lua/octo/utils.lua index ec264b65..8d9b2835 100644 --- a/lua/octo/utils.lua +++ b/lua/octo/utils.lua @@ -156,6 +156,13 @@ function M.is_blank(s) end function M.parse_remote_url(url, aliases) + -- filesystem path + if vim.startswith(url, "/") or vim.startswith(url, ".") then + return { + host = nil, + repo = url, + } + end -- remove trailing ".git" url = string.gsub(url, ".git$", "") -- remove protocol scheme @@ -616,7 +623,7 @@ function M.get_repo_number_from_varargs(...) return end if not repo then - M.error "Cant find repo name" + M.error "Can not find repo name" return end if not number then From 179405869efdbdd65d10bf60c9b83f4627bcc61f Mon Sep 17 00:00:00 2001 From: legobt <6wbvkn0j@anonaddy.me> Date: Sun, 3 Nov 2024 05:04:56 +0000 Subject: [PATCH 4/4] fix(pickers/telescope): handle nil selection in open --- lua/octo/pickers/telescope/provider.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lua/octo/pickers/telescope/provider.lua b/lua/octo/pickers/telescope/provider.lua index 5385c4d8..f8699ec2 100644 --- a/lua/octo/pickers/telescope/provider.lua +++ b/lua/octo/pickers/telescope/provider.lua @@ -76,7 +76,9 @@ local function open(command) elseif command == "tab" then vim.cmd [[:tab sb %]] end - utils.get(selection.kind, selection.repo, selection.value) + if selection then + utils.get(selection.kind, selection.repo, selection.value) + end end end