Skip to content

Commit

Permalink
Add support also for "/blob/"
Browse files Browse the repository at this point in the history
For retrocompatibility
  • Loading branch information
boozec committed Sep 2, 2023
1 parent 7e90210 commit 9b38442
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 3 deletions.
8 changes: 5 additions & 3 deletions giturlparse/platforms/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ class GitLabPlatform(BasePlatform):
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/).+)?)$"
r"(?P<path_raw>(/blob/|/-/blob/|/-/tree/).+)?)$"
),
"ssh": (
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/).+)?)$"
r"(?P<path_raw>(/blob/|/-/blob/|/-/tree/).+)?)$"
),
"git": (
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/).+)?)$"
r"(?P<path_raw>(/blob/|/-/blob/|/-/tree/).+)?)$"
),
}
FORMATS = {
Expand All @@ -36,6 +36,8 @@ class GitLabPlatform(BasePlatform):
@staticmethod
def clean_data(data):
data = BasePlatform.clean_data(data)
if data["path_raw"].startswith("/blob/"):
data["path"] = data["path_raw"].replace("/blob/", "")
if data["path_raw"].startswith("/-/blob/"):
data["path"] = data["path_raw"].replace("/-/blob/", "")
if data["path_raw"].startswith("/-/tree/"):
Expand Down
69 changes: 69 additions & 0 deletions giturlparse/tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,75 @@
},
),
),
(
"HTTPS",
(
"https://gitlab.com/nephila/giturlparse/blob/master/giturlparse/github.py",
{
"host": "gitlab.com",
"resource": "gitlab.com",
"user": "git",
"port": "",
"owner": "nephila",
"repo": "giturlparse",
"name": "giturlparse",
"groups": [],
"path": "master/giturlparse/github.py",
"path_raw": "/blob/master/giturlparse/github.py",
"pathname": "/nephila/giturlparse/blob/master/giturlparse/github.py",
"branch": "",
"protocol": "https",
"protocols": ["https"],
"platform": "gitlab",
},
),
),
(
"HTTPS",
(
"https://gitlab.com/nephila/git-urlparse/blob/master/giturlparse/github.py",
{
"host": "gitlab.com",
"resource": "gitlab.com",
"user": "git",
"port": "",
"owner": "nephila",
"repo": "git-urlparse",
"name": "git-urlparse",
"groups": [],
"path": "master/giturlparse/github.py",
"path_raw": "/blob/master/giturlparse/github.py",
"pathname": "/nephila/git-urlparse/blob/master/giturlparse/github.py",
"branch": "",
"protocol": "https",
"protocols": ["https"],
"platform": "gitlab",
},
),
),
(
"HTTPS",
(
"https://gitlab.com/nephila/git-urlparse/-/blob/master/giturlparse/github.py",
{
"host": "gitlab.com",
"resource": "gitlab.com",
"user": "git",
"port": "",
"owner": "nephila",
"repo": "git-urlparse",
"name": "git-urlparse",
"groups": [],
"path": "master/giturlparse/github.py",
"path_raw": "/-/blob/master/giturlparse/github.py",
"pathname": "/nephila/git-urlparse/-/blob/master/giturlparse/github.py",
"branch": "",
"protocol": "https",
"protocols": ["https"],
"platform": "gitlab",
},
),
),
(
"HTTPS",
(
Expand Down
5 changes: 5 additions & 0 deletions giturlparse/tests/test_rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
"ssh",
"git@host.org:Org/Group/Repo.git/-/blob/master/file.py",
),
(
"https://host.org/Org/Group/Repo/blob/master/file.py",
"ssh",
"git@host.org:Org/Group/Repo.git/blob/master/file.py",
),
)

INVALID_PARSE_URLS = (
Expand Down

0 comments on commit 9b38442

Please sign in to comment.