@@ -239,197 +239,197 @@ class PullrequestsController(BaseRepoCon
org_repo = _form['org_repo']
org_ref = 'rev:merge:%s' % _form['merge_rev']
other_repo = _form['other_repo']
other_ref = 'rev:ancestor:%s' % _form['ancestor_rev']
revisions = reversed(_form['revisions'])
reviewers = _form['review_members']
title = _form['pullrequest_title']
description = _form['pullrequest_desc']
try:
pull_request = PullRequestModel().create(
self.rhodecode_user.user_id, org_repo, org_ref, other_repo,
other_ref, revisions, reviewers, title, description
)
Session().commit()
h.flash(_('Successfully opened new pull request'),
category='success')
except Exception:
h.flash(_('Error occurred during sending 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,
pull_request_id=pull_request.pull_request_id))
@NotAnonymous()
@jsonify
def update(self, repo_name, pull_request_id):
pull_request = PullRequest.get_or_404(pull_request_id)
if pull_request.is_closed():
raise HTTPForbidden()
#only owner or admin can update it
owner = pull_request.author.user_id == c.rhodecode_user.user_id
if h.HasPermissionAny('hg.admin', 'repository.admin')() or owner:
reviewers_ids = map(int, filter(lambda v: v not in [None, ''],
request.POST.get('reviewers_ids', '').split(',')))
PullRequestModel().update_reviewers(pull_request_id, reviewers_ids)
return True
def delete(self, repo_name, pull_request_id):
#only owner can delete it !
if pull_request.author.user_id == c.rhodecode_user.user_id:
PullRequestModel().delete(pull_request)
h.flash(_('Successfully deleted pull request'),
return redirect(url('admin_settings_my_account', anchor='pullrequests'))
def _load_compare_data(self, pull_request, enable_comments=True):
"""
Load context data needed for generating compare diff
:param pull_request:
:type pull_request:
org_repo = pull_request.org_repo
(org_ref_type,
org_ref_name,
org_ref_rev) = pull_request.org_ref.split(':')
other_repo = org_repo
(other_ref_type,
other_ref_name,
other_ref_rev) = pull_request.other_ref.split(':')
# despite opening revisions for bookmarks/branches/tags, we always
# convert this to rev to prevent changes after bookmark or branch change
org_ref = ('rev', org_ref_rev)
other_ref = ('rev', other_ref_rev)
c.org_repo = org_repo
c.other_repo = other_repo
c.fulldiff = fulldiff = request.GET.get('fulldiff')
c.cs_ranges = [org_repo.get_changeset(x) for x in pull_request.revisions]
c.statuses = org_repo.statuses([x.raw_id for x in c.cs_ranges])
c.org_ref = org_ref[1]
c.org_ref_type = org_ref[0]
c.other_ref = other_ref[1]
c.other_ref_type = other_ref[0]
diff_limit = self.cut_off_limit if not fulldiff else None
#we swap org/other ref since we run a simple diff on one repo
# we swap org/other ref since we run a simple diff on one repo
log.debug('running diff between %s@%s and %s@%s'
% (org_repo.scm_instance.path, org_ref,
other_repo.scm_instance.path, other_ref))
_diff = org_repo.scm_instance.get_diff(rev1=safe_str(org_ref[1]), rev2=safe_str(other_ref[1]))
_diff = org_repo.scm_instance.get_diff(rev1=safe_str(other_ref[1]), rev2=safe_str(org_ref[1]))
diff_processor = diffs.DiffProcessor(_diff or '', format='gitdiff',
diff_limit=diff_limit)
_parsed = diff_processor.prepare()
c.limited_diff = False
if isinstance(_parsed, LimitedDiffContainer):
c.limited_diff = True
c.files = []
c.changes = {}
c.lines_added = 0
c.lines_deleted = 0
for f in _parsed:
st = f['stats']
if st[0] != 'b':
c.lines_added += st[0]
c.lines_deleted += st[1]
fid = h.FID('', f['filename'])
c.files.append([fid, f['operation'], f['filename'], f['stats']])
diff = diff_processor.as_html(enable_comments=enable_comments,
parsed_lines=[f])
c.changes[fid] = [f['operation'], f['filename'], diff]
def show(self, repo_name, pull_request_id):
repo_model = RepoModel()
c.users_array = repo_model.get_users_js()
c.users_groups_array = repo_model.get_users_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()
_cs_statuses = cs_model.get_statuses(c.pull_request.org_repo,
pull_request=c.pull_request,
with_revisions=True)
cs_statuses = defaultdict(list)
for st in _cs_statuses:
cs_statuses[st.author.username] += [st]
c.pull_request_reviewers = []
c.pull_request_pending_reviewers = []
for o in c.pull_request.reviewers:
st = cs_statuses.get(o.user.username, None)
if st:
sorter = lambda k: k.version
st = [(x, list(y)[0])
for x, y in (groupby(sorted(st, key=sorter), sorter))]
else:
c.pull_request_pending_reviewers.append(o.user)
c.pull_request_reviewers.append([o.user, st])
# 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
# load compare data into template context
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
c.inline_comments = cc_model.get_inline_comments(
c.rhodecode_db_repo.repo_id,
pull_request=pull_request_id)
# count inline comments
for __, lines in c.inline_comments:
for comments in lines.values():
c.inline_cnt += len(comments)
# comments
c.comments = cc_model.get_comments(c.rhodecode_db_repo.repo_id,
cur_status = c.statuses[c.pull_request.revisions[0]][0]
cur_status = 'undefined'
if c.pull_request.is_closed() and 0:
c.current_changeset_status = cur_status
# changeset(pull-request) status calulation based on reviewers
c.current_changeset_status = cs_model.calculate_status(
c.pull_request_reviewers,
c.changeset_statuses = ChangesetStatus.STATUSES
c.as_form = False
c.ancestor = None # there is one - but right here we don't know which
return render('/pullrequests/pullrequest_show.html')
def comment(self, repo_name, pull_request_id):
Status change: