Skip to content

Commit

Permalink
fix: handle owner/repo#issue format in github handler (#56)
Browse files Browse the repository at this point in the history
Fixes #56
  • Loading branch information
sportshead committed Apr 28, 2024
1 parent a7628f4 commit 0e1525f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lua/gx/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ local function parse_git_output(result)
end
end

function M.get_remote_url(remotes, push, owner)
function M.get_remote_url(remotes, push, owner, repo)
local notifier = require("gx.notifier")

local url = nil
Expand All @@ -41,6 +41,9 @@ function M.get_remote_url(remotes, push, owner)
end
if type(owner) == "string" and owner ~= "" then
local domain, repository = url:match("^https?://([^/]+)/[^/]+/([^/]*)")
if repo ~= "" then
repository = repo
end
url = string.format("https://%s/%s/%s", domain, owner, repository)
end

Expand Down
9 changes: 6 additions & 3 deletions lua/gx/handlers/github.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ local M = {

-- navigate to neovim github plugin url
function M.handle(mode, line, handler_options)
local match = helper.find(line, mode, "([%w-_]+#%d+)")
local match = helper.find(line, mode, "([%w-_]+/[%w-_]+#%d+)")
if not match then
match = helper.find(line, mode, "([%w-_]+#%d+)")
end
if not match then
match = helper.find(line, mode, "(#%d+)")
end
if not match then
return
end
local owner, issue = match:match("(.*)#(.+)")
local owner, repo, issue = match:match("([^/#]*)/?([^#]*)#(.+)")

local remotes = handler_options.git_remotes
if type(remotes) == "function" then
Expand All @@ -28,7 +31,7 @@ function M.handle(mode, line, handler_options)
push = push(vim.fn.expand("%:p"))
end

local git_url = require("gx.git").get_remote_url(remotes, push, owner)
local git_url = require("gx.git").get_remote_url(remotes, push, owner, repo)
if not git_url then
return
end
Expand Down
6 changes: 6 additions & 0 deletions test/spec/gx/handlers/github_handler_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,10 @@ describe("github_handler_does_work", function()
handler.handle("v", "See foouser#42", handler_options)
)
end)
it("parses owner/repo#issue format", function()
assert.equals(
"https://github.com/neovim/neovim/issues/23943",
handler.handle("v", "Waiting on upstream neovim/neovim#23943", handler_options)
)
end)
end)

0 comments on commit 0e1525f

Please sign in to comment.