##// 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 113 data = self._prepare_data(backend)
114 114 reviewers = [
115 115 {'username': TEST_USER_REGULAR_LOGIN,
116 'reasons': ['added manually']},
116 'reasons': ['{} added manually'.format(TEST_USER_REGULAR_LOGIN)]},
117 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 121 data['reviewers'] = reviewers
122
121 123 id_, params = build_data(
122 124 self.apikey_regular, 'create_pull_request', **data)
123 125 response = api_call(self.app, params)
@@ -128,12 +130,24 b' class TestCreatePullRequestApi(object):'
128 130 assert result['result']['msg'] == expected_message
129 131 pull_request_id = result['result']['pull_request_id']
130 132 pull_request = PullRequestModel().get(pull_request_id)
131 actual_reviewers = [
132 {'username': r.user.username,
133 'reasons': ['added manually'],
134 } for r in pull_request.reviewers
135 ]
136 assert sorted(actual_reviewers) == sorted(reviewers)
133
134 actual_reviewers = []
135 for rev in pull_request.reviewers:
136 entry = {
137 'username': rev.user.username,
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 152 @pytest.mark.backends("git", "hg")
139 153 def test_create_with_reviewers_specified_by_ids(
@@ -159,12 +173,23 b' class TestCreatePullRequestApi(object):'
159 173 assert result['result']['msg'] == expected_message
160 174 pull_request_id = result['result']['pull_request_id']
161 175 pull_request = PullRequestModel().get(pull_request_id)
162 actual_reviewers = [
163 {'username': r.user.user_id,
164 'reasons': ['added manually'],
165 } for r in pull_request.reviewers
166 ]
167 assert sorted(actual_reviewers) == sorted(reviewers)
176
177 actual_reviewers = []
178 for rev in pull_request.reviewers:
179 entry = {
180 'username': rev.user.user_id,
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 194 @pytest.mark.backends("git", "hg")
170 195 def test_create_fails_when_the_reviewer_is_not_found(self, backend):
@@ -271,9 +296,10 b' class TestCreatePullRequestApi(object):'
271 296 def test_create_fails_when_no_permissions(self, backend):
272 297 data = self._prepare_data(backend)
273 298 RepoModel().revoke_user_permission(
274 self.source.repo_name, User.DEFAULT_USER)
299 self.source.repo_name, self.test_user)
275 300 RepoModel().revoke_user_permission(
276 self.source.repo_name, self.test_user)
301 self.source.repo_name, User.DEFAULT_USER)
302
277 303 id_, params = build_data(
278 304 self.apikey_regular, 'create_pull_request', **data)
279 305 response = api_call(self.app, params)
@@ -641,6 +641,7 b' def create_pull_request('
641 641
642 642 reviewer_objects = Optional.extract(reviewers) or []
643 643
644 # serialize and validate passed in given reviewers
644 645 if reviewer_objects:
645 646 schema = ReviewerListSchema()
646 647 try:
@@ -653,20 +654,19 b' def create_pull_request('
653 654 user = get_user_or_error(reviewer_object['username'])
654 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 658 PullRequestModel().get_reviewer_functions()
658 659
660 # recalculate reviewers logic, to make sure we can validate this
659 661 reviewer_rules = get_default_reviewers_data(
660 662 apiuser.get_instance(), source_db_repo,
661 663 source_commit, target_db_repo, target_commit)
662 664
663 # specified rules are later re-validated, thus we can assume users will
664 # eventually provide those that meet the reviewer criteria.
665 if not reviewer_objects:
666 reviewer_objects = reviewer_rules['reviewers']
665 # now MERGE our given with the calculated
666 reviewer_objects = reviewer_rules['reviewers'] + reviewer_objects
667 667
668 668 try:
669 reviewers = get_validated_reviewers(
669 reviewers = validate_default_reviewers(
670 670 reviewer_objects, reviewer_rules)
671 671 except ValueError as e:
672 672 raise JSONRPCError('Reviewers Validation: {}'.format(e))
@@ -881,7 +881,8 b' class RepoPullRequestsView(RepoAppView, '
881 881 source_commit, target_db_repo, target_commit)
882 882
883 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 887 pullrequest_title = _form['pullrequest_title']
887 888 title_source_ref = source_ref.split(':', 2)[1]
General Comments 0
You need to be logged in to leave comments. Login now