##// END OF EJS Templates
api: creation of pull_request now honor additional reviewers when using reviewer rules.
marcink -
r2881:00ce3d87 default
parent child Browse files
Show More
@@ -113,11 +113,13 b' class TestCreatePullRequestApi(object):'
113 data = self._prepare_data(backend)
113 data = self._prepare_data(backend)
114 reviewers = [
114 reviewers = [
115 {'username': TEST_USER_REGULAR_LOGIN,
115 {'username': TEST_USER_REGULAR_LOGIN,
116 'reasons': ['added manually']},
116 'reasons': ['{} added manually'.format(TEST_USER_REGULAR_LOGIN)]},
117 {'username': TEST_USER_ADMIN_LOGIN,
117 {'username': TEST_USER_ADMIN_LOGIN,
118 'reasons': ['added manually']},
118 'reasons': ['{} added manually'.format(TEST_USER_ADMIN_LOGIN)],
119 'mandatory': True},
119 ]
120 ]
120 data['reviewers'] = reviewers
121 data['reviewers'] = reviewers
122
121 id_, params = build_data(
123 id_, params = build_data(
122 self.apikey_regular, 'create_pull_request', **data)
124 self.apikey_regular, 'create_pull_request', **data)
123 response = api_call(self.app, params)
125 response = api_call(self.app, params)
@@ -128,12 +130,24 b' class TestCreatePullRequestApi(object):'
128 assert result['result']['msg'] == expected_message
130 assert result['result']['msg'] == expected_message
129 pull_request_id = result['result']['pull_request_id']
131 pull_request_id = result['result']['pull_request_id']
130 pull_request = PullRequestModel().get(pull_request_id)
132 pull_request = PullRequestModel().get(pull_request_id)
131 actual_reviewers = [
133
132 {'username': r.user.username,
134 actual_reviewers = []
133 'reasons': ['added manually'],
135 for rev in pull_request.reviewers:
134 } for r in pull_request.reviewers
136 entry = {
135 ]
137 'username': rev.user.username,
136 assert sorted(actual_reviewers) == sorted(reviewers)
138 'reasons': rev.reasons,
139 }
140 if rev.mandatory:
141 entry['mandatory'] = rev.mandatory
142 actual_reviewers.append(entry)
143
144 # default reviewer will be added who is an owner of the repo
145 reviewers.append(
146 {'username': pull_request.author.username,
147 'reasons': [u'Default reviewer', u'Repository owner']},
148 )
149 assert sorted(actual_reviewers, key=lambda e: e['username']) \
150 == sorted(reviewers, key=lambda e: e['username'])
137
151
138 @pytest.mark.backends("git", "hg")
152 @pytest.mark.backends("git", "hg")
139 def test_create_with_reviewers_specified_by_ids(
153 def test_create_with_reviewers_specified_by_ids(
@@ -159,12 +173,23 b' class TestCreatePullRequestApi(object):'
159 assert result['result']['msg'] == expected_message
173 assert result['result']['msg'] == expected_message
160 pull_request_id = result['result']['pull_request_id']
174 pull_request_id = result['result']['pull_request_id']
161 pull_request = PullRequestModel().get(pull_request_id)
175 pull_request = PullRequestModel().get(pull_request_id)
162 actual_reviewers = [
176
163 {'username': r.user.user_id,
177 actual_reviewers = []
164 'reasons': ['added manually'],
178 for rev in pull_request.reviewers:
165 } for r in pull_request.reviewers
179 entry = {
166 ]
180 'username': rev.user.user_id,
167 assert sorted(actual_reviewers) == sorted(reviewers)
181 'reasons': rev.reasons,
182 }
183 if rev.mandatory:
184 entry['mandatory'] = rev.mandatory
185 actual_reviewers.append(entry)
186 # default reviewer will be added who is an owner of the repo
187 reviewers.append(
188 {'username': pull_request.author.user_id,
189 'reasons': [u'Default reviewer', u'Repository owner']},
190 )
191 assert sorted(actual_reviewers, key=lambda e: e['username']) \
192 == sorted(reviewers, key=lambda e: e['username'])
168
193
169 @pytest.mark.backends("git", "hg")
194 @pytest.mark.backends("git", "hg")
170 def test_create_fails_when_the_reviewer_is_not_found(self, backend):
195 def test_create_fails_when_the_reviewer_is_not_found(self, backend):
@@ -271,9 +296,10 b' class TestCreatePullRequestApi(object):'
271 def test_create_fails_when_no_permissions(self, backend):
296 def test_create_fails_when_no_permissions(self, backend):
272 data = self._prepare_data(backend)
297 data = self._prepare_data(backend)
273 RepoModel().revoke_user_permission(
298 RepoModel().revoke_user_permission(
274 self.source.repo_name, User.DEFAULT_USER)
299 self.source.repo_name, self.test_user)
275 RepoModel().revoke_user_permission(
300 RepoModel().revoke_user_permission(
276 self.source.repo_name, self.test_user)
301 self.source.repo_name, User.DEFAULT_USER)
302
277 id_, params = build_data(
303 id_, params = build_data(
278 self.apikey_regular, 'create_pull_request', **data)
304 self.apikey_regular, 'create_pull_request', **data)
279 response = api_call(self.app, params)
305 response = api_call(self.app, params)
@@ -641,6 +641,7 b' def create_pull_request('
641
641
642 reviewer_objects = Optional.extract(reviewers) or []
642 reviewer_objects = Optional.extract(reviewers) or []
643
643
644 # serialize and validate passed in given reviewers
644 if reviewer_objects:
645 if reviewer_objects:
645 schema = ReviewerListSchema()
646 schema = ReviewerListSchema()
646 try:
647 try:
@@ -653,20 +654,19 b' def create_pull_request('
653 user = get_user_or_error(reviewer_object['username'])
654 user = get_user_or_error(reviewer_object['username'])
654 reviewer_object['user_id'] = user.user_id
655 reviewer_object['user_id'] = user.user_id
655
656
656 get_default_reviewers_data, get_validated_reviewers = \
657 get_default_reviewers_data, validate_default_reviewers = \
657 PullRequestModel().get_reviewer_functions()
658 PullRequestModel().get_reviewer_functions()
658
659
660 # recalculate reviewers logic, to make sure we can validate this
659 reviewer_rules = get_default_reviewers_data(
661 reviewer_rules = get_default_reviewers_data(
660 apiuser.get_instance(), source_db_repo,
662 apiuser.get_instance(), source_db_repo,
661 source_commit, target_db_repo, target_commit)
663 source_commit, target_db_repo, target_commit)
662
664
663 # specified rules are later re-validated, thus we can assume users will
665 # now MERGE our given with the calculated
664 # eventually provide those that meet the reviewer criteria.
666 reviewer_objects = reviewer_rules['reviewers'] + reviewer_objects
665 if not reviewer_objects:
666 reviewer_objects = reviewer_rules['reviewers']
667
667
668 try:
668 try:
669 reviewers = get_validated_reviewers(
669 reviewers = validate_default_reviewers(
670 reviewer_objects, reviewer_rules)
670 reviewer_objects, reviewer_rules)
671 except ValueError as e:
671 except ValueError as e:
672 raise JSONRPCError('Reviewers Validation: {}'.format(e))
672 raise JSONRPCError('Reviewers Validation: {}'.format(e))
@@ -881,7 +881,8 b' class RepoPullRequestsView(RepoAppView, '
881 source_commit, target_db_repo, target_commit)
881 source_commit, target_db_repo, target_commit)
882
882
883 given_reviewers = _form['review_members']
883 given_reviewers = _form['review_members']
884 reviewers = validate_default_reviewers(given_reviewers, reviewer_rules)
884 reviewers = validate_default_reviewers(
885 given_reviewers, reviewer_rules)
885
886
886 pullrequest_title = _form['pullrequest_title']
887 pullrequest_title = _form['pullrequest_title']
887 title_source_ref = source_ref.split(':', 2)[1]
888 title_source_ref = source_ref.split(':', 2)[1]
General Comments 0
You need to be logged in to leave comments. Login now