Changeset - e30401bac6e1
[Not reviewed]
default
0 9 0
Mads Kiilerich - 11 years ago 2014-08-12 13:08:23
madski@unity3d.com
pull requests: show more helpful URLs
9 files changed with 27 insertions and 15 deletions:
0 comments (0 inline, 0 general)
kallithea/config/routing.py
Show inline comments
 
@@ -690,25 +690,25 @@ def make_map(config):
 

	
 
    rmap.connect('pullrequest',
 
                 '/{repo_name:.*?}/pull-request/new', controller='pullrequests',
 
                 action='create', conditions=dict(function=check_repo,
 
                                                  method=["POST"]))
 

	
 
    rmap.connect('pullrequest_copy_update',
 
                 '/{repo_name:.*?}/pull-request-update/{pull_request_id}', controller='pullrequests',
 
                 action='copy_update', conditions=dict(function=check_repo,
 
                                                       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"]))
 
    rmap.connect('pullrequest_post',
 
                 '/{repo_name:.*?}/pull-request/{pull_request_id}',
 
                 controller='pullrequests',
 
                 action='post', conditions=dict(function=check_repo,
 
                                                method=["POST"]))
 
    rmap.connect('pullrequest_update',
 
                 '/{repo_name:.*?}/pull-request/{pull_request_id}',
 
                 controller='pullrequests',
 
                 action='update', conditions=dict(function=check_repo,
kallithea/controllers/pullrequests.py
Show inline comments
 
@@ -451,26 +451,25 @@ class PullrequestsController(BaseRepoCon
 
                self.authuser.user_id, org_repo_name, org_ref, other_repo_name,
 
                other_ref, revisions, reviewers, title, description
 
            )
 
            Session().commit()
 
            h.flash(_('Successfully opened new pull request'),
 
                    category='success')
 
        except Exception:
 
            h.flash(_('Error occurred while creating pull request'),
 
                    category='error')
 
            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()
 
    @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
 
                                   'repository.admin')
 
    def copy_update(self, repo_name, pull_request_id):
 
        old_pull_request = PullRequest.get_or_404(pull_request_id)
 
        assert old_pull_request.other_repo.repo_name == repo_name
 
        if old_pull_request.is_closed():
 
            raise HTTPForbidden()
 

	
 
        org_repo = RepoModel()._get_repo(old_pull_request.org_repo.repo_name)
 
@@ -630,25 +629,25 @@ class PullrequestsController(BaseRepoCon
 
        #only owner can delete it !
 
        if pull_request.author.user_id == c.authuser.user_id:
 
            PullRequestModel().delete(pull_request)
 
            Session().commit()
 
            h.flash(_('Successfully deleted pull request'),
 
                    category='success')
 
            return redirect(url('my_account_pullrequests'))
 
        raise HTTPForbidden()
 

	
 
    @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()
 
        c.pull_request = PullRequest.get_or_404(pull_request_id)
 
        c.allowed_to_change_status = self._get_is_allowed_change_status(c.pull_request)
 
        cc_model = ChangesetCommentsModel()
 
        cs_model = ChangesetStatusModel()
 

	
 
        # pull_requests repo_name we opened it against
 
        # ie. other_repo must match
 
        if repo_name != c.pull_request.other_repo.repo_name:
 
            raise HTTPNotFound
kallithea/lib/utils2.py
Show inline comments
 
@@ -747,12 +747,15 @@ class Optional(object):
 
    @classmethod
 
    def extract(cls, val):
 
        """
 
        Extracts value from Optional() instance
 

	
 
        :param val:
 
        :return: original value if it's not Optional instance else
 
            value of instance
 
        """
 
        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('_')
kallithea/model/comment.py
Show inline comments
 
@@ -118,27 +118,25 @@ class ChangesetCommentsModel(BaseModel):
 
        #pull request
 
        elif pull_request:
 
            notification_type = Notification.TYPE_PULL_REQUEST_COMMENT
 
            desc = comment.pull_request.title
 
            _org_ref_type, org_ref_name, _org_rev = comment.pull_request.org_ref.split(':')
 
            threading = ['%s-pr-%s@%s' % (pull_request.other_repo.repo_name,
 
                                          pull_request.pull_request_id,
 
                                          h.canonical_hostname())]
 
            if line_no: # TODO: url to file _and_ line number
 
                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' % \
 
                          {'desc': desc,
 
                           'pr_id': comment.pull_request.pull_request_id,
 
                           'line': line},
 
                          comment_url)
 
            )
 
            # get the current participants of this pull request
 
            recipients = ChangesetComment.get_users(pull_request_id=
 
                                                pull_request.pull_request_id)
 
            # add pull request author
kallithea/model/db.py
Show inline comments
 
@@ -42,25 +42,25 @@ from webob.exc import HTTPNotFound
 

	
 
from pylons.i18n.translation import lazy_ugettext as _
 

	
 
from kallithea import DB_PREFIX
 
from kallithea.lib.vcs import get_backend
 
from kallithea.lib.vcs.utils.helpers import get_scm
 
from kallithea.lib.vcs.exceptions import VCSError
 
from kallithea.lib.vcs.utils.lazy import LazyProperty
 
from kallithea.lib.vcs.backends.base import EmptyChangeset
 

	
 
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
 

	
 
from kallithea.model.meta import Base, Session
 

	
 
URL_SEP = '/'
 
log = logging.getLogger(__name__)
 

	
 
#==============================================================================
 
# BASE CLASSES
 
#==============================================================================
 

	
 
@@ -2297,24 +2297,37 @@ class PullRequest(Base, BaseModel):
 
    def is_closed(self):
 
        return self.status == self.STATUS_CLOSED
 

	
 
    @property
 
    def last_review_status(self):
 
        return str(self.statuses[-1].status) if self.statuses else ''
 

	
 
    def __json__(self):
 
        return dict(
 
            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'
 
    __table_args__ = (
 
        {'extend_existing': True, 'mysql_engine': 'InnoDB',
 
         'mysql_charset': 'utf8', 'sqlite_autoincrement': True},
 
    )
 

	
 
    def __init__(self, user=None, pull_request=None):
 
        self.user = user
 
        self.pull_request = pull_request
 

	
kallithea/model/pull_request.py
Show inline comments
 
@@ -115,26 +115,25 @@ class PullRequestModel(BaseModel):
 

	
 
    def __add_reviewers(self, pr, reviewers, mention_recipients=None):
 
        #members
 
        for member in set(reviewers):
 
            _usr = self._get_user(member)
 
            reviewer = PullRequestReviewers(_usr, pr)
 
            Session().add(reviewer)
 

	
 
        revision_data = [(x.raw_id, x.message)
 
                         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(
 
            h.link_to(
 
              _('%(user)s wants you to review pull request #%(pr_id)s: %(pr_title)s') % \
 
                {'user': pr.author.username,
 
                 'pr_title': pr.title,
 
                 'pr_id': pr.pull_request_id},
 
                pr_url)
 
            )
 
        body = pr.description
 
        _org_ref_type, org_ref_name, _org_rev = pr.org_ref.split(':')
kallithea/templates/changeset/changeset_file_comment.html
Show inline comments
 
@@ -11,28 +11,28 @@
 
          <div class="user">
 
              ${co.author.username}
 
          </div>
 
          <div class="date">
 
              ${h.age(co.modified_at)}
 
          </div>
 

	
 
       <div style="float:left;padding:4px 0px 0px 5px">
 
        <span class="">
 
         %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:
 
              ${_('Status change on changeset')}:
 
            %else:
 
              ${_('Comment on changeset')}
 
            %endif
 
         %endif
 
        </span>
 
       </div>
 

	
 
        %if co.status_change:
kallithea/templates/pullrequests/pullrequest_data.html
Show inline comments
 
## -*- coding: utf-8 -*-
 

	
 
% for pr in c.pullrequests_pager:
 
  <div class="pr ${'pr-closed' if pr.is_closed() else ''}">
 
    <div class="pr-title">
 
    %if pr.last_review_status:
 
      <img src="${h.url('/images/icons/flag_status_%s.png' % pr.last_review_status)}" title="${_("Someone voted: %s") % pr.last_review_status}"/>
 
    %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>
 
       %endif
 
      </a>
 
            ${_('opened on %s from') % (h.fmt_date(pr.created_on))}
 
            <% org_ref_name=pr.org_ref.rsplit(':', 2)[-2] %>
 
            <a href="${h.url('summary_home', repo_name=pr.org_repo.repo_name, anchor=org_ref_name)}">
 
              ${pr.org_repo.repo_name}#${org_ref_name}
 
            </a>
 
    </div>
 
  </div>
kallithea/templates/pullrequests/pullrequest_show_my_data.html
Show inline comments
 
${h.checkbox('show_closed',checked="checked" if c.show_closed else "", label=_('Show closed pull requests too'))}
 
<div class="pullrequests_section_head">${_('Opened by me')}</div>
 
<ul>
 
  %if c.my_pull_requests:
 
    %for pull_request in c.my_pull_requests:
 
      <li class="${'closed' if pull_request.is_closed() else ''}">
 
        <div style="height: 12px">
 
            %if pull_request.last_review_status:
 
              <img src="${h.url('/images/icons/flag_status_%s.png' % pull_request.last_review_status)}" title="${_("Someone voted: %s") % pull_request.last_review_status}"/>
 
            %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))}
 
            <% org_ref_name=pull_request.org_ref.rsplit(':', 2)[-2] %>
 
            <a href="${h.url('summary_home', repo_name=pull_request.org_repo.repo_name, anchor=org_ref_name)}">
 
              ${pull_request.org_repo.repo_name}#${org_ref_name}
 
            </a>
 
            %if pull_request.is_closed():
 
              (${_('Closed')})
 
            %endif
 
            ${h.form(url('pullrequest_delete', repo_name=pull_request.other_repo.repo_name, pull_request_id=pull_request.pull_request_id),method='delete', style="display:inline-block")}
 
              ${h.submit('remove_%s' % pull_request.pull_request_id, '', title=_('Delete Pull Request'),class_="delete_icon action_button",onclick="return confirm('"+_('Confirm to delete this pull request')+"');")}
 
@@ -34,25 +34,25 @@ ${h.checkbox('show_closed',checked="chec
 

	
 
<div class="pullrequests_section_head" style="clear:both">${_('I participate in')}</div>
 
<ul>
 
  %if c.participate_in_pull_requests:
 
    %for pull_request in c.participate_in_pull_requests:
 
      <li class="${'closed' if pull_request.is_closed() else ''}">
 
        <div style="height: 12px">
 
            %if pull_request.last_review_status:
 
              <img src="${h.url('/images/icons/flag_status_%s.png' % pull_request.last_review_status)}" title="${_("Someone voted: %s") % pull_request.last_review_status}"/>
 
            %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')}
 
            <% org_ref_name=pull_request.org_ref.rsplit(':', 2)[-2] %>
 
            <a href="${h.url('summary_home', repo_name=pull_request.org_repo.repo_name, anchor=org_ref_name)}">
 
              ${pull_request.org_repo.repo_name}#${org_ref_name}
 
            </a>
 
            ${_('opened on %s') % (h.fmt_date(pull_request.created_on))}
 
            %if pull_request.is_closed():
 
              (${_('Closed')})
 
            %endif
 
        </div>
0 comments (0 inline, 0 general)