Skip to content

Commit fc819d9

Browse files
authored
Fix gitlab regexp to match more samples (#52)
* Add parsing variable for user to gitlab parser * Fix gitlab selector
1 parent 8987fc8 commit fc819d9

5 files changed

Lines changed: 102 additions & 5 deletions

File tree

changes/47.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add parsing variable for user to gitlab parser

giturlparse/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def parse(url, check_domain=True):
3535

3636
# Skip if not matched
3737
if not match:
38-
# print("[%s] URL: %s dit not match %s" % (name, url, regex.pattern))
38+
print("[{}] URL: {} dit not match {}".format(name, url, regex.pattern))
3939
continue
4040

4141
# Skip if domain is bad

giturlparse/platforms/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def __init__(self):
3535

3636
@staticmethod
3737
def clean_data(data):
38+
print(data)
3839
data["path"] = ""
3940
data["branch"] = ""
4041
data["protocols"] = list(filter(lambda x: x, data.get("protocols", "").split("+")))

giturlparse/platforms/gitlab.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
class GitLabPlatform(BasePlatform):
55
PATTERNS = {
66
"https": (
7-
r"(?P<protocols>(git\+)?(?P<protocol>https))://(?P<domain>.+?)(?P<port>:[0-9]+)?"
7+
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)?(/)?)"
1010
r"(?P<path_raw>(/blob/|/-/tree/).+)?)$"
1111
),
1212
"ssh": (
13-
r"(?P<protocols>(git\+)?(?P<protocol>ssh))?(://)?git@(?P<domain>.+?):(?P<port>[0-9]+)?(?(port))?"
13+
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)?(/)?)"
1616
r"(?P<path_raw>(/blob/|/-/tree/).+)?)$"
1717
),
1818
"git": (
19-
r"(?P<protocols>(?P<protocol>git))://(?P<domain>.+?):(?P<port>[0-9]+)?(?(port))?"
20-
r"(?P<pathname>/?(?P<owner>[^/]+)/"
19+
r"(?P<protocols>(?P<protocol>git))://(?P<domain>[^:/]+):?(?P<port>[0-9]+)?(?(port))?"
20+
r"(?P<pathname>/(?P<owner>[^/]+?)/"
2121
r"(?P<groups_path>.*?)?(?(groups_path)/)?(?P<repo>[^/]+?)(?:(\.git)?(/)?)"
2222
r"(?P<path_raw>(/blob/|/-/tree/).+)?)$"
2323
),

giturlparse/tests/test_parse.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,29 @@
500500
},
501501
),
502502
),
503+
(
504+
"GIT",
505+
(
506+
"git://host.org/Org/Group/subGroup/Repo.git/blob/master/giturlparse/github.py",
507+
{
508+
"host": "host.org",
509+
"resource": "host.org",
510+
"user": "git",
511+
"port": "",
512+
"owner": "Org",
513+
"repo": "Repo",
514+
"name": "Repo",
515+
"groups": ["Group", "subGroup"],
516+
"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",
519+
"branch": "",
520+
"protocol": "git",
521+
"protocols": ["git"],
522+
"platform": "gitlab",
523+
},
524+
),
525+
),
503526
(
504527
"GIT",
505528
(
@@ -546,6 +569,78 @@
546569
},
547570
),
548571
),
572+
(
573+
"GIT",
574+
(
575+
"joe@github.com-work:nephila/giturlparse.git",
576+
{
577+
"host": "github.com-work",
578+
"resource": "github.com-work",
579+
"user": "joe",
580+
"port": "",
581+
"owner": "nephila",
582+
"repo": "giturlparse",
583+
"name": "giturlparse",
584+
"groups": [],
585+
"path": "",
586+
"path_raw": "",
587+
"pathname": "nephila/giturlparse.git",
588+
"branch": "",
589+
"protocol": "ssh",
590+
"protocols": [],
591+
"github": False,
592+
"platform": "gitlab",
593+
},
594+
),
595+
),
596+
(
597+
"SSH",
598+
(
599+
"git@gitlab.example.com/groupA/projectB.git",
600+
{
601+
"host": "gitlab.example.com",
602+
"resource": "gitlab.example.com",
603+
"user": "git",
604+
"port": "",
605+
"owner": "groupA",
606+
"repo": "projectB",
607+
"name": "projectB",
608+
"groups": [],
609+
"path": "",
610+
"path_raw": "",
611+
"pathname": "/groupA/projectB.git",
612+
"branch": "",
613+
"protocol": "ssh",
614+
"protocols": [],
615+
"github": False,
616+
"platform": "gitlab",
617+
},
618+
),
619+
),
620+
(
621+
"SSH",
622+
(
623+
"ssh://git@gitlab.example.com/groupA/projectB.git",
624+
{
625+
"host": "gitlab.example.com",
626+
"resource": "gitlab.example.com",
627+
"user": "git",
628+
"port": "",
629+
"owner": "groupA",
630+
"repo": "projectB",
631+
"name": "projectB",
632+
"groups": [],
633+
"path": "",
634+
"path_raw": "",
635+
"pathname": "/groupA/projectB.git",
636+
"branch": "",
637+
"protocol": "ssh",
638+
"protocols": ["ssh"],
639+
"github": False,
640+
"platform": "gitlab",
641+
},
642+
),
643+
),
549644
)
550645

551646
INVALID_PARSE_URLS = (

0 commit comments

Comments
 (0)