@@ -83,198 +83,203 @@ class PullRequestModel(BaseModel):
pr_url = h.url('pullrequest_show', repo_name=other_repo.repo_name,
pull_request_id=new.pull_request_id,
qualified=True,
)
subject = safe_unicode(
h.link_to(
_('%(user)s wants you to review pull request #%(pr_id)s') % \
{'user': created_by_user.username,
'pr_id': new.pull_request_id},
pr_url
body = description
kwargs = {
'pr_title': title,
'pr_user_created': h.person(created_by_user.email),
'pr_repo_url': h.url('summary_home', repo_name=other_repo.repo_name,
qualified=True,),
'pr_url': pr_url,
'pr_revisions': revisions
}
notif.create(created_by=created_by_user, subject=subject, body=body,
recipients=reviewers,
type_=Notification.TYPE_PULL_REQUEST, email_kwargs=kwargs)
return new
def update_reviewers(self, pull_request, reviewers_ids):
reviewers_ids = set(reviewers_ids)
pull_request = self.__get_pull_request(pull_request)
current_reviewers = PullRequestReviewers.query()\
.filter(PullRequestReviewers.pull_request==
pull_request)\
.all()
current_reviewers_ids = set([x.user.user_id for x in current_reviewers])
to_add = reviewers_ids.difference(current_reviewers_ids)
to_remove = current_reviewers_ids.difference(reviewers_ids)
log.debug("Adding %s reviewers" % to_add)
log.debug("Removing %s reviewers" % to_remove)
for uid in to_add:
_usr = self._get_user(uid)
reviewer = PullRequestReviewers(_usr, pull_request)
self.sa.add(reviewer)
for uid in to_remove:
reviewer = PullRequestReviewers.query()\
.filter(PullRequestReviewers.user_id==uid,
PullRequestReviewers.pull_request==pull_request)\
.scalar()
if reviewer:
self.sa.delete(reviewer)
def delete(self, pull_request):
Session().delete(pull_request)
def close_pull_request(self, pull_request):
pull_request.status = PullRequest.STATUS_CLOSED
pull_request.updated_on = datetime.datetime.now()
self.sa.add(pull_request)
def _get_changesets(self, alias, org_repo, org_ref, other_repo, other_ref,
discovery_data):
"""
Returns a list of changesets that are incoming from org_repo@org_ref
to other_repo@other_ref
:param org_repo:
:param org_ref:
:param other_repo:
:param other_ref:
:param tmp:
changesets = []
#case two independent repos
common, incoming, rheads = discovery_data
if org_repo != other_repo:
revs = [
org_repo._repo.lookup(org_ref[1]),
org_repo._repo.lookup(other_ref[1]),
]
obj = findcommonoutgoing(org_repo._repo,
localrepo.locallegacypeer(other_repo._repo.local()),
revs,
force=True)
revs = obj.missing
for cs in map(binascii.hexlify, revs):
_cs = org_repo.get_changeset(cs)
changesets.append(_cs)
# in case we have revisions filter out the ones not in given range
if org_ref[0] == 'rev' and other_ref[0] == 'rev':
revs = [x.raw_id for x in changesets]
start = org_ref[1]
stop = other_ref[1]
changesets = changesets[revs.index(start):revs.index(stop) + 1]
else:
#no remote compare do it on the same repository
if alias == 'hg':
_revset_predicates = {
'branch': 'branch',
'book': 'bookmark',
'tag': 'tag',
'rev': 'id',
"ancestors(%s('%s')) and not ancestors(%s('%s'))" % (
_revset_predicates[other_ref[0]], other_ref[1],
_revset_predicates[org_ref[0]], org_ref[1],
out = scmutil.revrange(org_repo._repo, revs)
for cs in (out):
changesets.append(org_repo.get_changeset(cs))
elif alias == 'git':
so, se = org_repo.run_git_command(
'log --reverse --pretty="format: %%H" -s -p %s..%s' % (org_ref[1],
other_ref[1])
ids = re.findall(r'[0-9a-fA-F]{40}', so)
for cs in (ids):
return changesets
def _get_discovery(self, org_repo, org_ref, other_repo, other_ref):
Get's mercurial discovery data used to calculate difference between
repos and refs
:type org_repo:
:type org_ref:
:type other_repo:
:type other_ref:
_org_repo = org_repo._repo
org_rev_type, org_rev = org_ref
_other_repo = other_repo._repo
other_rev_type, other_rev = other_ref
log.debug('Doing discovery for %s@%s vs %s@%s' % (
org_repo, org_ref, other_repo, other_ref)
#log.debug('Filter heads are %s[%s]' % ('', org_ref[1]))
org_peer = localrepo.locallegacypeer(_org_repo.local())
tmp = discovery.findcommonincoming(
repo=_other_repo, # other_repo we check for incoming
remote=org_peer, # org_repo source for incoming
# heads=[_other_repo[other_rev].node(),
# _org_repo[org_rev].node()],
force=True
return tmp
def get_compare_data(self, org_repo, org_ref, other_repo, other_ref):
Returns a tuple of incomming changesets, and discoverydata cache for
mercurial repositories
if len(org_ref) != 2 or not isinstance(org_ref, (list, tuple)):
raise Exception('org_ref must be a two element list/tuple')
if len(other_ref) != 2 or not isinstance(org_ref, (list, tuple)):
raise Exception('other_ref must be a two element list/tuple')
org_repo_scm = org_repo.scm_instance
other_repo_scm = other_repo.scm_instance
alias = org_repo.scm_instance.alias
discovery_data = [None, None, None]
discovery_data = self._get_discovery(org_repo_scm, org_ref,
other_repo_scm, other_ref)
cs_ranges = self._get_changesets(alias,
org_repo_scm, org_ref,
other_repo_scm, other_ref,
discovery_data)
return cs_ranges, discovery_data
@@ -74,193 +74,193 @@ ${_('%s Changelog') % c.repo_name} - ${c
<div class="expand"><span class="expandtext">↓ ${_('show more')} ↓</span></div>
</div>
<div class="right">
<div class="changes">
<div id="changed_total_${cs.raw_id}" style="float:right;" class="changed_total tooltip" title="${h.tooltip(_('Affected number of files, click to show more details'))}">${len(cs.affected_files)}</div>
<div class="comments-container">
%if len(c.comments.get(cs.raw_id,[])) > 0:
<div class="comments-cnt" title="${('comments')}">
<a href="${h.url('changeset_home',repo_name=c.repo_name,revision=cs.raw_id,anchor='comment-%s' % c.comments[cs.raw_id][0].comment_id)}">
<div class="comments-cnt">${len(c.comments[cs.raw_id])}</div>
<img src="${h.url('/images/icons/comments.png')}">
</a>
%endif
<div class="changeset-status-container">
%if c.statuses.get(cs.raw_id):
<div title="${_('Changeset status')}" class="changeset-status-lbl">${c.statuses.get(cs.raw_id)[1]}</div>
<div class="changeset-status-ico">
%if c.statuses.get(cs.raw_id)[2]:
<a class="tooltip" title="${_('Click to open associated pull request')}" href="${h.url('pullrequest_show',repo_name=c.statuses.get(cs.raw_id)[3],pull_request_id=c.statuses.get(cs.raw_id)[2])}"><img src="${h.url('/images/icons/flag_status_%s.png' % c.statuses.get(cs.raw_id)[0])}" /></a>
%else:
<img src="${h.url('/images/icons/flag_status_%s.png' % c.statuses.get(cs.raw_id)[0])}" />
%if cs.parents:
%for p_cs in reversed(cs.parents):
<div class="parent">${_('Parent')}
<span class="changeset_id">${p_cs.revision}:<span class="changeset_hash">${h.link_to(h.short_id(p_cs.raw_id),
h.url('changeset_home',repo_name=c.repo_name,revision=p_cs.raw_id),title=p_cs.message)}</span></span>
%endfor
<div class="parent">${_('No parents')}</div>
<span class="logtags">
%if len(cs.parents)>1:
<span class="merge">${_('merge')}</span>
%if cs.branch:
<span class="branchtag" title="${'%s %s' % (_('branch'),cs.branch)}">
${h.link_to(h.shorter(cs.branch),h.url('files_home',repo_name=c.repo_name,revision=cs.raw_id))}
</span>
%if h.is_hg(c.rhodecode_repo):
%for book in cs.bookmarks:
<span class="bookbook" title="${'%s %s' % (_('bookmark'),book)}">
${h.link_to(h.shorter(book),h.url('files_home',repo_name=c.repo_name,revision=cs.raw_id))}
%for tag in cs.tags:
<span class="tagtag" title="${'%s %s' % (_('tag'),tag)}">
${h.link_to(h.shorter(tag),h.url('files_home',repo_name=c.repo_name,revision=cs.raw_id))}</span>
<div class="pagination-wh pagination-left">
${c.pagination.pager('$link_previous ~2~ $link_next')}
<script type="text/javascript" src="${h.url('/js/graph.js')}"></script>
<script type="text/javascript">
YAHOO.util.Event.onDOMReady(function(){
//Monitor range checkboxes and build a link to changesets
//ranges
var checkboxes = YUD.getElementsByClassName('changeset_range');
var url_tmpl = "${h.url('changeset_home',repo_name=c.repo_name,revision='__REVRANGE__')}";
YUE.on(checkboxes,'click',function(e){
var clicked_cb = e.currentTarget;
var checked_checkboxes = [];
for (pos in checkboxes){
if(checkboxes[pos].checked){
checked_checkboxes.push(checkboxes[pos]);
if(YUD.get('open_new_pr')){
if(checked_checkboxes.length>0){
// modify open pull request to show we have selected cs
YUD.get('open_new_pr').innerHTML = _TM['Open new pull request for selected changesets'];
}else{
YUD.get('open_new_pr').innerHTML = _TM['Open new pull request'];
if(checked_checkboxes.length>1){
var rev_end = checked_checkboxes[0].name;
var rev_start = checked_checkboxes[checked_checkboxes.length-1].name;
// now select all checkboxes in the middle.
var checked = false;
for (var i=0; i<checkboxes.length; i++){
var cb = checkboxes[i];
var rev = cb.name;
if (rev == rev_end){
checked = true;
if (checked){
cb.checked = true;
else{
cb.checked = false;
if (rev == rev_start){
checked = false;
var url = url_tmpl.replace('__REVRANGE__',
rev_start+'...'+rev_end);
var link = _TM['Show selected changes __S -> __E'];
link = link.replace('__S',rev_start.substr(0,6));
link = link.replace('__E',rev_end.substr(0,6));
YUD.get('rev_range_container').href = url;
YUD.get('rev_range_container').innerHTML = link;
YUD.setStyle('rev_range_container','display','');
YUD.setStyle('rev_range_clear','display','');
YUD.get('open_new_pr').href += '?rev_start={0}&rev_end={1}'.format(rev_start,rev_end);
YUD.setStyle('rev_range_container','display','none');
YUD.setStyle('rev_range_clear','display','none');
});
YUE.on('rev_range_clear','click',function(e){
YUE.preventDefault(e);
})
var msgs = YUQ('.message');
// get first element height
var el = YUQ('#graph_content .container')[0];
var row_h = el.clientHeight;
for(var i=0;i<msgs.length;i++){
var m = msgs[i];
var h = m.clientHeight;
var pad = YUD.getStyle(m,'padding');
if(h > row_h){
var offset = row_h - (h+12);
YUD.setStyle(m.nextElementSibling,'display','block');
YUD.setStyle(m.nextElementSibling,'margin-top',offset+'px');
};
YUE.on(YUQ('.expand'),'click',function(e){
var elem = e.currentTarget.parentNode.parentNode;
YUD.setStyle(e.currentTarget,'display','none');
YUD.setStyle(elem,'height','auto');
//redraw the graph, line_count and jsdata are global vars
set_canvas(100);
var r = new BranchRenderer();
r.render(jsdata,100,line_count);
// Fetch changeset details
YUE.on(YUD.getElementsByClassName('changed_total'),'click',function(e){
var id = e.currentTarget.id;
var url = "${h.url('changelog_details',repo_name=c.repo_name,cs='__CS__')}";
var url = url.replace('__CS__',id.replace('changed_total_',''));
ypjax(url,id,function(){tooltip_activate()});
// change branch filter
YUE.on(YUD.get('branch_filter'),'change',function(e){
var selected_branch = e.currentTarget.options[e.currentTarget.selectedIndex].value;
var url_main = "${h.url('changelog_home',repo_name=c.repo_name)}";
var url = "${h.url('changelog_home',repo_name=c.repo_name,branch='__BRANCH__')}";
var url = url.replace('__BRANCH__',selected_branch);
if(selected_branch != ''){
window.location = url;
window.location = url_main;
Status change: