Skip to content

Commit

Permalink
Fix github handler not matching github issue inside braces (#53)
Browse files Browse the repository at this point in the history
When one uses squash to merge PR-s, the issue number is in parentheses.
The github handler pattern failed to match those issues.

This change fixes that and adds some test-cases for various edge-cases
as well.
  • Loading branch information
reegnz authored Mar 20, 2024
1 parent f29a874 commit 075bc1c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lua/gx/handlers/github.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local M = {

-- navigate to neovim github plugin url
function M.handle(mode, line, _)
local pattern = "%a*%s#(%d*)"
local pattern = "#(%d+)"
local github_issue = helper.find(line, mode, pattern)
if not github_issue then
return
Expand Down
23 changes: 20 additions & 3 deletions test/spec/gx/handlers/github_handler_spec.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
local handler = require("gx.handlers.github")

describe("github_handler_does_work", function()
it("github_issue", function()
it("with_plain_issue_number", function()
assert.equals("https://github.com/chrishrb/gx.nvim/issues/2", handler.handle("v", "#2"))
end)
it("with_text_before_issue_number", function()
assert.equals("https://github.com/chrishrb/gx.nvim/issues/22", handler.handle("v", "Fixes #22"))
end)
it("with_text_after_issue_number", function()
assert.equals(
"https://github.com/chrishrb/gx.nvim/issues/40",
handler.handle("v", "#40 is a related issue")
)
end)
it("with_text_all_around", function()
assert.equals(
"https://github.com/chrishrb/gx.nvim/issues/4",
handler.handle("v", "Fixes #4 once and for all")
)
end)
it("with_issue_number_in_parentheses", function()
assert.equals(
"https://github.com/chrishrb/gx.nvim/issues/2",
handler.handle("v", "New Error #2")
"https://github.com/chrishrb/gx.nvim/issues/51",
handler.handle("v", "This is a squashed PR (#51)")
)
end)
end)

0 comments on commit 075bc1c

Please sign in to comment.