##// END OF EJS Templates
pull-request: code cleanup...
marcink -
r1979:f2f8f5ce default
parent child Browse files
Show More
@@ -35,13 +35,13 b' def admin_routes(config):'
35
35
36 config.add_route(
36 config.add_route(
37 name='pull_requests_global_0', # backward compat
37 name='pull_requests_global_0', # backward compat
38 pattern='/pull_requests/{pull_request_id:[0-9]+}')
38 pattern='/pull_requests/{pull_request_id:\d+}')
39 config.add_route(
39 config.add_route(
40 name='pull_requests_global_1', # backward compat
40 name='pull_requests_global_1', # backward compat
41 pattern='/pull-requests/{pull_request_id:[0-9]+}')
41 pattern='/pull-requests/{pull_request_id:\d+}')
42 config.add_route(
42 config.add_route(
43 name='pull_requests_global',
43 name='pull_requests_global',
44 pattern='/pull-request/{pull_request_id:[0-9]+}')
44 pattern='/pull-request/{pull_request_id:\d+}')
45
45
46 config.add_route(
46 config.add_route(
47 name='admin_settings_open_source',
47 name='admin_settings_open_source',
@@ -54,8 +54,10 b' class AdminMainView(BaseAppView):'
54 :param pull_request_id: id of pull requests in the system
54 :param pull_request_id: id of pull requests in the system
55 """
55 """
56
56
57 pull_request_id = self.request.matchdict.get('pull_request_id')
57 pull_request = PullRequest.get_or_404(
58 pull_request = PullRequest.get_or_404(pull_request_id)
58 self.request.matchdict['pull_request_id'])
59 pull_request_id = pull_request.pull_request_id
60
59 repo_name = pull_request.target_repo.repo_name
61 repo_name = pull_request.target_repo.repo_name
60
62
61 raise HTTPFound(
63 raise HTTPFound(
@@ -113,7 +113,7 b' class TestAdminRepoSettingsAdvanced(obje'
113 # mark it as None
113 # mark it as None
114 response = self.app.post(
114 response = self.app.post(
115 route_path('edit_repo_advanced_fork', repo_name=backend.repo_name),
115 route_path('edit_repo_advanced_fork', repo_name=backend.repo_name),
116 params={'id_fork_of': None, '_method': 'put',
116 params={'id_fork_of': None,
117 'csrf_token': csrf_token})
117 'csrf_token': csrf_token})
118 assert_session_flash(
118 assert_session_flash(
119 response,
119 response,
@@ -265,7 +265,7 b' class RepoPullRequestsView(RepoAppView, '
265 route_name='pullrequest_show', request_method='GET',
265 route_name='pullrequest_show', request_method='GET',
266 renderer='rhodecode:templates/pullrequests/pullrequest_show.mako')
266 renderer='rhodecode:templates/pullrequests/pullrequest_show.mako')
267 def pull_request_show(self):
267 def pull_request_show(self):
268 pull_request_id = self.request.matchdict.get('pull_request_id')
268 pull_request_id = self.request.matchdict['pull_request_id']
269
269
270 c = self.load_default_context()
270 c = self.load_default_context()
271
271
@@ -832,8 +832,8 b' class RepoPullRequestsView(RepoAppView, '
832 route_name='pullrequest_update', request_method='POST',
832 route_name='pullrequest_update', request_method='POST',
833 renderer='json_ext')
833 renderer='json_ext')
834 def pull_request_update(self):
834 def pull_request_update(self):
835 pull_request_id = self.request.matchdict['pull_request_id']
835 pull_request = PullRequest.get_or_404(
836 pull_request = PullRequest.get_or_404(pull_request_id)
836 self.request.matchdict['pull_request_id'])
837
837
838 # only owner or admin can update it
838 # only owner or admin can update it
839 allowed_to_update = PullRequestModel().check_user_update(
839 allowed_to_update = PullRequestModel().check_user_update(
@@ -843,7 +843,7 b' class RepoPullRequestsView(RepoAppView, '
843
843
844 if 'review_members' in controls:
844 if 'review_members' in controls:
845 self._update_reviewers(
845 self._update_reviewers(
846 pull_request_id, controls['review_members'],
846 pull_request, controls['review_members'],
847 pull_request.reviewer_data)
847 pull_request.reviewer_data)
848 elif str2bool(self.request.POST.get('update_commits', 'false')):
848 elif str2bool(self.request.POST.get('update_commits', 'false')):
849 self._update_commits(pull_request)
849 self._update_commits(pull_request)
@@ -930,8 +930,8 b' class RepoPullRequestsView(RepoAppView, '
930 After successful merging, the pull request is automatically
930 After successful merging, the pull request is automatically
931 closed, with a relevant comment.
931 closed, with a relevant comment.
932 """
932 """
933 pull_request_id = self.request.matchdict['pull_request_id']
933 pull_request = PullRequest.get_or_404(
934 pull_request = PullRequest.get_or_404(pull_request_id)
934 self.request.matchdict['pull_request_id'])
935
935
936 check = MergeCheck.validate(pull_request, self._rhodecode_db_user)
936 check = MergeCheck.validate(pull_request, self._rhodecode_db_user)
937 merge_possible = not check.failed
937 merge_possible = not check.failed
@@ -974,7 +974,7 b' class RepoPullRequestsView(RepoAppView, '
974 merge_resp.failure_reason)
974 merge_resp.failure_reason)
975 h.flash(msg, category='error')
975 h.flash(msg, category='error')
976
976
977 def _update_reviewers(self, pull_request_id, review_members, reviewer_rules):
977 def _update_reviewers(self, pull_request, review_members, reviewer_rules):
978 _ = self.request.translate
978 _ = self.request.translate
979 get_default_reviewers_data, validate_default_reviewers = \
979 get_default_reviewers_data, validate_default_reviewers = \
980 PullRequestModel().get_reviewer_functions()
980 PullRequestModel().get_reviewer_functions()
@@ -987,7 +987,7 b' class RepoPullRequestsView(RepoAppView, '
987 return
987 return
988
988
989 PullRequestModel().update_reviewers(
989 PullRequestModel().update_reviewers(
990 pull_request_id, reviewers, self._rhodecode_user)
990 pull_request, reviewers, self._rhodecode_user)
991 h.flash(_('Pull request reviewers updated.'), category='success')
991 h.flash(_('Pull request reviewers updated.'), category='success')
992 Session().commit()
992 Session().commit()
993
993
@@ -1002,8 +1002,8 b' class RepoPullRequestsView(RepoAppView, '
1002 def pull_request_delete(self):
1002 def pull_request_delete(self):
1003 _ = self.request.translate
1003 _ = self.request.translate
1004
1004
1005 pull_request_id = self.request.matchdict['pull_request_id']
1005 pull_request = PullRequest.get_or_404(
1006 pull_request = PullRequest.get_or_404(pull_request_id)
1006 self.request.matchdict['pull_request_id'])
1007
1007
1008 pr_closed = pull_request.is_closed()
1008 pr_closed = pull_request.is_closed()
1009 allowed_to_delete = PullRequestModel().check_user_delete(
1009 allowed_to_delete = PullRequestModel().check_user_delete(
@@ -1031,8 +1031,11 b' class RepoPullRequestsView(RepoAppView, '
1031 renderer='json_ext')
1031 renderer='json_ext')
1032 def pull_request_comment_create(self):
1032 def pull_request_comment_create(self):
1033 _ = self.request.translate
1033 _ = self.request.translate
1034 pull_request_id = self.request.matchdict['pull_request_id']
1034
1035 pull_request = PullRequest.get_or_404(pull_request_id)
1035 pull_request = PullRequest.get_or_404(
1036 self.request.matchdict['pull_request_id'])
1037 pull_request_id = pull_request.pull_request_id
1038
1036 if pull_request.is_closed():
1039 if pull_request.is_closed():
1037 log.debug('comment: forbidden because pull request is closed')
1040 log.debug('comment: forbidden because pull request is closed')
1038 raise HTTPForbidden()
1041 raise HTTPForbidden()
@@ -1080,7 +1083,7 b' class RepoPullRequestsView(RepoAppView, '
1080 text=text,
1083 text=text,
1081 repo=self.db_repo.repo_id,
1084 repo=self.db_repo.repo_id,
1082 user=self._rhodecode_user.user_id,
1085 user=self._rhodecode_user.user_id,
1083 pull_request=pull_request_id,
1086 pull_request=pull_request,
1084 f_path=self.request.POST.get('f_path'),
1087 f_path=self.request.POST.get('f_path'),
1085 line_no=self.request.POST.get('line'),
1088 line_no=self.request.POST.get('line'),
1086 status_change=(ChangesetStatus.get_status_lbl(status)
1089 status_change=(ChangesetStatus.get_status_lbl(status)
@@ -1102,7 +1105,7 b' class RepoPullRequestsView(RepoAppView, '
1102 status,
1105 status,
1103 self._rhodecode_user.user_id,
1106 self._rhodecode_user.user_id,
1104 comment,
1107 comment,
1105 pull_request=pull_request_id
1108 pull_request=pull_request
1106 )
1109 )
1107
1110
1108 Session().flush()
1111 Session().flush()
@@ -1142,15 +1145,17 b' class RepoPullRequestsView(RepoAppView, '
1142 route_name='pullrequest_comment_delete', request_method='POST',
1145 route_name='pullrequest_comment_delete', request_method='POST',
1143 renderer='json_ext')
1146 renderer='json_ext')
1144 def pull_request_comment_delete(self):
1147 def pull_request_comment_delete(self):
1145 pull_request_id = self.request.matchdict['pull_request_id']
1148 pull_request = PullRequest.get_or_404(
1146 comment_id = self.request.matchdict['comment_id']
1149 self.request.matchdict['pull_request_id'])
1147
1150
1148 pull_request = PullRequest.get_or_404(pull_request_id)
1151 comment = ChangesetComment.get_or_404(
1152 self.request.matchdict['comment_id'])
1153 comment_id = comment.comment_id
1154
1149 if pull_request.is_closed():
1155 if pull_request.is_closed():
1150 log.debug('comment: forbidden because pull request is closed')
1156 log.debug('comment: forbidden because pull request is closed')
1151 raise HTTPForbidden()
1157 raise HTTPForbidden()
1152
1158
1153 comment = ChangesetComment.get_or_404(comment_id)
1154 if not comment:
1159 if not comment:
1155 log.debug('Comment with id:%s not found, skipping', comment_id)
1160 log.debug('Comment with id:%s not found, skipping', comment_id)
1156 # comment already deleted in another call probably
1161 # comment already deleted in another call probably
@@ -544,7 +544,6 b' var CommentsController = function() {'
544 var comment_id = $comment.attr('data-comment-id');
544 var comment_id = $comment.attr('data-comment-id');
545 var url = AJAX_COMMENT_DELETE_URL.replace('__COMMENT_ID__', comment_id);
545 var url = AJAX_COMMENT_DELETE_URL.replace('__COMMENT_ID__', comment_id);
546 var postData = {
546 var postData = {
547 '_method': 'delete',
548 'csrf_token': CSRF_TOKEN
547 'csrf_token': CSRF_TOKEN
549 };
548 };
550
549
@@ -372,7 +372,6 b' var _updatePullRequest = function(repo_n'
372 */
372 */
373 var updateCommits = function(repo_name, pull_request_id) {
373 var updateCommits = function(repo_name, pull_request_id) {
374 var postData = {
374 var postData = {
375 '_method': 'put',
376 'update_commits': true};
375 'update_commits': true};
377 _updatePullRequest(repo_name, pull_request_id, postData);
376 _updatePullRequest(repo_name, pull_request_id, postData);
378 };
377 };
General Comments 0
You need to be logged in to leave comments. Login now