Changeset - 65a964fc9053
[Not reviewed]
default
0 4 0
Mads Kiilerich - 12 years ago 2013-12-10 19:30:37
madski@unity3d.com
pull requests: don't rely on hidden input fields in dynamically loaded changeset list
4 files changed with 29 insertions and 26 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/compare.py
Show inline comments
 
@@ -99,7 +99,8 @@ class CompareController(BaseRepoControll
 
                redirect(h.url('summary_home', repo_name=repo.repo_name))
 
            raise HTTPBadRequest()
 

	
 
    def _get_changesets(self, alias, org_repo, org_rev, other_repo, other_rev):
 
    @staticmethod
 
    def _get_changesets(alias, org_repo, org_rev, other_repo, other_rev):
 
        """
 
        Returns lists of changesets that can be merged from org_repo@org_rev
 
        to other_repo@other_rev
kallithea/controllers/pullrequests.py
Show inline comments
 
@@ -59,6 +59,7 @@ from kallithea.model.forms import PullRe
 
from kallithea.lib.utils2 import safe_int
 
from kallithea.controllers.changeset import anchor_url, _ignorews_url,\
 
    _context_url, get_line_ctx, get_ignore_ws
 
from kallithea.controllers.compare import CompareController
 

	
 
log = logging.getLogger(__name__)
 

	
 
@@ -357,35 +358,45 @@ class PullrequestsController(BaseRepoCon
 
            _form = PullRequestForm(repo.repo_id)().to_python(request.POST)
 
        except formencode.Invalid, errors:
 
            log.error(traceback.format_exc())
 
            if errors.error_dict.get('revisions'):
 
                msg = 'Revisions: %s' % errors.error_dict['revisions']
 
            elif errors.error_dict.get('pullrequest_title'):
 
                msg = _('Pull request requires a title with min. 3 chars')
 
            else:
 
                msg = _('Error creating pull request: %s') % errors.msg
 

	
 
            msg = _('Error creating pull request: %s') % errors.msg
 
            h.flash(msg, 'error')
 
            return redirect(url('pullrequest_home', repo_name=repo_name)) ## would rather just go back to form ...
 

	
 
        org_repo = _form['org_repo']
 
        org_ref = _form['org_ref'] # will end with merge_rev but have symbolic name
 
        other_repo = _form['other_repo']
 
        # heads up: org and other might seem backward here ...
 
        org_repo_name = _form['org_repo']
 
        org_ref = _form['org_ref'] # will have merge_rev as rev but symbolic name
 
        org_repo = RepoModel()._get_repo(org_repo_name)
 
        (_org_ref_type,
 
         org_ref_name,
 
         org_rev) = org_ref.split(':')
 

	
 
        other_repo_name = _form['other_repo']
 
        other_ref = _form['other_ref'] # will have symbolic name and head revision
 
        ancestor_rev = _form['ancestor_rev'] # revision number of ancestor
 
        other_repo = RepoModel()._get_repo(other_repo_name)
 
        (other_ref_type,
 
         other_ref_name,
 
         other_rev) = other_ref.split(':')
 

	
 
        cs_ranges, _cs_ranges_not, ancestor_rev = \
 
            CompareController._get_changesets(org_repo.scm_instance.alias,
 
                                              other_repo.scm_instance, other_rev, # org and other "swapped"
 
                                              org_repo.scm_instance, org_rev,
 
                                              )
 
        revisions = [cs.raw_id for cs in cs_ranges]
 

	
 
        # hack: ancestor_rev is not an other_ref but we want to show the
 
        # requested destination and have the exact ancestor
 
        other_ref = other_ref.rsplit(':', 1)[0] + ':' + ancestor_rev
 
        other_ref = '%s:%s:%s' % (other_ref_type, other_ref_name, ancestor_rev)
 

	
 
        revisions = [x for x in reversed(_form['revisions'])]
 
        reviewers = _form['review_members']
 

	
 
        title = _form['pullrequest_title']
 
        if not title:
 
            title = '%s#%s to %s' % (org_repo, org_ref.split(':', 2)[1], other_repo)
 
            title = '%s#%s to %s#%s' % (org_repo_name, org_ref_name, other_repo_name, other_ref_name)
 
        description = _form['pullrequest_desc'].strip() or _('No description')
 
        try:
 
            pull_request = PullRequestModel().create(
 
                self.authuser.user_id, org_repo, org_ref, other_repo,
 
                self.authuser.user_id, org_repo_name, org_ref, other_repo_name,
 
                other_ref, revisions, reviewers, title, description
 
            )
 
            Session().commit()
 
@@ -397,7 +408,7 @@ class PullrequestsController(BaseRepoCon
 
            log.error(traceback.format_exc())
 
            return redirect(url('pullrequest_home', repo_name=repo_name))
 

	
 
        return redirect(url('pullrequest_show', repo_name=other_repo,
 
        return redirect(url('pullrequest_show', repo_name=other_repo_name,
 
                            pull_request_id=pull_request.pull_request_id))
 

	
 
    @LoginRequired()
kallithea/model/forms.py
Show inline comments
 
@@ -490,15 +490,11 @@ def PullRequestForm(repo_id):
 
        org_ref = v.UnicodeString(strip=True, required=True)
 
        other_repo = v.UnicodeString(strip=True, required=True)
 
        other_ref = v.UnicodeString(strip=True, required=True)
 
        revisions = All(v.UniqueList()(not_empty=True))
 
        review_members = v.UniqueList()()
 

	
 
        pullrequest_title = v.UnicodeString(strip=True, required=True)
 
        pullrequest_desc = v.UnicodeString(strip=True, required=False)
 

	
 
        ancestor_rev = v.UnicodeString(strip=True, required=True)
 
        merge_rev = v.UnicodeString(strip=True, required=True)
 

	
 
    return _PullRequestForm
 

	
 

	
kallithea/templates/compare/compare_cs.html
Show inline comments
 
@@ -24,9 +24,6 @@
 
        <td><div class="gravatar" commit_id="${cs.raw_id}"><img alt="gravatar" src="${h.gravatar_url(h.email_or_none(cs.author),14)}"/></div></td>
 
        <td><div class="author">${h.person(cs.author)}</div></td>
 
        <td>${h.link_to('r%s:%s' % (cs.revision,h.short_id(cs.raw_id)),h.url('changeset_home',repo_name=c.other_repo.repo_name,revision=cs.raw_id))}
 
        %if c.as_form:
 
          ${h.hidden('revisions',cs.raw_id)}
 
        %endif
 
        </td>
 
        <td>
 
        %if cs.branch:
 
@@ -60,8 +57,6 @@
 
        ${_('No common ancestor found - repositories are unrelated')}
 
        %endif
 
      </div>
 
      ${h.hidden('ancestor_rev',c.ancestor)}
 
      ${h.hidden('merge_rev',c.cs_ranges[-1].raw_id)}
 
    %endif
 
    %if c.cs_ranges_org is not None:
 
      ## TODO: list actual changesets?
0 comments (0 inline, 0 general)