Skip to content

Commit 087edea

Browse files
rokroskarjirikuncar
authored andcommitted
models: fix git regex
closes #374
1 parent fbb8c5c commit 087edea

File tree

2 files changed

+63
-25
lines changed

2 files changed

+63
-25
lines changed

renku/models/_git.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@
4040
_RE_PORT = r':(?P<port>\d+)'
4141

4242
_RE_PATHNAME = (
43-
r'/(?P<pathname>'
43+
r'(?P<pathname>'
4444
r'(((?P<owner>[\w\-\.]+)/)?(?P<name>[\w\-\.]+)(\.git)?)?)'
4545
)
4646

4747
_RE_PREFIXED_PATHNAME = (
48-
r'/(?P<pathname>(([\w\-\~\.]+)/)+'
48+
r'(?P<pathname>(([\w\-\~\.]+)/)+'
4949
r'(?P<owner>[\w\-\.]+)/(?P<name>[\w\-\.]+)(\.git)?)'
5050
)
5151

@@ -62,21 +62,36 @@ def _build(*parts):
6262

6363
#: Define possible repository URLs.
6464
_REPOSITORY_URLS = (
65-
_build(_RE_PROTOCOL, _RE_USERNAME_PASSWORD, _RE_HOSTNAME, _RE_PATHNAME),
65+
# https://user:[email protected]/owner/repo.git
6666
_build(
67-
_RE_PROTOCOL, _RE_USERNAME_PASSWORD, _RE_HOSTNAME,
67+
_RE_PROTOCOL, _RE_USERNAME_PASSWORD, _RE_HOSTNAME, r'/', _RE_PATHNAME
68+
),
69+
70+
# https://user:[email protected]/prefix/owner/repo.git
71+
_build(
72+
_RE_PROTOCOL, _RE_USERNAME_PASSWORD, _RE_HOSTNAME, r'/',
6873
_RE_PREFIXED_PATHNAME
69-
), _build(_RE_USERNAME, _RE_HOSTNAME, _RE_PATHNAME),
74+
),
75+
76+
# https://user:[email protected]:1234/owner/repo.git
7077
_build(
71-
_RE_PROTOCOL, _RE_USERNAME_PASSWORD, _RE_HOSTNAME, _RE_PORT,
78+
_RE_PROTOCOL, _RE_USERNAME_PASSWORD, _RE_HOSTNAME, _RE_PORT, r'/',
7279
_RE_PATHNAME
7380
),
81+
82+
# https://user:[email protected]:1234/prefix/owner/repo.git
7483
_build(
75-
_RE_PROTOCOL, _RE_USERNAME_PASSWORD, _RE_HOSTNAME, _RE_PORT,
84+
_RE_PROTOCOL, _RE_USERNAME_PASSWORD, _RE_HOSTNAME, _RE_PORT, r'/',
7685
_RE_PREFIXED_PATHNAME
77-
), _build(_RE_USERNAME, _RE_HOSTNAME, _RE_PREFIXED_PATHNAME),
78-
_build(_RE_USERNAME, _RE_HOSTNAME, _RE_PORT, _RE_PATHNAME),
79-
_build(_RE_USERNAME, _RE_HOSTNAME, _RE_PORT, _RE_PREFIXED_PATHNAME),
86+
),
87+
88+
# [email protected]:owner/repo.git
89+
_build(_RE_USERNAME, _RE_HOSTNAME, r':', _RE_PATHNAME),
90+
91+
# [email protected]:prefix/owner/repo.git
92+
_build(_RE_USERNAME, _RE_HOSTNAME, r':', _RE_PREFIXED_PATHNAME),
93+
94+
# /path/to/repo
8095
_build(_RE_UNIXPATH)
8196
)
8297

tests/models/test_git.py

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,41 +120,55 @@
120120
'username': 'user',
121121
'password': 'pass',
122122
},
123+
pytest.param(
124+
{
125+
'href': '[email protected]/repo.git',
126+
'protocol': 'ssh',
127+
'hostname': 'example.com',
128+
'name': 'repo',
129+
'pathname': 'repo.git',
130+
'username': 'git',
131+
},
132+
marks=pytest.mark.
133+
xfail(raises=errors.ConfigurationError, strict=True),
134+
),
135+
pytest.param(
136+
{
137+
'href': '[email protected]/owner/repo.git',
138+
'protocol': 'ssh',
139+
'hostname': 'example.com',
140+
'name': 'repo',
141+
'pathname': 'owner/repo.git',
142+
'owner': 'owner',
143+
'username': 'git',
144+
},
145+
marks=pytest.mark.
146+
xfail(raises=errors.ConfigurationError, strict=True),
147+
),
123148
{
124-
'href': '[email protected]/repo.git',
149+
'href': '[email protected]:repo.git',
125150
'protocol': 'ssh',
126151
'hostname': 'example.com',
127152
'name': 'repo',
128153
'pathname': 'repo.git',
129154
'username': 'git',
130155
},
131156
{
132-
'href': '[email protected]/owner/repo.git',
133-
'protocol': 'ssh',
134-
'hostname': 'example.com',
135-
'name': 'repo',
136-
'pathname': 'owner/repo.git',
137-
'owner': 'owner',
138-
'username': 'git',
139-
},
140-
{
141-
'href': '[email protected]:1234/owner/repo.git',
157+
'href': '[email protected]:owner/repo.git',
142158
'protocol': 'ssh',
143159
'hostname': 'example.com',
144160
'name': 'repo',
145161
'pathname': 'owner/repo.git',
146162
'owner': 'owner',
147-
'port': '1234',
148163
'username': 'git',
149164
},
150165
{
151-
'href': '[email protected]:1234/prefix/owner/repo.git',
166+
'href': '[email protected]:prefix/owner/repo.git',
152167
'protocol': 'ssh',
153168
'hostname': 'example.com',
154169
'name': 'repo',
155170
'pathname': 'prefix/owner/repo.git',
156171
'owner': 'owner',
157-
'port': '1234',
158172
'username': 'git',
159173
},
160174
{
@@ -201,7 +215,7 @@
201215
pytest.param(
202216
{
203217
'href': '[email protected]:1234:owner/repo.git',
204-
'protocol': 'https',
218+
'protocol': 'ssh',
205219
'hostname': 'example.com',
206220
'port': '1234',
207221
'name': 'repo',
@@ -211,6 +225,15 @@
211225
marks=pytest.mark.
212226
xfail(raises=errors.ConfigurationError, strict=True),
213227
),
228+
{
229+
'href': '[email protected]:1234/prefix/owner/repo.git',
230+
'username': 'git',
231+
'protocol': 'ssh',
232+
'hostname': 'example.com',
233+
'name': 'repo',
234+
'pathname': '1234/prefix/owner/repo.git',
235+
'owner': 'owner',
236+
},
214237
]
215238
)
216239
def test_valid_href(fields):

0 commit comments

Comments
 (0)