Mercurial > kallithea
changeset 5671:779d43be59c6
pullrequests: make it possible to delete pull requests instead of commenting
Deleting a pull request might however be a bad idea - the reviews on the PR
will be lost.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Wed, 20 Jan 2016 01:47:11 +0100 |
parents | 1ecfb8ecc634 |
children | b4b57beb4928 |
files | kallithea/controllers/pullrequests.py kallithea/public/js/base.js kallithea/templates/changeset/changeset_file_comment.html |
diffstat | 3 files changed, 55 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/controllers/pullrequests.py Wed Jan 20 01:47:11 2016 +0100 +++ b/kallithea/controllers/pullrequests.py Wed Jan 20 01:47:11 2016 +0100 @@ -710,10 +710,11 @@ 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) and (f_path or line_no): + 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() @@ -723,6 +724,22 @@ h.flash(_('No permission to change pull request status'), 'error') raise HTTPForbidden() + if delete == "delete": + if (pull_request.owner.user_id == c.authuser.user_id or + h.HasPermissionAny('hg.admin')() or + h.HasRepoPermissionAny('repository.admin')(pull_request.org_repo.repo_name) or + h.HasRepoPermissionAny('repository.admin')(pull_request.other_repo.repo_name) + ) and not pull_request.is_closed(): + PullRequestModel().delete(pull_request) + Session().commit() + h.flash(_('Successfully deleted pull request %s') % pull_request_id, + category='success') + return { + 'location': url('my_pullrequests'), # or repo pr list? + } + raise HTTPFound(location=url('my_pullrequests')) # or repo pr list? + raise HTTPForbidden() + text = request.POST.get('text', '').strip() if close_pr: text = _('Closing.') + '\n' + text
--- a/kallithea/public/js/base.js Wed Jan 20 01:47:11 2016 +0100 +++ b/kallithea/public/js/base.js Wed Jan 20 01:47:11 2016 +0100 @@ -700,12 +700,28 @@ var text = $textarea.val(); var review_status = $form.find('input:radio[name=changeset_status]:checked').val(); var pr_close = $form.find('input:checkbox[name=save_close]:checked').length ? 'on' : ''; + var pr_delete = $form.find('input:checkbox[name=save_delete]:checked').length ? 'delete' : ''; - if (!text && !review_status && !pr_close) { + if (!text && !review_status && !pr_close && !pr_delete) { alert("Please provide a comment"); return false; } + if (pr_delete) { + if (text || review_status || pr_close) { + alert('Cannot delete pull request while making other changes'); + return false; + } + if (!confirm('Confirm to delete this pull request')) { + return false; + } + var comments = $('.comment').size(); + if (comments > 0 && + !confirm('Confirm again to delete this pull request with {0} comments'.format(comments))) { + return false; + } + } + $form.find('.submitting-overlay').show(); var postData = { @@ -713,16 +729,21 @@ 'f_path': f_path, 'line': line_no, 'changeset_status': review_status, - 'save_close': pr_close + 'save_close': pr_close, + 'save_delete': pr_delete }; var success = function(json_data) { - $comment_div.append(json_data['rendered_text']); - comment_div_state($comment_div, f_path, line_no); - linkInlineComments($('.firstlink'), $('.comment:first-child')); - if ((review_status || pr_close) && !f_path && !line_no) { - // Page changed a lot - reload it after closing the submitted form - comment_div_state($comment_div, f_path, line_no, false); - location.reload(true); + if (pr_delete) { + location = json_data['location']; + } else { + $comment_div.append(json_data['rendered_text']); + comment_div_state($comment_div, f_path, line_no); + linkInlineComments($('.firstlink'), $('.comment:first-child')); + if ((review_status || pr_close) && !f_path && !line_no) { + // Page changed a lot - reload it after closing the submitted form + comment_div_state($comment_div, f_path, line_no, false); + location.reload(true); + } } }; ajaxPOST(AJAX_COMMENT_URL, postData, success);
--- a/kallithea/templates/changeset/changeset_file_comment.html Wed Jan 20 01:47:11 2016 +0100 +++ b/kallithea/templates/changeset/changeset_file_comment.html Wed Jan 20 01:47:11 2016 +0100 @@ -82,10 +82,17 @@ %if c.pull_request is not None and ( \ h.HasPermissionAny('hg.admin')() or h.HasRepoPermissionAny('repository.admin')(c.repo_name) \ or c.pull_request.owner.user_id == c.authuser.user_id): + <div> + ${_('Finish pull request')}: <label> <input id="save_close" type="checkbox" name="save_close"> ${_("Close")} </label> + <label> + <input id="save_delete" type="checkbox" name="save_delete" value="delete"> + ${_("Delete")} + </label> + </div> %endif </div>