landing-refs: create helpers for landing ref to make clear indication about type/name

This commit is contained in:
Marcin Kuzminski 2020-06-03 10:59:50 +02:00
parent 52e7c53793
commit e3b079f978
10 changed files with 29 additions and 21 deletions

View file

@ -178,7 +178,7 @@ class TestFilesViews(object):
commit_id='tip', f_path='/'))
# make sure Files menu url is not tip but new commit
landing_rev = backend.repo.landing_rev[1]
landing_rev = backend.repo.landing_ref_name
files_url = route_path('repo_files:default_path',
repo_name=backend.repo_name,
commit_id=landing_rev)

View file

@ -137,7 +137,7 @@ class RepoFilesView(RepoAppView):
raise HTTPFound(files_url)
def _get_commit_and_path(self):
default_commit_id = self.db_repo.landing_rev[1]
default_commit_id = self.db_repo.landing_ref_name
default_f_path = '/'
commit_id = self.request.matchdict.get(

View file

@ -138,10 +138,10 @@ class RepoForksView(RepoAppView, DataGridAppView):
url_link = h.route_path(
'repo_compare',
repo_name=fork.repo_name,
source_ref_type=self.db_repo.landing_rev[0],
source_ref=self.db_repo.landing_rev[1],
target_ref_type=self.db_repo.landing_rev[0],
target_ref=self.db_repo.landing_rev[1],
source_ref_type=self.db_repo.landing_ref_type,
source_ref=self.db_repo.landing_ref_name,
target_ref_type=self.db_repo.landing_ref_type,
target_ref=self.db_repo.landing_ref_name,
_query=dict(merge=1, target_repo=f.repo_name))
return h.link_to(_('Compare fork'), url_link, class_='btn-link')

View file

@ -1758,7 +1758,7 @@ class Repository(Base, BaseModel):
@hybrid_property
def landing_rev(self):
# always should return [rev_type, rev]
# always should return [rev_type, rev], e.g ['branch', 'master']
if self._landing_revision:
_rev_info = self._landing_revision.split(':')
if len(_rev_info) < 2:
@ -1766,6 +1766,14 @@ class Repository(Base, BaseModel):
return [_rev_info[0], _rev_info[1]]
return [None, None]
@property
def landing_ref_type(self):
return self.landing_rev[0]
@property
def landing_ref_name(self):
return self.landing_rev[1]
@landing_rev.setter
def landing_rev(self, val):
if ':' not in val:

View file

@ -365,7 +365,7 @@
<ul id="context-pages" class="navigation horizontal-list">
<li class="${h.is_active('summary', active)}"><a class="menulink" href="${h.route_path('repo_summary', repo_name=c.repo_name)}"><div class="menulabel">${_('Summary')}</div></a></li>
<li class="${h.is_active('commits', active)}"><a class="menulink" href="${h.route_path('repo_commits', repo_name=c.repo_name)}"><div class="menulabel">${_('Commits')}</div></a></li>
<li class="${h.is_active('files', active)}"><a class="menulink" href="${h.route_path('repo_files', repo_name=c.repo_name, commit_id=c.rhodecode_db_repo.landing_rev[1], f_path='')}"><div class="menulabel">${_('Files')}</div></a></li>
<li class="${h.is_active('files', active)}"><a class="menulink" href="${h.route_path('repo_files', repo_name=c.repo_name, commit_id=c.rhodecode_db_repo.landing_ref_name, f_path='')}"><div class="menulabel">${_('Files')}</div></a></li>
<li class="${h.is_active('compare', active)}"><a class="menulink" href="${h.route_path('repo_compare_select',repo_name=c.repo_name)}"><div class="menulabel">${_('Compare')}</div></a></li>
## TODO: anderson: ideally it would have a function on the scm_instance "enable_pullrequest() and enable_fork()"

View file

@ -6,7 +6,7 @@ c.template_context['repo_name'] = getattr(c, 'repo_name', '')
go_import_header = ''
if hasattr(c, 'rhodecode_db_repo'):
c.template_context['repo_type'] = c.rhodecode_db_repo.repo_type
c.template_context['repo_landing_commit'] = c.rhodecode_db_repo.landing_rev[1]
c.template_context['repo_landing_commit'] = c.rhodecode_db_repo.landing_ref_name
c.template_context['repo_id'] = c.rhodecode_db_repo.repo_id
c.template_context['repo_view_type'] = h.get_repo_view_type(request)

View file

@ -60,10 +60,10 @@
class="btn btn-small"
href="${h.route_path('repo_compare',
repo_name=c.rhodecode_db_repo.fork.repo_name,
source_ref_type=c.rhodecode_db_repo.landing_rev[0],
source_ref=c.rhodecode_db_repo.landing_rev[1],
target_ref_type='branch' if request.GET.get('branch') else c.rhodecode_db_repo.landing_rev[0],
target_ref=request.GET.get('branch') or c.rhodecode_db_repo.landing_rev[1],
source_ref_type=c.rhodecode_db_repo.landing_ref_type,
source_ref=c.rhodecode_db_repo.landing_ref_name,
target_ref_type='branch' if request.GET.get('branch') else c.rhodecode_db_repo.landing_ref_type,
target_ref=request.GET.get('branch') or c.rhodecode_db_repo.landing_ref_name,
_query=dict(merge=1, target_repo=c.repo_name))}"
>
${_('Compare fork with Parent (%s)' % c.rhodecode_db_repo.fork.repo_name)}

View file

@ -93,10 +93,10 @@
<a class="btn btn-default" title="${h.tooltip(_('Compare fork with %s' % c.rhodecode_db_repo.fork.repo_name))}"
href="${h.route_path('repo_compare',
repo_name=c.rhodecode_db_repo.fork.repo_name,
source_ref_type=c.rhodecode_db_repo.landing_rev[0],
source_ref=c.rhodecode_db_repo.landing_rev[1],
target_repo=c.repo_name,target_ref_type='branch' if request.GET.get('branch') else c.rhodecode_db_repo.landing_rev[0],
target_ref=request.GET.get('branch') or c.rhodecode_db_repo.landing_rev[1],
source_ref_type=c.rhodecode_db_repo.landing_ref_type,
source_ref=c.rhodecode_db_repo.landing_ref_name,
target_repo=c.repo_name,target_ref_type='branch' if request.GET.get('branch') else c.rhodecode_db_repo.landing_ref_type,
target_ref=request.GET.get('branch') or c.rhodecode_db_repo.landing_ref_name,
_query=dict(merge=1))}"
>
${_('Compare with origin')}

View file

@ -64,10 +64,10 @@
%if c.readme_data:
<div id="readme" class="anchor">
<div class="box">
<div class="readme-title" title="${h.tooltip(_('Readme file from commit %s:%s') % (c.rhodecode_db_repo.landing_rev[0], c.rhodecode_db_repo.landing_rev[1]))}">
<div class="readme-title" title="${h.tooltip(_('Readme file from commit %s:%s') % (c.rhodecode_db_repo.landing_ref_type, c.rhodecode_db_repo.landing_ref_name))}">
<div>
<i class="icon-file-text"></i>
<a href="${h.route_path('repo_files',repo_name=c.repo_name,commit_id=c.rhodecode_db_repo.landing_rev[1],f_path=c.readme_file)}">
<a href="${h.route_path('repo_files',repo_name=c.repo_name,commit_id=c.rhodecode_db_repo.landing_ref_name,f_path=c.readme_file)}">
${c.readme_file}
</a>
</div>

View file

@ -34,10 +34,10 @@
<div id="readme" class="anchor">
<div class="box">
<div class="readme-title" title="${h.tooltip(_('Readme file from commit %s:%s') % (c.rhodecode_db_repo.landing_rev[0], c.rhodecode_db_repo.landing_rev[1]))}">
<div class="readme-title" title="${h.tooltip(_('Readme file from commit %s:%s') % (c.rhodecode_db_repo.landing_ref_type, c.rhodecode_db_repo.landing_ref_name))}">
<div>
<i class="icon-file-text"></i>
<a href="${h.route_path('repo_files',repo_name=c.repo_name,commit_id=c.rhodecode_db_repo.landing_rev[1],f_path=c.readme_file)}">
<a href="${h.route_path('repo_files',repo_name=c.repo_name,commit_id=c.rhodecode_db_repo.landing_ref_name,f_path=c.readme_file)}">
${c.readme_file}
</a>
</div>