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/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 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 diff --git a/lua/octo/utils.lua b/lua/octo/utils.lua index ec264b65..2a8d580f 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 @@ -174,8 +181,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 { @@ -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 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()