Mercurial > kallithea
changeset 4447:e30401bac6e1
pull requests: show more helpful URLs
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Tue, 12 Aug 2014 13:08:23 +0200 |
parents | 5e7c69707f08 |
children | 8e26c46e9abe |
files | kallithea/config/routing.py kallithea/controllers/pullrequests.py kallithea/lib/utils2.py kallithea/model/comment.py kallithea/model/db.py kallithea/model/pull_request.py kallithea/templates/changeset/changeset_file_comment.html kallithea/templates/pullrequests/pullrequest_data.html kallithea/templates/pullrequests/pullrequest_show_my_data.html |
diffstat | 9 files changed, 27 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/config/routing.py Tue Aug 12 13:08:23 2014 +0200 +++ b/kallithea/config/routing.py Tue Aug 12 13:08:23 2014 +0200 @@ -699,7 +699,7 @@ method=["POST"])) rmap.connect('pullrequest_show', - '/{repo_name:.*?}/pull-request/{pull_request_id}', + '/{repo_name:.*?}/pull-request/{pull_request_id:\\d+}{extra:(/.*)?}', extra='', controller='pullrequests', action='show', conditions=dict(function=check_repo, method=["GET"]))
--- a/kallithea/controllers/pullrequests.py Tue Aug 12 13:08:23 2014 +0200 +++ b/kallithea/controllers/pullrequests.py Tue Aug 12 13:08:23 2014 +0200 @@ -460,8 +460,7 @@ log.error(traceback.format_exc()) return redirect(url('pullrequest_home', repo_name=repo_name)) - return redirect(url('pullrequest_show', repo_name=other_repo_name, - pull_request_id=pull_request.pull_request_id)) + return redirect(pull_request.url()) @LoginRequired() @NotAnonymous() @@ -639,7 +638,7 @@ @LoginRequired() @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', 'repository.admin') - def show(self, repo_name, pull_request_id): + def show(self, repo_name, pull_request_id, extra=None): repo_model = RepoModel() c.users_array = repo_model.get_users_js() c.user_groups_array = repo_model.get_user_groups_js()
--- a/kallithea/lib/utils2.py Tue Aug 12 13:08:23 2014 +0200 +++ b/kallithea/lib/utils2.py Tue Aug 12 13:08:23 2014 +0200 @@ -756,3 +756,6 @@ if isinstance(val, cls): return val.getval() return val + +def urlreadable(s, _cleanstringsub=re.compile('[^-a-zA-Z0-9./]+').sub): + return _cleanstringsub('_', safe_str(s)).rstrip('_')
--- a/kallithea/model/comment.py Tue Aug 12 13:08:23 2014 +0200 +++ b/kallithea/model/comment.py Tue Aug 12 13:08:23 2014 +0200 @@ -127,9 +127,7 @@ threading.append('%s-pr-%s-line-%s@%s' % (pull_request.other_repo.repo_name, pull_request.pull_request_id, line_no, h.canonical_hostname())) - comment_url = h.canonical_url('pullrequest_show', - repo_name=pull_request.other_repo.repo_name, - pull_request_id=pull_request.pull_request_id, + comment_url = pull_request.url(canonical=True, anchor='comment-%s' % comment.comment_id) subj = safe_unicode( h.link_to('Re pull request #%(pr_id)s: %(desc)s %(line)s' % \
--- a/kallithea/model/db.py Tue Aug 12 13:08:23 2014 +0200 +++ b/kallithea/model/db.py Tue Aug 12 13:08:23 2014 +0200 @@ -51,7 +51,7 @@ from kallithea.lib.utils2 import str2bool, safe_str, get_changeset_safe, \ safe_unicode, remove_prefix, time_to_datetime, aslist, Optional, safe_int, \ - get_clone_url + get_clone_url, urlreadable from kallithea.lib.compat import json from kallithea.lib.caching_query import FromCache @@ -2306,6 +2306,19 @@ revisions=self.revisions ) + def url(self, **kwargs): + canonical = kwargs.pop('canonical', None) + import kallithea.lib.helpers as h + s = '/' + self.title + b = self.org_ref_parts[1] + if b not in s and b != self.other_ref_parts[1]: + s = '/_%s_%s' % (b, s) + kwargs['extra'] = urlreadable(s) + if canonical: + return h.canonical_url('pullrequest_show', repo_name=self.other_repo.repo_name, + pull_request_id=self.pull_request_id, **kwargs) + return h.url('pullrequest_show', repo_name=self.other_repo.repo_name, + pull_request_id=self.pull_request_id, **kwargs) class PullRequestReviewers(Base, BaseModel): __tablename__ = 'pull_request_reviewers'
--- a/kallithea/model/pull_request.py Tue Aug 12 13:08:23 2014 +0200 +++ b/kallithea/model/pull_request.py Tue Aug 12 13:08:23 2014 +0200 @@ -124,8 +124,7 @@ for x in map(pr.org_repo.get_changeset, pr.revisions)] #notification to reviewers - pr_url = h.canonical_url('pullrequest_show', repo_name=pr.other_repo.repo_name, - pull_request_id=pr.pull_request_id) + pr_url = pr.url(canonical=True) threading = [h.canonical_url('pullrequest_show', repo_name=pr.other_repo.repo_name, pull_request_id=pr.pull_request_id)] subject = safe_unicode(
--- a/kallithea/templates/changeset/changeset_file_comment.html Tue Aug 12 13:08:23 2014 +0200 +++ b/kallithea/templates/changeset/changeset_file_comment.html Tue Aug 12 13:08:23 2014 +0200 @@ -20,10 +20,10 @@ %if co.pull_request: %if co.status_change: ${_('Status change from pull request')} - <a href="${h.url('pullrequest_show',repo_name=co.pull_request.other_repo.repo_name,pull_request_id=co.pull_request.pull_request_id)}">"${co.pull_request.title or _("No title")}"</a>: + <a href="${co.pull_request.url()}">"${co.pull_request.title or _("No title")}"</a>: %else: ${_('Comment from pull request')} - <a href="${h.url('pullrequest_show',repo_name=co.pull_request.other_repo.repo_name,pull_request_id=co.pull_request.pull_request_id)}">"${co.pull_request.title or _("No title")}"</a> + <a href="${co.pull_request.url()}">"${co.pull_request.title or _("No title")}"</a> %endif %else: %if co.status_change:
--- a/kallithea/templates/pullrequests/pullrequest_data.html Tue Aug 12 13:08:23 2014 +0200 +++ b/kallithea/templates/pullrequests/pullrequest_data.html Tue Aug 12 13:08:23 2014 +0200 @@ -8,7 +8,7 @@ %else: <img src="${h.url('/images/icons/flag_status_not_reviewed.png')}" title="${_("Nobody voted")}"/> %endif - <a href="${h.url('pullrequest_show',repo_name=pr.other_repo.repo_name,pull_request_id=pr.pull_request_id)}"> + <a href="${pr.url()}"> ${pr.title or _("(no title)")} %if pr.is_closed(): <span class="pr-closed-tag">${_('Closed')}</span>
--- a/kallithea/templates/pullrequests/pullrequest_show_my_data.html Tue Aug 12 13:08:23 2014 +0200 +++ b/kallithea/templates/pullrequests/pullrequest_show_my_data.html Tue Aug 12 13:08:23 2014 +0200 @@ -10,7 +10,7 @@ %else: <img src="${h.url('/images/icons/flag_status_not_reviewed.png')}" title="${_("Nobody voted")}"/> %endif - <a href="${h.url('pullrequest_show',repo_name=pull_request.other_repo.repo_name,pull_request_id=pull_request.pull_request_id)}"> + <a href="${pull_request.url()}"> ${pull_request.title or _("(no title)")} </a> ${_('opened on %s from') % (h.fmt_date(pull_request.created_on))} @@ -43,7 +43,7 @@ %else: <img src="${h.url('/images/icons/flag_status_not_reviewed.png')}" title="${_("Nobody voted")}"/> %endif - <a href="${h.url('pullrequest_show',repo_name=pull_request.other_repo.repo_name,pull_request_id=pull_request.pull_request_id)}"> + <a href="${pull_request.url()}"> ${pull_request.title or _("(no title)")} </a> ${_('from')}