Changeset - 67962f489ddd
[Not reviewed]
default
0 4 0
Mads Kiilerich - 6 years ago 2019-07-30 22:59:44
mads@kiilerich.com
clone_url: always pass a clone_uri_tmpl, with Repository.DEFAULT_CLONE_URI as last resort

clone_url() had a layering violation of using c.clone_uri_tmpl . This
refactoring now makes it clear that this only was used from
PullRequest.__json__(), so move the hack there and simplify it.
4 files changed with 7 insertions and 19 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/base.py
Show inline comments
 
@@ -403,7 +403,7 @@ class BaseController(TGController):
 
                    })();
 
            </script>''' % c.ga_code
 
        c.site_name = rc_config.get('title')
 
        c.clone_uri_tmpl = rc_config.get('clone_uri_tmpl')
 
        c.clone_uri_tmpl = rc_config.get('clone_uri_tmpl') or Repository.DEFAULT_CLONE_URI
 

	
 
        ## INI stored
 
        c.visual.allow_repo_location_change = str2bool(config.get('allow_repo_location_change', True))
kallithea/model/db.py
Show inline comments
 
@@ -43,6 +43,7 @@ from webob.exc import HTTPNotFound
 

	
 
from tg.i18n import lazy_ugettext as _
 

	
 
import kallithea
 
from kallithea.lib.exceptions import DefaultUserException
 
from kallithea.lib.vcs import get_backend
 
from kallithea.lib.vcs.utils.helpers import get_scm
 
@@ -325,7 +326,6 @@ class Setting(Base, BaseDbModel):
 
    def get_server_info(cls):
 
        import pkg_resources
 
        import platform
 
        import kallithea
 
        from kallithea.lib.utils import check_git_version
 
        mods = [(p.project_name, p.version) for p in pkg_resources.working_set]
 
        info = {
 
@@ -1270,17 +1270,6 @@ class Repository(Base, BaseDbModel):
 
            clone_uri_tmpl = override['clone_uri_tmpl']
 
            del override['clone_uri_tmpl']
 

	
 
        # we didn't override our tmpl from **overrides
 
        if not clone_uri_tmpl:
 
            clone_uri_tmpl = self.DEFAULT_CLONE_URI
 
            try:
 
                from tg import tmpl_context as c
 
                clone_uri_tmpl = c.clone_uri_tmpl
 
            except AttributeError:
 
                # in any case if we call this outside of request context,
 
                # ie, not having tmpl_context set up
 
                pass
 

	
 
        import kallithea.lib.helpers as h
 
        prefix_url = h.canonical_url('home')
 

	
 
@@ -2092,7 +2081,6 @@ class CacheInvalidation(Base, BaseDbMode
 
        Wrapper for generating a unique cache key for this instance and "key".
 
        key must / will start with a repo_name which will be stored in .cache_args .
 
        """
 
        import kallithea
 
        prefix = kallithea.CONFIG.get('instance_id', '')
 
        return "%s%s" % (prefix, key)
 

	
 
@@ -2370,6 +2358,7 @@ class PullRequest(Base, BaseDbModel):
 
        return self.__json__()
 

	
 
    def __json__(self):
 
        clone_uri_tmpl = kallithea.CONFIG.get('clone_uri_tmpl') or Repository.DEFAULT_CLONE_URI
 
        return dict(
 
            pull_request_id=self.pull_request_id,
 
            url=self.url(),
 
@@ -2378,7 +2367,7 @@ class PullRequest(Base, BaseDbModel):
 
            owner=self.owner.username,
 
            title=self.title,
 
            description=self.description,
 
            org_repo_url=self.org_repo.clone_url(),
 
            org_repo_url=self.org_repo.clone_url(clone_uri_tmpl=clone_uri_tmpl),
 
            org_ref_parts=self.org_ref_parts,
 
            other_ref_parts=self.other_ref_parts,
 
            status=self.status,
 
@@ -2479,7 +2468,6 @@ class Gist(Base, BaseDbModel):
 
        return cls.query().filter(cls.gist_access_id == gist_access_id).scalar()
 

	
 
    def gist_url(self):
 
        import kallithea
 
        alias_url = kallithea.CONFIG.get('gist_alias_url')
 
        if alias_url:
 
            return alias_url.replace('{gistid}', self.gist_access_id)
kallithea/templates/admin/repos/repo_edit_settings.html
Show inline comments
 
@@ -6,7 +6,7 @@ ${h.form(url('update_repo', repo_name=c.
 
                    ${h.text('repo_name',class_='form-control')}
 
                    <span class="help-block">${_('Permanent Repository ID')}: `_${c.repo_info.repo_id}` <span><a id="show_more_clone_id" href="#">${_('What is that?')}</a></span></span>
 
                    <span id="clone_id" class="help-block" style="display: none">
 
                        ${_('URL by id')}: `${c.repo_info.clone_url(with_id=True)}`<br/>
 
                        ${_('URL by id')}: `${c.repo_info.clone_url(clone_uri_tmpl=c.clone_uri_tmpl, with_id=True)}`<br/>
 
                        ${_('''In case this repository is renamed or moved into another group the repository URL changes.
 
                               Using the above permanent URL guarantees that this repository always will be accessible on that URL.
 
                               This is useful for CI systems, or any other cases that you need to hardcode the URL into a 3rd party service.''')}</span>
kallithea/templates/pullrequests/pullrequest_show.html
Show inline comments
 
@@ -106,9 +106,9 @@ ${self.repo_context_bar('showpullrequest
 
              <div>
 
               ## TODO: use cs_ranges[-1] or org_ref_parts[1] in both cases?
 
               %if h.is_hg(c.pull_request.org_repo):
 
                 <span>hg pull ${c.pull_request.org_repo.clone_url()} -r ${h.short_id(c.cs_ranges[-1].raw_id)}</span>
 
                 <span>hg pull ${c.pull_request.org_repo.clone_url(clone_uri_tmpl=c.clone_uri_tmpl)} -r ${h.short_id(c.cs_ranges[-1].raw_id)}</span>
 
               %elif h.is_git(c.pull_request.org_repo):
 
                 <span>git pull ${c.pull_request.org_repo.clone_url()} ${c.pull_request.org_ref_parts[1]}</span>
 
                 <span>git pull ${c.pull_request.org_repo.clone_url(clone_uri_tmpl=c.clone_uri_tmpl)} ${c.pull_request.org_ref_parts[1]}</span>
 
               %endif
 
              </div>
 
            %endif
0 comments (0 inline, 0 general)