From 047d11f3d8a6643e6758475cf167f48be9dd8043 Mon Sep 17 00:00:00 2001 From: "Igor S. Morozov" Date: Wed, 25 Sep 2024 14:46:37 +0200 Subject: [PATCH] Fix for orgs with dashes --- lua/git_browse/url_builder.lua | 2 +- tests/git_browse/url_builder_spec.lua | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lua/git_browse/url_builder.lua b/lua/git_browse/url_builder.lua index 38caf92..9efd690 100644 --- a/lua/git_browse/url_builder.lua +++ b/lua/git_browse/url_builder.lua @@ -31,7 +31,7 @@ M.build_gitlab_url = function(domain, repo, branch_name, path, url_type) end M.build_url = function(remote, current_branch_name, path_in_repo, url_type) - local _, _, domain, repo = string.find(remote, "[htps:/@]+(.*)[/:](%a+/.+)%p.*") + local _, _, domain, repo = string.find(remote, "[htps:/@]+(.*)[/:]([%a-]+/.+)%p.*") if domain and repo then if string.find(domain, "github.com") then diff --git a/tests/git_browse/url_builder_spec.lua b/tests/git_browse/url_builder_spec.lua index b5a0310..2556800 100644 --- a/tests/git_browse/url_builder_spec.lua +++ b/tests/git_browse/url_builder_spec.lua @@ -16,6 +16,13 @@ describe("URL builder", function() ) end) + it("generates a URL from SSH remote and current branch", function() + assert.are.same( + "https://github.com/Morozzzko-with-suffix/git-browse-nvim/tree/main", + module.build_url("git@github.com:Morozzzko-with-suffix/git-browse-nvim.git", "main", nil, "browse") + ) + end) + it("generates a URL from SSH remote and current branch", function() assert.are.same( "https://github.com/Morozzzko/git-browse-nvim/tree/main",