21
21
22
22
from readthedocs .core .utils import broadcast
23
23
from readthedocs .projects .constants import (
24
- BITBUCKET_REGEXS , BITBUCKET_URL , GITHUB_REGEXS , GITHUB_URL , GITLAB_REGEXS ,
25
- GITLAB_URL , PRIVACY_CHOICES , PRIVATE )
24
+ BITBUCKET_URL , GITHUB_URL , GITLAB_URL , PRIVACY_CHOICES , PRIVATE )
26
25
from readthedocs .projects .models import APIProject , Project
27
26
28
27
from .constants import (
29
28
BRANCH , BUILD_STATE , BUILD_STATE_FINISHED , BUILD_TYPES , LATEST ,
30
29
NON_REPOSITORY_VERSIONS , STABLE , TAG , VERSION_TYPES )
31
30
from .managers import VersionManager
32
31
from .querysets import BuildQuerySet , RelatedBuildQuerySet , VersionQuerySet
32
+ from .utils import (
33
+ get_bitbucket_username_repo , get_github_username_repo ,
34
+ get_gitlab_username_repo )
33
35
from .version_slug import VersionSlugField
34
36
35
37
DEFAULT_VERSION_PRIVACY_LEVEL = getattr (
@@ -277,12 +279,8 @@ def get_github_url(
277
279
elif action == 'edit' :
278
280
action_string = 'edit'
279
281
280
- for regex in GITHUB_REGEXS :
281
- match = regex .search (repo_url )
282
- if match :
283
- user , repo = match .groups ()
284
- break
285
- else :
282
+ user , repo = get_github_username_repo (repo_url )
283
+ if not user and not repo :
286
284
return ''
287
285
repo = repo .rstrip ('/' )
288
286
@@ -315,12 +313,8 @@ def get_gitlab_url(
315
313
elif action == 'edit' :
316
314
action_string = 'edit'
317
315
318
- for regex in GITLAB_REGEXS :
319
- match = regex .search (repo_url )
320
- if match :
321
- user , repo = match .groups ()
322
- break
323
- else :
316
+ user , repo = get_gitlab_username_repo (repo_url )
317
+ if not user and not repo :
324
318
return ''
325
319
repo = repo .rstrip ('/' )
326
320
@@ -341,12 +335,8 @@ def get_bitbucket_url(self, docroot, filename, source_suffix='.rst'):
341
335
if not docroot :
342
336
return ''
343
337
344
- for regex in BITBUCKET_REGEXS :
345
- match = regex .search (repo_url )
346
- if match :
347
- user , repo = match .groups ()
348
- break
349
- else :
338
+ user , repo = get_bitbucket_username_repo (repo_url )
339
+ if not user and not repo :
350
340
return ''
351
341
repo = repo .rstrip ('/' )
352
342
0 commit comments