From 93e8ad05999c51be6d7ddff48c5293c71c20f0f2 Mon Sep 17 00:00:00 2001 From: sportshead Date: Mon, 29 Apr 2024 17:13:21 +0100 Subject: [PATCH] fix: support dots in owner/repo#issue, and default to github remote with owner, repo --- lua/gx/git.lua | 3 +++ lua/gx/handlers/github.lua | 4 ++-- test/spec/gx/handlers/github_handler_spec.lua | 6 ++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lua/gx/git.lua b/lua/gx/git.lua index 3a0ca7a..549db81 100644 --- a/lua/gx/git.lua +++ b/lua/gx/git.lua @@ -35,6 +35,9 @@ function M.get_remote_url(remotes, push, owner, repo) end end + if not url and (owner ~= "" and repo ~= "") then -- fallback to github if owner and repo are present + url = "https://github.com/foo/bar" + end if not url then notifier.warn("No remote git repository found!") return diff --git a/lua/gx/handlers/github.lua b/lua/gx/handlers/github.lua index 1bebc84..689690d 100644 --- a/lua/gx/handlers/github.lua +++ b/lua/gx/handlers/github.lua @@ -9,9 +9,9 @@ local M = { -- navigate to neovim github plugin url function M.handle(mode, line, handler_options) - local match = helper.find(line, mode, "([%w-_]+/[%w-_]+#%d+)") + local match = helper.find(line, mode, "([%w-_.]+/[%w-_.]+#%d+)") if not match then - match = helper.find(line, mode, "([%w-_]+#%d+)") + match = helper.find(line, mode, "([%w-_.]+#%d+)") end if not match then match = helper.find(line, mode, "(#%d+)") diff --git a/test/spec/gx/handlers/github_handler_spec.lua b/test/spec/gx/handlers/github_handler_spec.lua index 07bbcf7..cd7c338 100644 --- a/test/spec/gx/handlers/github_handler_spec.lua +++ b/test/spec/gx/handlers/github_handler_spec.lua @@ -46,4 +46,10 @@ describe("github_handler_does_work", function() handler.handle("v", "Waiting on upstream neovim/neovim#23943", handler_options) ) end) + it("parses owner/repo#issue formats with dots", function() + assert.equals( + "https://github.com/chrishrb/gx.nvim/issues/46", + handler.handle("v", "Waiting on upstream chrishrb/gx.nvim#46", handler_options) + ) + end) end)