Show More
@@ -1020,6 +1020,9 b' class PullRequestModel(BaseModel):' | |||||
1020 | log.debug("Adding %s reviewers", ids_to_add) |
|
1020 | log.debug("Adding %s reviewers", ids_to_add) | |
1021 | log.debug("Removing %s reviewers", ids_to_remove) |
|
1021 | log.debug("Removing %s reviewers", ids_to_remove) | |
1022 | changed = False |
|
1022 | changed = False | |
|
1023 | added_audit_reviewers = [] | |||
|
1024 | removed_audit_reviewers = [] | |||
|
1025 | ||||
1023 | for uid in ids_to_add: |
|
1026 | for uid in ids_to_add: | |
1024 | changed = True |
|
1027 | changed = True | |
1025 | _usr = self._get_user(uid) |
|
1028 | _usr = self._get_user(uid) | |
@@ -1030,29 +1033,37 b' class PullRequestModel(BaseModel):' | |||||
1030 | # NOTE(marcink): mandatory shouldn't be changed now |
|
1033 | # NOTE(marcink): mandatory shouldn't be changed now | |
1031 | # reviewer.mandatory = reviewers[uid]['reasons'] |
|
1034 | # reviewer.mandatory = reviewers[uid]['reasons'] | |
1032 | Session().add(reviewer) |
|
1035 | Session().add(reviewer) | |
1033 | self._log_audit_action( |
|
1036 | added_audit_reviewers.append(reviewer.get_dict()) | |
1034 | 'repo.pull_request.reviewer.add', {'data': reviewer.get_dict()}, |
|
|||
1035 | user, pull_request) |
|
|||
1036 |
|
1037 | |||
1037 | for uid in ids_to_remove: |
|
1038 | for uid in ids_to_remove: | |
1038 | changed = True |
|
1039 | changed = True | |
|
1040 | # NOTE(marcink): we fetch "ALL" reviewers using .all(). This is an edge case | |||
|
1041 | # that prevents and fixes cases that we added the same reviewer twice. | |||
|
1042 | # this CAN happen due to the lack of DB checks | |||
1039 | reviewers = PullRequestReviewers.query()\ |
|
1043 | reviewers = PullRequestReviewers.query()\ | |
1040 | .filter(PullRequestReviewers.user_id == uid, |
|
1044 | .filter(PullRequestReviewers.user_id == uid, | |
1041 | PullRequestReviewers.pull_request == pull_request)\ |
|
1045 | PullRequestReviewers.pull_request == pull_request)\ | |
1042 | .all() |
|
1046 | .all() | |
1043 | # use .all() in case we accidentally added the same person twice |
|
1047 | ||
1044 | # this CAN happen due to the lack of DB checks |
|
|||
1045 | for obj in reviewers: |
|
1048 | for obj in reviewers: | |
1046 |
|
|
1049 | added_audit_reviewers.append(obj.get_dict()) | |
1047 | Session().delete(obj) |
|
1050 | Session().delete(obj) | |
1048 | self._log_audit_action( |
|
|||
1049 | 'repo.pull_request.reviewer.delete', |
|
|||
1050 | {'old_data': old_data}, user, pull_request) |
|
|||
1051 |
|
1051 | |||
1052 | if changed: |
|
1052 | if changed: | |
|
1053 | Session().expire_all() | |||
1053 | pull_request.updated_on = datetime.datetime.now() |
|
1054 | pull_request.updated_on = datetime.datetime.now() | |
1054 | Session().add(pull_request) |
|
1055 | Session().add(pull_request) | |
1055 |
|
1056 | |||
|
1057 | # finally store audit logs | |||
|
1058 | for user_data in added_audit_reviewers: | |||
|
1059 | self._log_audit_action( | |||
|
1060 | 'repo.pull_request.reviewer.add', {'data': user_data}, | |||
|
1061 | user, pull_request) | |||
|
1062 | for user_data in removed_audit_reviewers: | |||
|
1063 | self._log_audit_action( | |||
|
1064 | 'repo.pull_request.reviewer.delete', {'old_data': user_data}, | |||
|
1065 | user, pull_request) | |||
|
1066 | ||||
1056 | self.notify_reviewers(pull_request, ids_to_add) |
|
1067 | self.notify_reviewers(pull_request, ids_to_add) | |
1057 | return ids_to_add, ids_to_remove |
|
1068 | return ids_to_add, ids_to_remove | |
1058 |
|
1069 |
General Comments 0
You need to be logged in to leave comments.
Login now