##// END OF EJS Templates
pull-requests: handle exceptions in state change and improve logging.
marcink -
r3927:65220619 default
parent child Browse files
Show More
@@ -3805,21 +3805,35 b' class _SetState(object):'
3805 self._pr = pull_request
3805 self._pr = pull_request
3806 self._org_state = back_state or pull_request.pull_request_state
3806 self._org_state = back_state or pull_request.pull_request_state
3807 self._pr_state = pr_state
3807 self._pr_state = pr_state
3808 self._current_state = None
3808
3809
3809 def __enter__(self):
3810 def __enter__(self):
3810 log.debug('StateLock: entering set state context, setting state to: `%s`',
3811 log.debug('StateLock: entering set state context, setting state to: `%s`',
3811 self._pr_state)
3812 self._pr_state)
3812 self._pr.pull_request_state = self._pr_state
3813 self.set_pr_state(self._pr_state)
3813 Session().add(self._pr)
3814 return self
3814 Session().commit()
3815
3815
3816 def __exit__(self, exc_type, exc_val, exc_tb):
3816 def __exit__(self, exc_type, exc_val, exc_tb):
3817 if exc_val is not None:
3818 log.error(traceback.format_exc(exc_tb))
3819 return None
3820
3821 self.set_pr_state(self._org_state)
3817 log.debug('StateLock: exiting set state context, setting state to: `%s`',
3822 log.debug('StateLock: exiting set state context, setting state to: `%s`',
3818 self._org_state)
3823 self._org_state)
3819 self._pr.pull_request_state = self._org_state
3824 @property
3820 Session().add(self._pr)
3825 def state(self):
3821 Session().commit()
3826 return self._current_state
3822
3827
3828 def set_pr_state(self, pr_state):
3829 try:
3830 self._pr.pull_request_state = pr_state
3831 Session().add(self._pr)
3832 Session().commit()
3833 self._current_state = pr_state
3834 except Exception:
3835 log.exception('Failed to set PullRequest %s state to %s', self._pr, pr_state)
3836 raise
3823
3837
3824 class _PullRequestBase(BaseModel):
3838 class _PullRequestBase(BaseModel):
3825 """
3839 """
@@ -507,10 +507,10 b' class PullRequestModel(BaseModel):'
507 # operation
507 # operation
508 pull_request = PullRequest.get(pull_request.pull_request_id)
508 pull_request = PullRequest.get(pull_request.pull_request_id)
509
509
510 # set as merging, for simulation, and if finished to created so we mark
510 # set as merging, for merge simulation, and if finished to created so we mark
511 # simulation is working fine
511 # simulation is working fine
512 with pull_request.set_state(PullRequest.STATE_MERGING,
512 with pull_request.set_state(PullRequest.STATE_MERGING,
513 final_state=PullRequest.STATE_CREATED):
513 final_state=PullRequest.STATE_CREATED) as state_obj:
514 MergeCheck.validate(
514 MergeCheck.validate(
515 pull_request, auth_user=auth_user, translator=translator)
515 pull_request, auth_user=auth_user, translator=translator)
516
516
@@ -1099,6 +1099,8 b' class PullRequestModel(BaseModel):'
1099 if not reviewers_ids:
1099 if not reviewers_ids:
1100 return
1100 return
1101
1101
1102 log.debug('Notify following reviewers about pull-request %s', reviewers_ids)
1103
1102 pull_request_obj = pull_request
1104 pull_request_obj = pull_request
1103 # get the current participants of this pull request
1105 # get the current participants of this pull request
1104 recipients = reviewers_ids
1106 recipients = reviewers_ids
General Comments 0
You need to be logged in to leave comments. Login now