From fc819d9c0bc788d7bb49a6caac0169f4f0b0693c Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Tue, 25 Apr 2023 12:19:37 +0200 Subject: [PATCH] Fix gitlab regexp to match more samples (#52) * Add parsing variable for user to gitlab parser * Fix gitlab selector --- changes/47.feature | 1 + giturlparse/parser.py | 2 +- giturlparse/platforms/base.py | 1 + giturlparse/platforms/gitlab.py | 8 +-- giturlparse/tests/test_parse.py | 95 +++++++++++++++++++++++++++++++++ 5 files changed, 102 insertions(+), 5 deletions(-) create mode 100644 changes/47.feature diff --git a/changes/47.feature b/changes/47.feature new file mode 100644 index 0000000..d9fbcf0 --- /dev/null +++ b/changes/47.feature @@ -0,0 +1 @@ +Add parsing variable for user to gitlab parser diff --git a/giturlparse/parser.py b/giturlparse/parser.py index db620cf..dcabf5b 100644 --- a/giturlparse/parser.py +++ b/giturlparse/parser.py @@ -35,7 +35,7 @@ def parse(url, check_domain=True): # Skip if not matched if not match: - # print("[%s] URL: %s dit not match %s" % (name, url, regex.pattern)) + print("[{}] URL: {} dit not match {}".format(name, url, regex.pattern)) continue # Skip if domain is bad diff --git a/giturlparse/platforms/base.py b/giturlparse/platforms/base.py index 8ca9bad..328d814 100644 --- a/giturlparse/platforms/base.py +++ b/giturlparse/platforms/base.py @@ -35,6 +35,7 @@ def __init__(self): @staticmethod def clean_data(data): + print(data) data["path"] = "" data["branch"] = "" data["protocols"] = list(filter(lambda x: x, data.get("protocols", "").split("+"))) diff --git a/giturlparse/platforms/gitlab.py b/giturlparse/platforms/gitlab.py index ec094cf..c8be4a3 100644 --- a/giturlparse/platforms/gitlab.py +++ b/giturlparse/platforms/gitlab.py @@ -4,20 +4,20 @@ class GitLabPlatform(BasePlatform): PATTERNS = { "https": ( - r"(?P(git\+)?(?Phttps))://(?P.+?)(?P:[0-9]+)?" + r"(?P(git\+)?(?Phttps))://(?P[^:/]+)(?P:[0-9]+)?" r"(?P/(?P[^/]+?)/" r"(?P.*?)?(?(groups_path)/)?(?P[^/]+?)(?:(\.git)?(/)?)" r"(?P(/blob/|/-/tree/).+)?)$" ), "ssh": ( - r"(?P(git\+)?(?Pssh))?(://)?git@(?P.+?):(?P[0-9]+)?(?(port))?" + r"(?P(git\+)?(?Pssh))?(://)?(?P<_user>.+?)@(?P[^:/]+)(:)?(?P[0-9]+)?(?(port))?" r"(?P/?(?P[^/]+)/" r"(?P.*?)?(?(groups_path)/)?(?P[^/]+?)(?:(\.git)?(/)?)" r"(?P(/blob/|/-/tree/).+)?)$" ), "git": ( - r"(?P(?Pgit))://(?P.+?):(?P[0-9]+)?(?(port))?" - r"(?P/?(?P[^/]+)/" + r"(?P(?Pgit))://(?P[^:/]+):?(?P[0-9]+)?(?(port))?" + r"(?P/(?P[^/]+?)/" r"(?P.*?)?(?(groups_path)/)?(?P[^/]+?)(?:(\.git)?(/)?)" r"(?P(/blob/|/-/tree/).+)?)$" ), diff --git a/giturlparse/tests/test_parse.py b/giturlparse/tests/test_parse.py index 3d65ee4..b8a0f31 100644 --- a/giturlparse/tests/test_parse.py +++ b/giturlparse/tests/test_parse.py @@ -500,6 +500,29 @@ }, ), ), + ( + "GIT", + ( + "git://host.org/Org/Group/subGroup/Repo.git/blob/master/giturlparse/github.py", + { + "host": "host.org", + "resource": "host.org", + "user": "git", + "port": "", + "owner": "Org", + "repo": "Repo", + "name": "Repo", + "groups": ["Group", "subGroup"], + "path": "master/giturlparse/github.py", + "path_raw": "/blob/master/giturlparse/github.py", + "pathname": "/Org/Group/subGroup/Repo.git/blob/master/giturlparse/github.py", + "branch": "", + "protocol": "git", + "protocols": ["git"], + "platform": "gitlab", + }, + ), + ), ( "GIT", ( @@ -546,6 +569,78 @@ }, ), ), + ( + "GIT", + ( + "joe@github.com-work:nephila/giturlparse.git", + { + "host": "github.com-work", + "resource": "github.com-work", + "user": "joe", + "port": "", + "owner": "nephila", + "repo": "giturlparse", + "name": "giturlparse", + "groups": [], + "path": "", + "path_raw": "", + "pathname": "nephila/giturlparse.git", + "branch": "", + "protocol": "ssh", + "protocols": [], + "github": False, + "platform": "gitlab", + }, + ), + ), + ( + "SSH", + ( + "git@gitlab.example.com/groupA/projectB.git", + { + "host": "gitlab.example.com", + "resource": "gitlab.example.com", + "user": "git", + "port": "", + "owner": "groupA", + "repo": "projectB", + "name": "projectB", + "groups": [], + "path": "", + "path_raw": "", + "pathname": "/groupA/projectB.git", + "branch": "", + "protocol": "ssh", + "protocols": [], + "github": False, + "platform": "gitlab", + }, + ), + ), + ( + "SSH", + ( + "ssh://git@gitlab.example.com/groupA/projectB.git", + { + "host": "gitlab.example.com", + "resource": "gitlab.example.com", + "user": "git", + "port": "", + "owner": "groupA", + "repo": "projectB", + "name": "projectB", + "groups": [], + "path": "", + "path_raw": "", + "pathname": "/groupA/projectB.git", + "branch": "", + "protocol": "ssh", + "protocols": ["ssh"], + "github": False, + "platform": "gitlab", + }, + ), + ), ) INVALID_PARSE_URLS = (