Skip to content

Commit c6efbfd

Browse files
authored
Merge 9b38442 into f7255c0
2 parents f7255c0 + 9b38442 commit c6efbfd

File tree

4 files changed

+93
-15
lines changed

4 files changed

+93
-15
lines changed

changes/42.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix Gitlab URLs with branch

giturlparse/platforms/gitlab.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ class GitLabPlatform(BasePlatform):
77
r"(?P<protocols>(git\+)?(?P<protocol>https))://(?P<domain>[^:/]+)(?P<port>:[0-9]+)?"
88
r"(?P<pathname>/(?P<owner>[^/]+?)/"
99
r"(?P<groups_path>.*?)?(?(groups_path)/)?(?P<repo>[^/]+?)(?:(\.git)?(/)?)"
10-
r"(?P<path_raw>(/blob/|/-/tree/).+)?)$"
10+
r"(?P<path_raw>(/blob/|/-/blob/|/-/tree/).+)?)$"
1111
),
1212
"ssh": (
1313
r"(?P<protocols>(git\+)?(?P<protocol>ssh))?(://)?(?P<_user>.+?)@(?P<domain>[^:/]+)(:)?(?P<port>[0-9]+)?(?(port))?"
1414
r"(?P<pathname>/?(?P<owner>[^/]+)/"
1515
r"(?P<groups_path>.*?)?(?(groups_path)/)?(?P<repo>[^/]+?)(?:(\.git)?(/)?)"
16-
r"(?P<path_raw>(/blob/|/-/tree/).+)?)$"
16+
r"(?P<path_raw>(/blob/|/-/blob/|/-/tree/).+)?)$"
1717
),
1818
"git": (
1919
r"(?P<protocols>(?P<protocol>git))://(?P<domain>[^:/]+):?(?P<port>[0-9]+)?(?(port))?"
2020
r"(?P<pathname>/(?P<owner>[^/]+?)/"
2121
r"(?P<groups_path>.*?)?(?(groups_path)/)?(?P<repo>[^/]+?)(?:(\.git)?(/)?)"
22-
r"(?P<path_raw>(/blob/|/-/tree/).+)?)$"
22+
r"(?P<path_raw>(/blob/|/-/blob/|/-/tree/).+)?)$"
2323
),
2424
}
2525
FORMATS = {
@@ -38,6 +38,8 @@ def clean_data(data):
3838
data = BasePlatform.clean_data(data)
3939
if data["path_raw"].startswith("/blob/"):
4040
data["path"] = data["path_raw"].replace("/blob/", "")
41+
if data["path_raw"].startswith("/-/blob/"):
42+
data["path"] = data["path_raw"].replace("/-/blob/", "")
4143
if data["path_raw"].startswith("/-/tree/"):
4244
data["branch"] = data["path_raw"].replace("/-/tree/", "")
4345
return data

giturlparse/tests/test_parse.py

Lines changed: 82 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,77 @@
457457
(
458458
"HTTPS",
459459
(
460-
"https://gitlab.com/nephila/group2/third-group/giturlparse/blob/master/" "giturlparse/platforms/github.py",
460+
"https://gitlab.com/nephila/git-urlparse/blob/master/giturlparse/github.py",
461+
{
462+
"host": "gitlab.com",
463+
"resource": "gitlab.com",
464+
"user": "git",
465+
"port": "",
466+
"owner": "nephila",
467+
"repo": "git-urlparse",
468+
"name": "git-urlparse",
469+
"groups": [],
470+
"path": "master/giturlparse/github.py",
471+
"path_raw": "/blob/master/giturlparse/github.py",
472+
"pathname": "/nephila/git-urlparse/blob/master/giturlparse/github.py",
473+
"branch": "",
474+
"protocol": "https",
475+
"protocols": ["https"],
476+
"platform": "gitlab",
477+
},
478+
),
479+
),
480+
(
481+
"HTTPS",
482+
(
483+
"https://gitlab.com/nephila/git-urlparse/-/blob/master/giturlparse/github.py",
484+
{
485+
"host": "gitlab.com",
486+
"resource": "gitlab.com",
487+
"user": "git",
488+
"port": "",
489+
"owner": "nephila",
490+
"repo": "git-urlparse",
491+
"name": "git-urlparse",
492+
"groups": [],
493+
"path": "master/giturlparse/github.py",
494+
"path_raw": "/-/blob/master/giturlparse/github.py",
495+
"pathname": "/nephila/git-urlparse/-/blob/master/giturlparse/github.py",
496+
"branch": "",
497+
"protocol": "https",
498+
"protocols": ["https"],
499+
"platform": "gitlab",
500+
},
501+
),
502+
),
503+
(
504+
"HTTPS",
505+
(
506+
"https://gitlab.com/nephila/giturlparse/-/blob/master/giturlparse/github.py",
507+
{
508+
"host": "gitlab.com",
509+
"resource": "gitlab.com",
510+
"user": "git",
511+
"port": "",
512+
"owner": "nephila",
513+
"repo": "giturlparse",
514+
"name": "giturlparse",
515+
"groups": [],
516+
"path": "master/giturlparse/github.py",
517+
"path_raw": "/-/blob/master/giturlparse/github.py",
518+
"pathname": "/nephila/giturlparse/-/blob/master/giturlparse/github.py",
519+
"branch": "",
520+
"protocol": "https",
521+
"protocols": ["https"],
522+
"platform": "gitlab",
523+
},
524+
),
525+
),
526+
(
527+
"HTTPS",
528+
(
529+
"https://gitlab.com/nephila/group2/third-group/giturlparse/-/blob/master/"
530+
"giturlparse/platforms/github.py",
461531
{
462532
"host": "gitlab.com",
463533
"resource": "gitlab.com",
@@ -468,8 +538,8 @@
468538
"name": "giturlparse",
469539
"groups": ["group2", "third-group"],
470540
"path": "master/giturlparse/platforms/github.py",
471-
"path_raw": "/blob/master/giturlparse/platforms/github.py",
472-
"pathname": "/nephila/group2/third-group/giturlparse/blob/master/" "giturlparse/platforms/github.py",
541+
"path_raw": "/-/blob/master/giturlparse/platforms/github.py",
542+
"pathname": "/nephila/group2/third-group/giturlparse/-/blob/master/" "giturlparse/platforms/github.py",
473543
"branch": "",
474544
"protocol": "https",
475545
"protocols": ["https"],
@@ -480,7 +550,7 @@
480550
(
481551
"SSH",
482552
(
483-
"git@host.org:9999/Org/Group/subGroup/Repo.git/blob/master/giturlparse/github.py",
553+
"git@host.org:9999/Org/Group/subGroup/Repo.git/-/blob/master/giturlparse/github.py",
484554
{
485555
"host": "host.org",
486556
"resource": "host.org",
@@ -491,8 +561,8 @@
491561
"name": "Repo",
492562
"groups": ["Group", "subGroup"],
493563
"path": "master/giturlparse/github.py",
494-
"path_raw": "/blob/master/giturlparse/github.py",
495-
"pathname": "/Org/Group/subGroup/Repo.git/blob/master/giturlparse/github.py",
564+
"path_raw": "/-/blob/master/giturlparse/github.py",
565+
"pathname": "/Org/Group/subGroup/Repo.git/-/blob/master/giturlparse/github.py",
496566
"branch": "",
497567
"protocol": "ssh",
498568
"protocols": [],
@@ -503,7 +573,7 @@
503573
(
504574
"GIT",
505575
(
506-
"git://host.org:9999/Org/Group/subGroup/Repo.git/blob/master/giturlparse/github.py",
576+
"git://host.org:9999/Org/Group/subGroup/Repo.git/-/blob/master/giturlparse/github.py",
507577
{
508578
"host": "host.org",
509579
"resource": "host.org",
@@ -514,8 +584,8 @@
514584
"name": "Repo",
515585
"groups": ["Group", "subGroup"],
516586
"path": "master/giturlparse/github.py",
517-
"path_raw": "/blob/master/giturlparse/github.py",
518-
"pathname": "/Org/Group/subGroup/Repo.git/blob/master/giturlparse/github.py",
587+
"path_raw": "/-/blob/master/giturlparse/github.py",
588+
"pathname": "/Org/Group/subGroup/Repo.git/-/blob/master/giturlparse/github.py",
519589
"branch": "",
520590
"protocol": "git",
521591
"protocols": ["git"],
@@ -526,7 +596,7 @@
526596
(
527597
"GIT",
528598
(
529-
"git://host.org/Org/Group/subGroup/Repo.git/blob/master/giturlparse/github.py",
599+
"git://host.org/Org/Group/subGroup/Repo.git/-/blob/master/giturlparse/github.py",
530600
{
531601
"host": "host.org",
532602
"resource": "host.org",
@@ -537,8 +607,8 @@
537607
"name": "Repo",
538608
"groups": ["Group", "subGroup"],
539609
"path": "master/giturlparse/github.py",
540-
"path_raw": "/blob/master/giturlparse/github.py",
541-
"pathname": "/Org/Group/subGroup/Repo.git/blob/master/giturlparse/github.py",
610+
"path_raw": "/-/blob/master/giturlparse/github.py",
611+
"pathname": "/Org/Group/subGroup/Repo.git/-/blob/master/giturlparse/github.py",
542612
"branch": "",
543613
"protocol": "git",
544614
"protocols": ["git"],

giturlparse/tests/test_rewrite.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@
5151
("https://host.org/Org/Repo.git", "ssh", "git@host.org:Org/Repo.git"),
5252
("https://host.org/Org/Repo.git", "https", "https://host.org/Org/Repo.git"),
5353
("https://host.org/Org/Group/Repo.git", "ssh", "git@host.org:Org/Group/Repo.git"),
54+
(
55+
"https://host.org/Org/Group/Repo/-/blob/master/file.py",
56+
"ssh",
57+
"git@host.org:Org/Group/Repo.git/-/blob/master/file.py",
58+
),
5459
(
5560
"https://host.org/Org/Group/Repo/blob/master/file.py",
5661
"ssh",

0 commit comments

Comments
 (0)