changeset.py
491 lines
| 17.8 KiB
| text/x-python
|
PythonLexer
Bradley M. Kuhn
|
r4187 | # -*- coding: utf-8 -*- | ||
# This program is free software: you can redistribute it and/or modify | ||||
# it under the terms of the GNU General Public License as published by | ||||
# the Free Software Foundation, either version 3 of the License, or | ||||
# (at your option) any later version. | ||||
# | ||||
# This program is distributed in the hope that it will be useful, | ||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
# GNU General Public License for more details. | ||||
# | ||||
# You should have received a copy of the GNU General Public License | ||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
""" | ||||
kallithea.controllers.changeset | ||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||
Thomas De Schampheleire
|
r6178 | changeset controller showing changes between revisions | ||
Bradley M. Kuhn
|
r4187 | |||
Bradley M. Kuhn
|
r4211 | This file was forked by the Kallithea project in July 2014. | ||
Original author and date, and relevant copyright and licensing information is below: | ||||
Bradley M. Kuhn
|
r4187 | :created_on: Apr 25, 2010 | ||
:author: marcink | ||||
Bradley M. Kuhn
|
r4211 | :copyright: (c) 2013 RhodeCode GmbH, and others. | ||
Bradley M. Kuhn
|
r4208 | :license: GPLv3, see LICENSE.md for more details. | ||
Bradley M. Kuhn
|
r4187 | """ | ||
Mads Kiilerich
|
r7882 | import binascii | ||
Bradley M. Kuhn
|
r4187 | import logging | ||
import traceback | ||||
Mads Kiilerich
|
r7718 | from collections import OrderedDict, defaultdict | ||
Bradley M. Kuhn
|
r4187 | |||
Mads Kiilerich
|
r7718 | from tg import request, response | ||
from tg import tmpl_context as c | ||||
Mads Kiilerich
|
r6508 | from tg.i18n import ugettext as _ | ||
Mads Kiilerich
|
r7718 | from webob.exc import HTTPBadRequest, HTTPForbidden, HTTPFound, HTTPNotFound | ||
Bradley M. Kuhn
|
r4187 | |||
import kallithea.lib.helpers as h | ||||
Mads Kiilerich
|
r7718 | from kallithea.lib import diffs | ||
from kallithea.lib.auth import HasRepoPermissionLevelDecorator, LoginRequired | ||||
from kallithea.lib.base import BaseRepoController, jsonify, render | ||||
from kallithea.lib.graphmod import graph_data | ||||
Bradley M. Kuhn
|
r4187 | from kallithea.lib.utils import action_logger | ||
Mads Kiilerich
|
r8078 | from kallithea.lib.utils2 import ascii_str, safe_str | ||
Mads Kiilerich
|
r7718 | from kallithea.lib.vcs.backends.base import EmptyChangeset | ||
from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError, EmptyRepositoryError, RepositoryError | ||||
from kallithea.model.changeset_status import ChangesetStatusModel | ||||
from kallithea.model.comment import ChangesetCommentsModel | ||||
Bradley M. Kuhn
|
r4187 | from kallithea.model.db import ChangesetComment, ChangesetStatus | ||
from kallithea.model.meta import Session | ||||
Mads Kiilerich
|
r7518 | from kallithea.model.pull_request import PullRequestModel | ||
Mads Kiilerich
|
r7718 | |||
Bradley M. Kuhn
|
r4187 | |||
log = logging.getLogger(__name__) | ||||
def _update_with_GET(params, GET): | ||||
for k in ['diff1', 'diff2', 'diff']: | ||||
params[k] += GET.getall(k) | ||||
def anchor_url(revision, path, GET): | ||||
fid = h.FID(revision, path) | ||||
return h.url.current(anchor=fid, **dict(GET)) | ||||
def get_ignore_ws(fid, GET): | ||||
ig_ws_global = GET.get('ignorews') | ||||
Mads Kiilerich
|
r7893 | ig_ws = [k for k in GET.getall(fid) if k.startswith('WS')] | ||
Bradley M. Kuhn
|
r4187 | if ig_ws: | ||
Andrew Shadura
|
r4889 | try: | ||
return int(ig_ws[0].split(':')[-1]) | ||||
except ValueError: | ||||
raise HTTPBadRequest() | ||||
Bradley M. Kuhn
|
r4187 | return ig_ws_global | ||
def _ignorews_url(GET, fileid=None): | ||||
fileid = str(fileid) if fileid else None | ||||
params = defaultdict(list) | ||||
_update_with_GET(params, GET) | ||||
Mads Kiilerich
|
r4401 | lbl = _('Show whitespace') | ||
Bradley M. Kuhn
|
r4187 | ig_ws = get_ignore_ws(fileid, GET) | ||
ln_ctx = get_line_ctx(fileid, GET) | ||||
# global option | ||||
if fileid is None: | ||||
if ig_ws is None: | ||||
params['ignorews'] += [1] | ||||
Mads Kiilerich
|
r4401 | lbl = _('Ignore whitespace') | ||
Bradley M. Kuhn
|
r4187 | ctx_key = 'context' | ||
ctx_val = ln_ctx | ||||
# per file options | ||||
else: | ||||
if ig_ws is None: | ||||
params[fileid] += ['WS:1'] | ||||
Mads Kiilerich
|
r4401 | lbl = _('Ignore whitespace') | ||
Bradley M. Kuhn
|
r4187 | |||
ctx_key = fileid | ||||
ctx_val = 'C:%s' % ln_ctx | ||||
# if we have passed in ln_ctx pass it along to our params | ||||
if ln_ctx: | ||||
params[ctx_key] += [ctx_val] | ||||
params['anchor'] = fileid | ||||
Sean Farley
|
r4628 | icon = h.literal('<i class="icon-strike"></i>') | ||
domruf
|
r6394 | return h.link_to(icon, h.url.current(**params), title=lbl, **{'data-toggle': 'tooltip'}) | ||
Bradley M. Kuhn
|
r4187 | |||
def get_line_ctx(fid, GET): | ||||
ln_ctx_global = GET.get('context') | ||||
if fid: | ||||
Mads Kiilerich
|
r7893 | ln_ctx = [k for k in GET.getall(fid) if k.startswith('C')] | ||
Bradley M. Kuhn
|
r4187 | else: | ||
Mads Kiilerich
|
r7893 | _ln_ctx = [k for k in GET if k.startswith('C')] | ||
Lars Kruse
|
r6789 | ln_ctx = GET.get(_ln_ctx[0]) if _ln_ctx else ln_ctx_global | ||
Bradley M. Kuhn
|
r4187 | if ln_ctx: | ||
ln_ctx = [ln_ctx] | ||||
if ln_ctx: | ||||
retval = ln_ctx[0].split(':')[-1] | ||||
else: | ||||
retval = ln_ctx_global | ||||
try: | ||||
return int(retval) | ||||
except Exception: | ||||
return 3 | ||||
def _context_url(GET, fileid=None): | ||||
""" | ||||
Generates url for context lines | ||||
:param fileid: | ||||
""" | ||||
fileid = str(fileid) if fileid else None | ||||
ig_ws = get_ignore_ws(fileid, GET) | ||||
ln_ctx = (get_line_ctx(fileid, GET) or 3) * 2 | ||||
params = defaultdict(list) | ||||
_update_with_GET(params, GET) | ||||
# global option | ||||
if fileid is None: | ||||
if ln_ctx > 0: | ||||
params['context'] += [ln_ctx] | ||||
if ig_ws: | ||||
ig_ws_key = 'ignorews' | ||||
ig_ws_val = 1 | ||||
# per file option | ||||
else: | ||||
params[fileid] += ['C:%s' % ln_ctx] | ||||
ig_ws_key = fileid | ||||
ig_ws_val = 'WS:%s' % 1 | ||||
if ig_ws: | ||||
params[ig_ws_key] += [ig_ws_val] | ||||
Mads Kiilerich
|
r5127 | lbl = _('Increase diff context to %(num)s lines') % {'num': ln_ctx} | ||
Bradley M. Kuhn
|
r4187 | |||
params['anchor'] = fileid | ||||
Sean Farley
|
r4629 | icon = h.literal('<i class="icon-sort"></i>') | ||
domruf
|
r6394 | return h.link_to(icon, h.url.current(**params), title=lbl, **{'data-toggle': 'tooltip'}) | ||
Bradley M. Kuhn
|
r4187 | |||
Thomas De Schampheleire
|
r7353 | def create_cs_pr_comment(repo_name, revision=None, pull_request=None, allowed_to_change_status=True): | ||
Thomas De Schampheleire
|
r7356 | """ | ||
Add a comment to the specified changeset or pull request, using POST values | ||||
from the request. | ||||
Comments can be inline (when a file path and line number is specified in | ||||
POST) or general comments. | ||||
A comment can be accompanied by a review status change (accepted, rejected, | ||||
etc.). Pull requests can be closed or deleted. | ||||
Parameter 'allowed_to_change_status' is used for both status changes and | ||||
closing of pull requests. For deleting of pull requests, more specific | ||||
checks are done. | ||||
""" | ||||
Thomas De Schampheleire
|
r7353 | assert request.environ.get('HTTP_X_PARTIAL_XHR') | ||
if pull_request: | ||||
pull_request_id = pull_request.pull_request_id | ||||
else: | ||||
pull_request_id = None | ||||
status = request.POST.get('changeset_status') | ||||
close_pr = request.POST.get('save_close') | ||||
delete = request.POST.get('save_delete') | ||||
f_path = request.POST.get('f_path') | ||||
line_no = request.POST.get('line') | ||||
if (status or close_pr or delete) and (f_path or line_no): | ||||
# status votes and closing is only possible in general comments | ||||
raise HTTPBadRequest() | ||||
if not allowed_to_change_status: | ||||
if status or close_pr: | ||||
h.flash(_('No permission to change status'), 'error') | ||||
raise HTTPForbidden() | ||||
if pull_request and delete == "delete": | ||||
if (pull_request.owner_id == request.authuser.user_id or | ||||
h.HasPermissionAny('hg.admin')() or | ||||
h.HasRepoPermissionLevel('admin')(pull_request.org_repo.repo_name) or | ||||
h.HasRepoPermissionLevel('admin')(pull_request.other_repo.repo_name) | ||||
Mads Kiilerich
|
r7733 | ) and not pull_request.is_closed(): | ||
Thomas De Schampheleire
|
r7353 | PullRequestModel().delete(pull_request) | ||
Session().commit() | ||||
h.flash(_('Successfully deleted pull request %s') % pull_request_id, | ||||
category='success') | ||||
return { | ||||
Mads Kiilerich
|
r7518 | 'location': h.url('my_pullrequests'), # or repo pr list? | ||
Thomas De Schampheleire
|
r7353 | } | ||
Mads Kiilerich
|
r7518 | raise HTTPFound(location=h.url('my_pullrequests')) # or repo pr list? | ||
Thomas De Schampheleire
|
r7353 | raise HTTPForbidden() | ||
text = request.POST.get('text', '').strip() | ||||
Thomas De Schampheleire
|
r7354 | comment = ChangesetCommentsModel().create( | ||
text=text, | ||||
repo=c.db_repo.repo_id, | ||||
author=request.authuser.user_id, | ||||
Thomas De Schampheleire
|
r7353 | revision=revision, | ||
Thomas De Schampheleire
|
r7354 | pull_request=pull_request_id, | ||
f_path=f_path or None, | ||||
line_no=line_no or None, | ||||
status_change=ChangesetStatus.get_status_lbl(status) if status else None, | ||||
Thomas De Schampheleire
|
r7353 | closing_pr=close_pr, | ||
) | ||||
if status: | ||||
ChangesetStatusModel().set_status( | ||||
c.db_repo.repo_id, | ||||
status, | ||||
request.authuser.user_id, | ||||
comment, | ||||
revision=revision, | ||||
pull_request=pull_request_id, | ||||
) | ||||
if pull_request: | ||||
action = 'user_commented_pull_request:%s' % pull_request_id | ||||
else: | ||||
action = 'user_commented_revision:%s' % revision | ||||
action_logger(request.authuser, action, c.db_repo, request.ip_addr) | ||||
if pull_request and close_pr: | ||||
PullRequestModel().close_pull_request(pull_request_id) | ||||
action_logger(request.authuser, | ||||
'user_closed_pull_request:%s' % pull_request_id, | ||||
c.db_repo, request.ip_addr) | ||||
Session().commit() | ||||
data = { | ||||
Mads Kiilerich
|
r8075 | 'target_id': h.safeid(request.POST.get('f_path')), | ||
Thomas De Schampheleire
|
r7353 | } | ||
if comment is not None: | ||||
c.comment = comment | ||||
data.update(comment.get_dict()) | ||||
data.update({'rendered_text': | ||||
render('changeset/changeset_comment_block.html')}) | ||||
return data | ||||
Thomas De Schampheleire
|
r7355 | def delete_cs_pr_comment(repo_name, comment_id): | ||
Thomas De Schampheleire
|
r7356 | """Delete a comment from a changeset or pull request""" | ||
Thomas De Schampheleire
|
r7346 | co = ChangesetComment.get_or_404(comment_id) | ||
if co.repo.repo_name != repo_name: | ||||
raise HTTPNotFound() | ||||
Thomas De Schampheleire
|
r7355 | if co.pull_request and co.pull_request.is_closed(): | ||
Thomas De Schampheleire
|
r7346 | # don't allow deleting comments on closed pull request | ||
raise HTTPForbidden() | ||||
owner = co.author_id == request.authuser.user_id | ||||
repo_admin = h.HasRepoPermissionLevel('admin')(repo_name) | ||||
if h.HasPermissionAny('hg.admin')() or repo_admin or owner: | ||||
ChangesetCommentsModel().delete(comment=co) | ||||
Session().commit() | ||||
return True | ||||
else: | ||||
raise HTTPForbidden() | ||||
Mads Kiilerich
|
r5646 | |||
Bradley M. Kuhn
|
r4187 | class ChangesetController(BaseRepoController): | ||
Thomas De Schampheleire
|
r6513 | def _before(self, *args, **kwargs): | ||
super(ChangesetController, self)._before(*args, **kwargs) | ||||
Bradley M. Kuhn
|
r4187 | c.affected_files_cut_off = 60 | ||
def _index(self, revision, method): | ||||
Mads Kiilerich
|
r5647 | c.pull_request = None | ||
Bradley M. Kuhn
|
r4187 | c.anchor_url = anchor_url | ||
c.ignorews_url = _ignorews_url | ||||
c.context_url = _context_url | ||||
Mads Kiilerich
|
r6831 | c.fulldiff = request.GET.get('fulldiff') # for reporting number of changed files | ||
Lars Kruse
|
r6789 | # get ranges of revisions if preset | ||
Bradley M. Kuhn
|
r4187 | rev_range = revision.split('...')[:2] | ||
enable_comments = True | ||||
Mads Kiilerich
|
r4368 | c.cs_repo = c.db_repo | ||
Bradley M. Kuhn
|
r4187 | try: | ||
if len(rev_range) == 2: | ||||
enable_comments = False | ||||
rev_start = rev_range[0] | ||||
rev_end = rev_range[1] | ||||
Bradley M. Kuhn
|
r4196 | rev_ranges = c.db_repo_scm_instance.get_changesets(start=rev_start, | ||
Bradley M. Kuhn
|
r4187 | end=rev_end) | ||
else: | ||||
Bradley M. Kuhn
|
r4196 | rev_ranges = [c.db_repo_scm_instance.get_changeset(revision)] | ||
Bradley M. Kuhn
|
r4187 | |||
c.cs_ranges = list(rev_ranges) | ||||
if not c.cs_ranges: | ||||
raise RepositoryError('Changeset range returned empty result') | ||||
Mads Kiilerich
|
r6004 | except (ChangesetDoesNotExistError, EmptyRepositoryError): | ||
Thomas De Schampheleire
|
r5186 | log.debug(traceback.format_exc()) | ||
Bradley M. Kuhn
|
r4187 | msg = _('Such revision does not exist for this repository') | ||
h.flash(msg, category='error') | ||||
raise HTTPNotFound() | ||||
c.changes = OrderedDict() | ||||
c.lines_added = 0 # count of lines added | ||||
c.lines_deleted = 0 # count of lines removes | ||||
c.changeset_statuses = ChangesetStatus.STATUSES | ||||
Mads Kiilerich
|
r4330 | comments = dict() | ||
Bradley M. Kuhn
|
r4187 | c.statuses = [] | ||
c.inline_comments = [] | ||||
c.inline_cnt = 0 | ||||
# Iterate over ranges (default changeset view is always one changeset) | ||||
for changeset in c.cs_ranges: | ||||
if method == 'show': | ||||
c.statuses.extend([ChangesetStatusModel().get_status( | ||||
Bradley M. Kuhn
|
r4195 | c.db_repo.repo_id, changeset.raw_id)]) | ||
Bradley M. Kuhn
|
r4187 | |||
Mads Kiilerich
|
r4330 | # Changeset comments | ||
comments.update((com.comment_id, com) | ||||
for com in ChangesetCommentsModel() | ||||
.get_comments(c.db_repo.repo_id, | ||||
revision=changeset.raw_id)) | ||||
Bradley M. Kuhn
|
r4187 | |||
Mads Kiilerich
|
r4330 | # Status change comments - mostly from pull requests | ||
Søren Løvborg
|
r6282 | comments.update((st.comment_id, st.comment) | ||
Mads Kiilerich
|
r4330 | for st in ChangesetStatusModel() | ||
.get_statuses(c.db_repo.repo_id, | ||||
Mads Kiilerich
|
r5278 | changeset.raw_id, with_revisions=True) | ||
Søren Løvborg
|
r6282 | if st.comment_id is not None) | ||
Bradley M. Kuhn
|
r4187 | |||
Mads Kiilerich
|
r5585 | inlines = ChangesetCommentsModel() \ | ||
Bradley M. Kuhn
|
r4195 | .get_inline_comments(c.db_repo.repo_id, | ||
Bradley M. Kuhn
|
r4187 | revision=changeset.raw_id) | ||
c.inline_comments.extend(inlines) | ||||
cs2 = changeset.raw_id | ||||
cs1 = changeset.parents[0].raw_id if changeset.parents else EmptyChangeset().raw_id | ||||
context_lcl = get_line_ctx('', request.GET) | ||||
Jiří Suchan
|
r5567 | ign_whitespace_lcl = get_ignore_ws('', request.GET) | ||
Bradley M. Kuhn
|
r4187 | |||
Mads Kiilerich
|
r6863 | raw_diff = diffs.get_diff(c.db_repo_scm_instance, cs1, cs2, | ||
Bradley M. Kuhn
|
r4187 | ignore_whitespace=ign_whitespace_lcl, context=context_lcl) | ||
Mads Kiilerich
|
r6831 | diff_limit = None if c.fulldiff else self.cut_off_limit | ||
Mads Kiilerich
|
r6266 | file_diff_data = [] | ||
Bradley M. Kuhn
|
r4187 | if method == 'show': | ||
Mads Kiilerich
|
r6834 | diff_processor = diffs.DiffProcessor(raw_diff, | ||
vcs=c.db_repo_scm_instance.alias, | ||||
diff_limit=diff_limit) | ||||
Mads Kiilerich
|
r6839 | c.limited_diff = diff_processor.limited_diff | ||
Mads Kiilerich
|
r6838 | for f in diff_processor.parsed: | ||
Bradley M. Kuhn
|
r4187 | st = f['stats'] | ||
c.lines_added += st['added'] | ||||
c.lines_deleted += st['deleted'] | ||||
Mads Kiilerich
|
r6155 | filename = f['filename'] | ||
fid = h.FID(changeset.raw_id, filename) | ||||
Mads Kiilerich
|
r6156 | url_fid = h.FID('', filename) | ||
Mads Kiilerich
|
r6841 | html_diff = diffs.as_html(enable_comments=enable_comments, parsed_lines=[f]) | ||
file_diff_data.append((fid, url_fid, f['operation'], f['old_filename'], filename, html_diff, st)) | ||||
Bradley M. Kuhn
|
r4187 | else: | ||
# downloads/raw we only need RAW diff nothing else | ||||
Mads Kiilerich
|
r6834 | file_diff_data.append(('', None, None, None, raw_diff, None)) | ||
Mads Kiilerich
|
r6156 | c.changes[changeset.raw_id] = (cs1, cs2, file_diff_data) | ||
Bradley M. Kuhn
|
r4187 | |||
Lars Kruse
|
r6789 | # sort comments in creation order | ||
Mads Kiilerich
|
r4330 | c.comments = [com for com_id, com in sorted(comments.items())] | ||
Bradley M. Kuhn
|
r4187 | |||
# count inline comments | ||||
for __, lines in c.inline_comments: | ||||
for comments in lines.values(): | ||||
c.inline_cnt += len(comments) | ||||
if len(c.cs_ranges) == 1: | ||||
c.changeset = c.cs_ranges[0] | ||||
c.parent_tmpl = ''.join(['# Parent %s\n' % x.raw_id | ||||
for x in c.changeset.parents]) | ||||
Mads Kiilerich
|
r7995 | c.changeset_graft_source_hash = ascii_str(c.changeset.extra.get(b'source', b'')) | ||
c.changeset_transplant_source_hash = ascii_str(binascii.hexlify(c.changeset.extra.get(b'transplant_source', b''))) | ||||
Bradley M. Kuhn
|
r4187 | if method == 'download': | ||
response.content_type = 'text/plain' | ||||
response.content_disposition = 'attachment; filename=%s.diff' \ | ||||
% revision[:12] | ||||
Mads Kiilerich
|
r6834 | return raw_diff | ||
Bradley M. Kuhn
|
r4187 | elif method == 'patch': | ||
response.content_type = 'text/plain' | ||||
Mads Kiilerich
|
r8078 | c.diff = safe_str(raw_diff) | ||
Bradley M. Kuhn
|
r4187 | return render('changeset/patch_changeset.html') | ||
elif method == 'raw': | ||||
response.content_type = 'text/plain' | ||||
Mads Kiilerich
|
r6834 | return raw_diff | ||
Bradley M. Kuhn
|
r4187 | elif method == 'show': | ||
if len(c.cs_ranges) == 1: | ||||
return render('changeset/changeset.html') | ||||
else: | ||||
Mads Kiilerich
|
r4297 | c.cs_ranges_org = None | ||
Mads Kiilerich
|
r4367 | c.cs_comments = {} | ||
Mads Kiilerich
|
r4352 | revs = [ctx.revision for ctx in reversed(c.cs_ranges)] | ||
Søren Løvborg
|
r6492 | c.jsdata = graph_data(c.db_repo_scm_instance, revs) | ||
Bradley M. Kuhn
|
r4187 | return render('changeset/changeset_range.html') | ||
Mads Kiilerich
|
r7038 | @LoginRequired(allow_default_user=True) | ||
Søren Løvborg
|
r6471 | @HasRepoPermissionLevelDecorator('read') | ||
Bradley M. Kuhn
|
r4187 | def index(self, revision, method='show'): | ||
return self._index(revision, method=method) | ||||
Mads Kiilerich
|
r7038 | @LoginRequired(allow_default_user=True) | ||
Søren Løvborg
|
r6471 | @HasRepoPermissionLevelDecorator('read') | ||
Bradley M. Kuhn
|
r4187 | def changeset_raw(self, revision): | ||
return self._index(revision, method='raw') | ||||
Mads Kiilerich
|
r7038 | @LoginRequired(allow_default_user=True) | ||
Søren Løvborg
|
r6471 | @HasRepoPermissionLevelDecorator('read') | ||
Bradley M. Kuhn
|
r4187 | def changeset_patch(self, revision): | ||
return self._index(revision, method='patch') | ||||
Mads Kiilerich
|
r7038 | @LoginRequired(allow_default_user=True) | ||
Søren Løvborg
|
r6471 | @HasRepoPermissionLevelDecorator('read') | ||
Bradley M. Kuhn
|
r4187 | def changeset_download(self, revision): | ||
return self._index(revision, method='download') | ||||
@LoginRequired() | ||||
Søren Løvborg
|
r6471 | @HasRepoPermissionLevelDecorator('read') | ||
Bradley M. Kuhn
|
r4187 | @jsonify | ||
def comment(self, repo_name, revision): | ||||
Thomas De Schampheleire
|
r7353 | return create_cs_pr_comment(repo_name, revision=revision) | ||
Bradley M. Kuhn
|
r4187 | |||
@LoginRequired() | ||||
Søren Løvborg
|
r6471 | @HasRepoPermissionLevelDecorator('read') | ||
Bradley M. Kuhn
|
r4187 | @jsonify | ||
Thomas De Schampheleire
|
r7346 | def delete_comment(self, repo_name, comment_id): | ||
Thomas De Schampheleire
|
r7355 | return delete_cs_pr_comment(repo_name, comment_id) | ||
Bradley M. Kuhn
|
r4187 | |||
Mads Kiilerich
|
r7038 | @LoginRequired(allow_default_user=True) | ||
Søren Løvborg
|
r6471 | @HasRepoPermissionLevelDecorator('read') | ||
Bradley M. Kuhn
|
r4187 | @jsonify | ||
def changeset_info(self, repo_name, revision): | ||||
if request.is_xhr: | ||||
try: | ||||
Bradley M. Kuhn
|
r4196 | return c.db_repo_scm_instance.get_changeset(revision) | ||
Mads Kiilerich
|
r5374 | except ChangesetDoesNotExistError as e: | ||
Bradley M. Kuhn
|
r4187 | return EmptyChangeset(message=str(e)) | ||
else: | ||||
raise HTTPBadRequest() | ||||
Mads Kiilerich
|
r7038 | @LoginRequired(allow_default_user=True) | ||
Søren Løvborg
|
r6471 | @HasRepoPermissionLevelDecorator('read') | ||
Bradley M. Kuhn
|
r4187 | @jsonify | ||
def changeset_children(self, repo_name, revision): | ||||
if request.is_xhr: | ||||
Bradley M. Kuhn
|
r4196 | changeset = c.db_repo_scm_instance.get_changeset(revision) | ||
Bradley M. Kuhn
|
r4187 | result = {"results": []} | ||
if changeset.children: | ||||
result = {"results": changeset.children} | ||||
return result | ||||
else: | ||||
raise HTTPBadRequest() | ||||
Mads Kiilerich
|
r7038 | @LoginRequired(allow_default_user=True) | ||
Søren Løvborg
|
r6471 | @HasRepoPermissionLevelDecorator('read') | ||
Bradley M. Kuhn
|
r4187 | @jsonify | ||
def changeset_parents(self, repo_name, revision): | ||||
if request.is_xhr: | ||||
Bradley M. Kuhn
|
r4196 | changeset = c.db_repo_scm_instance.get_changeset(revision) | ||
Bradley M. Kuhn
|
r4187 | result = {"results": []} | ||
if changeset.parents: | ||||
result = {"results": changeset.parents} | ||||
return result | ||||
else: | ||||
raise HTTPBadRequest() | ||||