# HG changeset patch # User Martin Bornhold # Date 2016-09-21 07:34:47 # Node ID b8b5fdac29837563d6ba10ed666d711db6ecf234 # Parent a4f1049ad9a010b7dd71c4a1e502a893be8bc768 pr: Unify clone url generation of shadow repository. diff --git a/rhodecode/lib/middleware/simplevcs.py b/rhodecode/lib/middleware/simplevcs.py --- a/rhodecode/lib/middleware/simplevcs.py +++ b/rhodecode/lib/middleware/simplevcs.py @@ -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. diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py --- a/rhodecode/model/db.py +++ b/rhodecode/model/db.py @@ -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'), diff --git a/rhodecode/model/pull_request.py b/rhodecode/model/pull_request.py --- a/rhodecode/model/pull_request.py +++ b/rhodecode/model/pull_request.py @@ -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