From 639c981c1ffcd282f81687169db6df464d201568 Mon Sep 17 00:00:00 2001 From: linrongbin16 Date: Wed, 12 Jul 2023 09:42:48 +0800 Subject: [PATCH] fix: dash in repo name --- README.md | 20 ++++++++++---------- lua/gitlinker.lua | 16 ++++++++-------- lua/gitlinker/test/test_rules.lua | 10 ++++++++++ 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index b40bfbc..ddb5404 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ in `setup()` function. ## Configuration -```lua +````lua require('gitlinker').setup({ -- print message in command line message = true, @@ -116,16 +116,16 @@ require('gitlinker').setup({ -- regex pattern based rules pattern_rules = { { - ["^git@github%.([_%.%-%w]+):([%.%-%w]+)/([%.%-%w]+)%.git$"] = "https://github.%1/%2/%3/blob/", - ["^https?://github%.([_%.%-%w]+)/([%.%-%w]+)/([%.%-%w]+)%.git$"] = "https://github.%1/%2/%3/blob/", - ["^git@gitlab%.([_%.%-%w]+):([%.%-%w]+)/([%.%-%w]+)%.git$"] = "https://gitlab.%1/%2/%3/blob/", - ["^https?://gitlab%.([_%.%-%w]+)/([%.%-%w]+)/([%.%-%w]+)%.git$"] = "https://gitlab.%1/%2/%3/blob/", + ["^git@github%.([_%.%-%w]+):([%.%-%w]+)/([_%.%-%w]+)%.git$"] = "https://github.%1/%2/%3/blob/", + ["^https?://github%.([_%.%-%w]+)/([%.%-%w]+)/([_%.%-%w]+)%.git$"] = "https://github.%1/%2/%3/blob/", + ["^git@gitlab%.([_%.%-%w]+):([%.%-%w]+)/([_%.%-%w]+)%.git$"] = "https://gitlab.%1/%2/%3/blob/", + ["^https?://gitlab%.([_%.%-%w]+)/([%.%-%w]+)/([_%.%-%w]+)%.git$"] = "https://gitlab.%1/%2/%3/blob/", }, { - ["^git@github%.([_%.%-%w]+):([%.%-%w]+)/([%.%-%w]+)$"] = "https://github.%1/%2/%3/blob/", - ["^https?://github%.([_%.%-%w]+)/([%.%-%w]+)/([%.%-%w]+)$"] = "https://github.%1/%2/%3/blob/", - ["^git@gitlab%.([_%.%-%w]+):([%.%-%w]+)/([%.%-%w]+)$"] = "https://gitlab.%1/%2/%3/blob/", - ["^https?://gitlab%.([_%.%-%w]+)/([%.%-%w]+)/([%.%-%w]+)$"] = "https://gitlab.%1/%2/%3/blob/", + ["^git@github%.([_%.%-%w]+):([%.%-%w]+)/([_%.%-%w]+)$"] = "https://github.%1/%2/%3/blob/", + ["^https?://github%.([_%.%-%w]+)/([%.%-%w]+)/([_%.%-%w]+)$"] = "https://github.%1/%2/%3/blob/", + ["^git@gitlab%.([_%.%-%w]+):([%.%-%w]+)/([_%.%-%w]+)$"] = "https://gitlab.%1/%2/%3/blob/", + ["^https?://gitlab%.([_%.%-%w]+)/([%.%-%w]+)/([_%.%-%w]+)$"] = "https://gitlab.%1/%2/%3/blob/", }, }, @@ -171,4 +171,4 @@ require('gitlinker').setup({ -- write logs to file file_log = false, }) -``` +```` diff --git a/lua/gitlinker.lua b/lua/gitlinker.lua index e327a79..2039710 100644 --- a/lua/gitlinker.lua +++ b/lua/gitlinker.lua @@ -31,16 +31,16 @@ local Defaults = { --- @type table[] pattern_rules = { { - ["^git@github%.([_%.%-%w]+):([%.%-%w]+)/([%.%-%w]+)%.git$"] = "https://github.%1/%2/%3/blob/", - ["^https?://github%.([_%.%-%w]+)/([%.%-%w]+)/([%.%-%w]+)%.git$"] = "https://github.%1/%2/%3/blob/", - ["^git@gitlab%.([_%.%-%w]+):([%.%-%w]+)/([%.%-%w]+)%.git$"] = "https://gitlab.%1/%2/%3/blob/", - ["^https?://gitlab%.([_%.%-%w]+)/([%.%-%w]+)/([%.%-%w]+)%.git$"] = "https://gitlab.%1/%2/%3/blob/", + ["^git@github%.([_%.%-%w]+):([%.%-%w]+)/([_%.%-%w]+)%.git$"] = "https://github.%1/%2/%3/blob/", + ["^https?://github%.([_%.%-%w]+)/([%.%-%w]+)/([_%.%-%w]+)%.git$"] = "https://github.%1/%2/%3/blob/", + ["^git@gitlab%.([_%.%-%w]+):([%.%-%w]+)/([_%.%-%w]+)%.git$"] = "https://gitlab.%1/%2/%3/blob/", + ["^https?://gitlab%.([_%.%-%w]+)/([%.%-%w]+)/([_%.%-%w]+)%.git$"] = "https://gitlab.%1/%2/%3/blob/", }, { - ["^git@github%.([_%.%-%w]+):([%.%-%w]+)/([%.%-%w]+)$"] = "https://github.%1/%2/%3/blob/", - ["^https?://github%.([_%.%-%w]+)/([%.%-%w]+)/([%.%-%w]+)$"] = "https://github.%1/%2/%3/blob/", - ["^git@gitlab%.([_%.%-%w]+):([%.%-%w]+)/([%.%-%w]+)$"] = "https://gitlab.%1/%2/%3/blob/", - ["^https?://gitlab%.([_%.%-%w]+)/([%.%-%w]+)/([%.%-%w]+)$"] = "https://gitlab.%1/%2/%3/blob/", + ["^git@github%.([_%.%-%w]+):([%.%-%w]+)/([_%.%-%w]+)$"] = "https://github.%1/%2/%3/blob/", + ["^https?://github%.([_%.%-%w]+)/([%.%-%w]+)/([_%.%-%w]+)$"] = "https://github.%1/%2/%3/blob/", + ["^git@gitlab%.([_%.%-%w]+):([%.%-%w]+)/([_%.%-%w]+)$"] = "https://gitlab.%1/%2/%3/blob/", + ["^https?://gitlab%.([_%.%-%w]+)/([%.%-%w]+)/([_%.%-%w]+)$"] = "https://gitlab.%1/%2/%3/blob/", }, }, diff --git a/lua/gitlinker/test/test_rules.lua b/lua/gitlinker/test/test_rules.lua index 374339d..66072aa 100644 --- a/lua/gitlinker/test/test_rules.lua +++ b/lua/gitlinker/test/test_rules.lua @@ -66,6 +66,16 @@ local test_cases = { "https://gitlab.com/ruifm/gitlinker.nvim", "https://gitlab.com/ruifm/gitlinker.nvim/blob/", }, + -- [13] + { + "git@github.enterprise.io:organization/repository_with_single_dash1", + "https://github.enterprise.io/organization/repository_with_single_dash1/blob/", + }, + -- [14] + { + "https://github.enterprise.io/organization/repository____multiple___dash2.git", + "https://github.enterprise.io/organization/repository____multiple___dash2/blob/", + }, } for i, case in ipairs(test_cases) do