pr: Unify clone url generation of shadow repository.

This commit is contained in:
Martin Bornhold 2016-09-21 09:34:47 +02:00
parent 3a69737da4
commit a385c08a46
3 changed files with 11 additions and 6 deletions

View file

@ -111,9 +111,6 @@ class SimpleVCS(object):
This will populate the attributes acl_repo_name, url_repo_name,
vcs_repo_name and pr_id on the current instance.
"""
# TODO: martinb: Unify generation/suffix of clone url. It is currently
# used here in the regex, in PullRequest in get_api_data() and
# indirectly in routing configuration.
# TODO: martinb: Move to class or module scope.
# TODO: martinb: Check if we have to use re.UNICODE.
# TODO: martinb: Check which chars are allowed for repo/group names.

View file

@ -3140,8 +3140,8 @@ class PullRequest(Base, _PullRequestBase):
},
},
'shadow': {
# TODO: martinb: Unify generation/suffix of clone url.
'clone_url': '{}/repository'.format(pull_request_url),
'clone_url': PullRequestModel().get_shadow_clone_url(
pull_request),
},
'author': pull_request.author.get_api_data(include_secrets=False,
details='basic'),

View file

@ -777,7 +777,15 @@ class PullRequestModel(BaseModel):
qualified=True)
def get_shadow_clone_url(self, pull_request):
return u'{url}/repository'.format(url=self.get_url(pull_request))
"""
Returns qualified url pointing to the shadow repository. If this pull
request is closed there is no shadow repository and ``None`` will be
returned.
"""
if pull_request.is_closed():
return None
else:
return u'{url}/repository'.format(url=self.get_url(pull_request))
def notify_reviewers(self, pull_request, reviewers_ids):
# notification to reviewers