@@ -254,137 +254,136 @@ class PullrequestsController(BaseRepoCon
def delete(self, repo_name, pull_request_id):
pull_request = PullRequest.get_or_404(pull_request_id)
#only owner can delete it !
if pull_request.author.user_id == c.rhodecode_user.user_id:
PullRequestModel().delete(pull_request)
Session().commit()
h.flash(_('Successfully deleted pull request'),
category='success')
return redirect(url('admin_settings_my_account', anchor='pullrequests'))
raise HTTPForbidden()
def _load_compare_data(self, pull_request, enable_comments=True):
"""
Load context data needed for generating compare diff
:param pull_request:
:type pull_request:
rev_start = request.GET.get('rev_start')
rev_end = request.GET.get('rev_end')
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 book 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]
other_ref = ('rev', getattr(c.cs_ranges[0].parents[0]
if c.cs_ranges[0].parents
else EmptyChangeset(), 'raw_id'))
c.statuses = org_repo.statuses([x.raw_id for x in c.cs_ranges])
c.target_repo = c.repo_name
c.target_repo = other_repo.repo_name
# defines that we need hidden inputs with changesets
c.as_form = request.GET.get('as_form', False)
c.org_ref = org_ref[1]
c.other_ref = other_ref[1]
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
_diff = diffs.differ(org_repo, other_ref, other_repo, org_ref)
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.target_repo = c.pull_request.org_repo.repo_name
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,
try:
cur_status = c.statuses[c.pull_request.revisions[0]][0]
except:
Status change: