Merge "Only the last CI result can be treated as merged"
This commit is contained in:
		| @@ -40,6 +40,7 @@ def find_ci_result(review, ci_map): | ||||
|  | ||||
|     review_id = review['id'] | ||||
|     review_number = review['number'] | ||||
|     ci_already_seen = set() | ||||
|  | ||||
|     for comment in reversed(review.get('comments') or []): | ||||
|         reviewer_id = comment['reviewer'].get('username') | ||||
| @@ -72,9 +73,13 @@ def find_ci_result(review, ci_map): | ||||
|             result = _find_vote(review, ci['id'], patch_set_number) | ||||
|  | ||||
|         if result is not None: | ||||
|             is_merged = (review['status'] == 'MERGED' and | ||||
|                          patch_set_number == review['patchSets'][-1] | ||||
|                          ['number']) | ||||
|             is_merged = ( | ||||
|                 review['status'] == 'MERGED' and | ||||
|                 patch_set_number == review['patchSets'][-1]['number'] and | ||||
|                 ci['id'] not in ci_already_seen) | ||||
|  | ||||
|             ci_already_seen.add(ci['id']) | ||||
|  | ||||
|             yield { | ||||
|                 'reviewer': comment['reviewer'], | ||||
|                 'ci_result': result, | ||||
|   | ||||
							
								
								
									
										79
									
								
								tests/unit/test_driverlog.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										79
									
								
								tests/unit/test_driverlog.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,79 @@ | ||||
| # Copyright (c) 2013 Mirantis Inc. | ||||
| # | ||||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| # you may not use this file except in compliance with the License. | ||||
| # You may obtain a copy of the License at | ||||
| # | ||||
| #   http://www.apache.org/licenses/LICENSE-2.0 | ||||
| # | ||||
| # Unless required by applicable law or agreed to in writing, software | ||||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||||
| # implied. | ||||
| # See the License for the specific language governing permissions and | ||||
| # limitations under the License. | ||||
|  | ||||
| import testtools | ||||
|  | ||||
| from stackalytics.processor import driverlog | ||||
|  | ||||
|  | ||||
| class TestDriverlog(testtools.TestCase): | ||||
|     def setUp(self): | ||||
|         super(TestDriverlog, self).setUp() | ||||
|  | ||||
|     def test_find_ci_result_voting_ci(self): | ||||
|         review = { | ||||
|             'record_type': 'review', | ||||
|             'id': 'I1045730e47e9e6ad31fcdfbaefdad77e2f3b2c3e', | ||||
|             'module': 'nova', | ||||
|             'branch': 'master', | ||||
|             'status': 'NEW', | ||||
|             'number': '97860', | ||||
|             'patchSets': [ | ||||
|                 {'number': '1', | ||||
|                  'approvals': [ | ||||
|                      {'type': 'Verified', 'description': 'Verified', | ||||
|                       'value': '1', 'grantedOn': 1234567890 - 1, | ||||
|                       'by': { | ||||
|                           'name': 'Batman', | ||||
|                           'email': 'batman@openstack.org', | ||||
|                           'username': 'batman'}}, | ||||
|                      {'type': 'Verified', 'description': 'Verified', | ||||
|                       'value': '-1', 'grantedOn': 1234567890, | ||||
|                       'by': { | ||||
|                           'name': 'Pikachu', | ||||
|                           'email': 'pikachu@openstack.org', | ||||
|                           'username': 'pikachu'}}, | ||||
|                  ]}], | ||||
|             'comments': [ | ||||
|                 {'message': 'Patch Set 1: build successful', | ||||
|                  'reviewer': {'username': 'batman'}, | ||||
|                  'timestamp': 1234567890} | ||||
|             ]} | ||||
|  | ||||
|         ci_map = { | ||||
|             'batman': { | ||||
|                 'name': 'Batman Driver', | ||||
|                 'vendor': 'Gotham Inc', | ||||
|                 'ci': { | ||||
|                     'id': 'batman' | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         res = list(driverlog.find_ci_result(review, ci_map)) | ||||
|  | ||||
|         expected_result = { | ||||
|             'reviewer': {'username': 'batman'}, | ||||
|             'ci_result': True, | ||||
|             'is_merged': False, | ||||
|             'message': 'build successful', | ||||
|             'date': 1234567890, | ||||
|             'review_id': 'I1045730e47e9e6ad31fcdfbaefdad77e2f3b2c3e', | ||||
|             'review_number': '97860', | ||||
|             'driver_name': 'Batman Driver', | ||||
|             'driver_vendor': 'Gotham Inc', | ||||
|         } | ||||
|         self.assertEqual(1, len(res), 'One CI result is expected') | ||||
|         self.assertEqual(expected_result, res[0]) | ||||
		Reference in New Issue
	
	Block a user
	 Jenkins
					Jenkins