Changeset - 58c529332e7e
[Not reviewed]
beta
0 8 0
Marcin Kuzminski - 13 years ago 2012-07-15 03:14:58
marcin@python-works.com
Added option to close pull requests, in future that will be close & merge
8 files changed with 75 insertions and 22 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/pullrequests.py
Show inline comments
 
@@ -169,7 +169,7 @@ class PullrequestsController(BaseRepoCon
 
        return redirect(url('pullrequest_show', repo_name=other_repo,
 
                            pull_request_id=pull_request.pull_request_id))
 

	
 
    def _load_compare_data(self, pull_request):
 
    def _load_compare_data(self, pull_request, enable_comments=True):
 
        """
 
        Load context data needed for generating compare diff
 

	
 
@@ -211,7 +211,7 @@ class PullrequestsController(BaseRepoCon
 
        for f in _parsed:
 
            fid = h.FID('', f['filename'])
 
            c.files.append([fid, f['operation'], f['filename'], f['stats']])
 
            diff = diff_processor.as_html(enable_comments=True,
 
            diff = diff_processor.as_html(enable_comments=enable_comments,
 
                                          diff_lines=[f])
 
            c.changes[fid] = [f['operation'], f['filename'], diff]
 

	
 
@@ -246,7 +246,8 @@ class PullrequestsController(BaseRepoCon
 
            raise HTTPNotFound
 

	
 
        # load compare data into template context
 
        self._load_compare_data(c.pull_request)
 
        enable_comments = not c.pull_request.is_closed()
 
        self._load_compare_data(c.pull_request, enable_comments=enable_comments)
 

	
 
        # inline comments
 
        c.inline_cnt = 0
 
@@ -271,6 +272,9 @@ class PullrequestsController(BaseRepoCon
 

	
 
    @jsonify
 
    def comment(self, repo_name, pull_request_id):
 
        pull_request = PullRequest.get_or_404(pull_request_id)
 
        if pull_request.is_closed():
 
            raise HTTPForbidden()
 

	
 
        status = request.POST.get('changeset_status')
 
        change_status = request.POST.get('change_changeset_status')
 
@@ -299,6 +303,12 @@ class PullrequestsController(BaseRepoCon
 
                      'user_commented_pull_request:%s' % pull_request_id,
 
                      c.rhodecode_db_repo, self.ip_addr, self.sa)
 

	
 
        if request.POST.get('save_close'):
 
            PullRequestModel().close_pull_request(pull_request_id)
 
            action_logger(self.rhodecode_user,
 
                      'user_closed_pull_request:%s' % pull_request_id,
 
                      c.rhodecode_db_repo, self.ip_addr, self.sa)
 

	
 
        Session().commit()
 

	
 
        if not request.environ.get('HTTP_X_PARTIAL_XHR'):
 
@@ -319,6 +329,10 @@ class PullrequestsController(BaseRepoCon
 
    @jsonify
 
    def delete_comment(self, repo_name, comment_id):
 
        co = ChangesetComment.get(comment_id)
 
        if co.pull_request.is_closed():
 
            #don't allow deleting comments on closed pull request
 
            raise HTTPForbidden()
 

	
 
        owner = lambda: co.author.user_id == c.rhodecode_user.user_id
 
        if h.HasPermissionAny('hg.admin', 'repository.admin')() or owner:
 
            ChangesetCommentsModel().delete(comment=co)
rhodecode/model/db.py
Show inline comments
 
@@ -1519,6 +1519,7 @@ class PullRequest(Base, BaseModel):
 
    description = Column('description', UnicodeText(10240), nullable=True)
 
    status = Column('status', Unicode(256), nullable=False, default=STATUS_NEW)
 
    created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
 
    updated_on = Column('updated_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
 
    user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None)
 
    _revisions = Column('revisions', UnicodeText(20500))  # 500 revisions max
 
    org_repo_id = Column('org_repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False)
 
@@ -1526,6 +1527,8 @@ class PullRequest(Base, BaseModel):
 
    other_repo_id = Column('other_repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False)
 
    other_ref = Column('other_ref', Unicode(256), nullable=False)
 

	
 
    statuses = relationship('ChangesetStatus')
 

	
 
    @hybrid_property
 
    def revisions(self):
 
        return self._revisions.split(':')
 
@@ -1539,6 +1542,9 @@ class PullRequest(Base, BaseModel):
 
    org_repo = relationship('Repository', primaryjoin='PullRequest.org_repo_id==Repository.repo_id')
 
    other_repo = relationship('Repository', primaryjoin='PullRequest.other_repo_id==Repository.repo_id')
 

	
 
    def is_closed(self):
 
        return self.status == self.STATUS_CLOSED
 

	
 
    def __json__(self):
 
        return dict(
 
          revisions=self.revisions
rhodecode/model/pull_request.py
Show inline comments
 
# -*- coding: utf-8 -*-
 
"""
 
    rhodecode.model.pull_reuquest
 
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
    rhodecode.model.pull_request
 
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

	
 
    pull request model for RhodeCode
 

	
 
@@ -25,6 +25,7 @@
 

	
 
import logging
 
import binascii
 
import datetime
 

	
 
from pylons.i18n.translation import _
 

	
 
@@ -44,6 +45,9 @@ class PullRequestModel(BaseModel):
 

	
 
    cls = PullRequest
 

	
 
    def __get_pull_request(self, pull_request):
 
        return self._get_instance(PullRequest, pull_request)
 

	
 
    def get_all(self, repo):
 
        repo = self._get_repo(repo)
 
        return PullRequest.query().filter(PullRequest.other_repo == repo).all()
 
@@ -93,6 +97,12 @@ class PullRequestModel(BaseModel):
 

	
 
        return new
 

	
 
    def close_pull_request(self, pull_request):
 
        pull_request = self.__get_pull_request(pull_request)
 
        pull_request.status = PullRequest.STATUS_CLOSED
 
        pull_request.updated_on = datetime.datetime.now()
 
        self.sa.add(pull_request)
 

	
 
    def _get_changesets(self, org_repo, org_ref, other_repo, other_ref,
 
                        discovery_data):
 
        """
rhodecode/public/js/rhodecode.js
Show inline comments
 
@@ -396,7 +396,8 @@ var injectInlineForm = function(tr){
 
		  return
 
	  }
 
	  var submit_url = AJAX_COMMENT_URL;
 
	  if(YUD.hasClass(tr,'form-open') || YUD.hasClass(tr,'context') || YUD.hasClass(tr,'no-comment')){
 
	  var _td = tr.getElementsByClassName('code')[0];
 
	  if(YUD.hasClass(tr,'form-open') || YUD.hasClass(tr,'context') || YUD.hasClass(_td,'no-comment')){
 
		  return
 
	  }	
 
	  YUD.addClass(tr,'form-open');
rhodecode/templates/changeset/changeset.html
Show inline comments
 
@@ -136,7 +136,10 @@
 
    <%namespace name="comment" file="/changeset/changeset_file_comment.html"/>
 
    ${comment.comment_inline_form()}
 

	
 
    ## render comments main comments form and it status
 
    ## render comments and inlines
 
    ${comment.generate_comments()}
 

	
 
    ## main comment form and it status
 
    ${comment.comments(h.url('changeset_comment', repo_name=c.repo_name, revision=c.changeset.raw_id),
 
                       h.changeset_status(c.rhodecode_db_repo, c.changeset.raw_id))}
 

	
rhodecode/templates/changeset/changeset_file_comment.html
Show inline comments
 
@@ -92,9 +92,8 @@
 

	
 
</%def>
 

	
 
## MAIN COMMENT FORM
 
<%def name="comments(post_url, cur_status)">
 

	
 
## generate inline comments and the main ones
 
<%def name="generate_comments()">
 
<div class="comments">
 
    <div id="inline-comments-container">
 
    ## generate inlines for this changeset
 
@@ -106,6 +105,13 @@
 
          ${comment_block(co)}
 
        </div>
 
    %endfor
 
</div>    
 
</%def>
 

	
 
## MAIN COMMENT FORM
 
<%def name="comments(post_url, cur_status, close_btn=False)">
 

	
 
<div class="comments">
 
    %if c.rhodecode_user.username != 'default':
 
    <div class="comment-form ac">
 
        ${h.form(post_url)}
 
@@ -129,7 +135,10 @@
 
             ${h.textarea('text')}
 
        </div>
 
        <div class="comment-button">
 
        ${h.submit('save', _('Comment'), class_='ui-button')}
 
        ${h.submit('save', _('Comment'), class_="ui-btn large")}
 
        %if close_btn:
 
           ${h.submit('save_close', _('Comment and close'), class_='ui-btn blue large')}
 
        %endif
 
        </div>
 
        ${h.end_form()}
 
    </div>
rhodecode/templates/pullrequests/pullrequest_show.html
Show inline comments
 
@@ -19,12 +19,14 @@
 
    <div class="title">
 
        ${self.breadcrumbs()}
 
    </div>
 

	
 
        %if c.pull_request.is_closed():
 
        <div style="padding:10px; font-size:22px;width:100%;text-align: center; color:#88D882">${_('Closed %s') % (h.age(c.pull_request.updated_on))}</div>
 
        %endif        
 
    <h3>${_('Title')}: ${c.pull_request.title} 
 
        <div class="changeset-status-container" style="float:none">
 
        %if c.current_changeset_status:
 
          <div title="${_('Pull request status')}" class="changeset-status-lbl">[${h.changeset_status_lbl(c.current_changeset_status)}]</div>
 
          <div class="changeset-status-ico" style="padding:4px"><img src="${h.url('/images/icons/flag_status_%s.png' % c.current_changeset_status)}" /></div>
 
          <div class="changeset-status-ico" style="padding:4px"><img src="${h.url('/images/icons/flag_status_%s.png' % c.current_changeset_status)}" /></div>          
 
        %endif
 
        </div>
 
    </h3>
 
@@ -96,11 +98,17 @@
 
    ## template for inline comment form
 
    <%namespace name="comment" file="/changeset/changeset_file_comment.html"/>
 
    ${comment.comment_inline_form()}
 

	
 
    ## render comments main comments form and it status
 
    ${comment.comments(h.url('pullrequest_comment', repo_name=c.repo_name, pull_request_id=c.pull_request.pull_request_id),
 
                       c.current_changeset_status)}
 

	
 
    
 
    ## render comments and inlines
 
    ${comment.generate_comments()}
 
    
 
    % if not c.pull_request.is_closed():
 
      ## main comment form and it status
 
      ${comment.comments(h.url('pullrequest_comment', repo_name=c.repo_name,
 
                                pull_request_id=c.pull_request.pull_request_id),
 
                                c.current_changeset_status,
 
                                close_btn=True)}
 
    %endif
 

	
 
    <script type="text/javascript">
 
      YUE.onDOMReady(function(){
 
@@ -131,10 +139,8 @@
 
          var file_comments = YUQ('.inline-comment-placeholder');
 
          renderInlineComments(file_comments);
 
      })
 

	
 
    </script>
 

	
 

	
 
</div>
 

	
 
</%def>
rhodecode/templates/pullrequests/pullrequest_show_all.html
Show inline comments
 
<%inherit file="/base/base.html"/>
 

	
 
<%def name="title()">
 
    ${c.repo_name} ${_('All pull requests')}
 
    ${c.repo_name} ${_('all pull requests')}
 
</%def>
 

	
 
<%def name="breadcrumbs_links()">
 
@@ -22,7 +22,11 @@
 

	
 
    %for pr in c.pull_requests:
 
        <div>
 
          <h4><a href="${h.url('pullrequest_show',repo_name=c.repo_name,pull_request_id=pr.pull_request_id)}">
 
          <h4>
 
          %if pr.is_closed():
 
          <img src="${h.url('/images/icons/tick.png')}" alt="${_('Closed')}" />
 
          %endif          
 
          <a href="${h.url('pullrequest_show',repo_name=c.repo_name,pull_request_id=pr.pull_request_id)}">
 
          ${_('Pull request #%s opened by %s on %s') % (pr.pull_request_id, pr.author.full_name, h.fmt_date(pr.created_on))}
 
          </a>
 
          </h4>
0 comments (0 inline, 0 general)