Skip to content

Commit

Permalink
Fix gitlab regexp to match more samples (#52)
Browse files Browse the repository at this point in the history
* Add parsing variable for user to gitlab parser
* Fix gitlab selector
  • Loading branch information
yakky committed Apr 25, 2023
1 parent 8987fc8 commit fc819d9
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 5 deletions.
1 change: 1 addition & 0 deletions changes/47.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add parsing variable for user to gitlab parser
2 changes: 1 addition & 1 deletion giturlparse/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions giturlparse/platforms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("+")))
Expand Down
8 changes: 4 additions & 4 deletions giturlparse/platforms/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
class GitLabPlatform(BasePlatform):
PATTERNS = {
"https": (
r"(?P<protocols>(git\+)?(?P<protocol>https))://(?P<domain>.+?)(?P<port>:[0-9]+)?"
r"(?P<protocols>(git\+)?(?P<protocol>https))://(?P<domain>[^:/]+)(?P<port>:[0-9]+)?"
r"(?P<pathname>/(?P<owner>[^/]+?)/"
r"(?P<groups_path>.*?)?(?(groups_path)/)?(?P<repo>[^/]+?)(?:(\.git)?(/)?)"
r"(?P<path_raw>(/blob/|/-/tree/).+)?)$"
),
"ssh": (
r"(?P<protocols>(git\+)?(?P<protocol>ssh))?(://)?git@(?P<domain>.+?):(?P<port>[0-9]+)?(?(port))?"
r"(?P<protocols>(git\+)?(?P<protocol>ssh))?(://)?(?P<_user>.+?)@(?P<domain>[^:/]+)(:)?(?P<port>[0-9]+)?(?(port))?"
r"(?P<pathname>/?(?P<owner>[^/]+)/"
r"(?P<groups_path>.*?)?(?(groups_path)/)?(?P<repo>[^/]+?)(?:(\.git)?(/)?)"
r"(?P<path_raw>(/blob/|/-/tree/).+)?)$"
),
"git": (
r"(?P<protocols>(?P<protocol>git))://(?P<domain>.+?):(?P<port>[0-9]+)?(?(port))?"
r"(?P<pathname>/?(?P<owner>[^/]+)/"
r"(?P<protocols>(?P<protocol>git))://(?P<domain>[^:/]+):?(?P<port>[0-9]+)?(?(port))?"
r"(?P<pathname>/(?P<owner>[^/]+?)/"
r"(?P<groups_path>.*?)?(?(groups_path)/)?(?P<repo>[^/]+?)(?:(\.git)?(/)?)"
r"(?P<path_raw>(/blob/|/-/tree/).+)?)$"
),
Expand Down
95 changes: 95 additions & 0 deletions giturlparse/tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
(
Expand Down Expand Up @@ -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 = (
Expand Down

0 comments on commit fc819d9

Please sign in to comment.