From 22a11b3da2d49beb7c0848f8befbba9b8d87aa1f Mon Sep 17 00:00:00 2001 From: John Vandenberg Date: Mon, 8 Jul 2019 20:24:52 +0700 Subject: [PATCH] Support ports for git@ URLs --- giturlparse/parser.py | 4 ++-- test/conftest.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/giturlparse/parser.py b/giturlparse/parser.py index 3dd86ed..d40b35f 100644 --- a/giturlparse/parser.py +++ b/giturlparse/parser.py @@ -51,9 +51,9 @@ r'(?P(\/(?P\w+)/)?' r'(\/?(?P[\w\-]+)(\.git)?)?)$'), re.compile(r'^(?:(?P.+)@)*' - r'(?P[a-z0-9_.-]*)[:/]*' + r'(?P[a-z0-9_.-]*)[:]*' r'(?P[\d]+){0,1}' - r'[:](?P\/?(?P.+)/(?P.+).git)$'), + r'(?P\/?(?P.+)/(?P.+).git)$'), re.compile(r'((?P\w+)@)?' r'((?P[\w\.\-]+))' r'[\:\/]{1,2}' diff --git a/test/conftest.py b/test/conftest.py index 664f926..3a49993 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -277,6 +277,17 @@ def second_match_urls(): 'name': 'repo', 'owner': 'owner', }, + 'git+ssh://example.com:9999/owner/repo.git': { + 'pathname': '/owner/repo.git', + 'protocols': ['git', 'ssh'], + 'protocol': 'ssh', + 'href': 'git+ssh://example.com:9999/owner/repo.git', + 'resource': 'example.com', + 'user': None, + 'port': '9999', + 'name': 'repo', + 'owner': 'owner', + }, 'git+https://example.com/owner/repo.git': { 'pathname': '/owner/repo.git', 'protocols': ['git', 'https'], @@ -288,6 +299,17 @@ def second_match_urls(): 'name': 'repo', 'owner': 'owner', }, + 'git+https://example.com:9999/owner/repo.git': { + 'pathname': '/owner/repo.git', + 'protocols': ['git', 'https'], + 'protocol': 'https', + 'href': 'git+https://example.com:9999/owner/repo.git', + 'resource': 'example.com', + 'user': None, + 'port': '9999', + 'name': 'repo', + 'owner': 'owner', + }, } @@ -327,6 +349,18 @@ def third_match_urls(): 'name': 'repo', 'owner': 'owner', }, + # GitLab + 'user@foo-example.com:9999/owner/repo.git': { + 'pathname': '/owner/repo.git', + 'protocols': [], + 'protocol': 'ssh', + 'href': 'user@foo-example.com:9999/owner/repo.git', + 'resource': 'foo-example.com', + 'user': 'user', + 'port': '9999', + 'name': 'repo', + 'owner': 'owner', + }, }