##// END OF EJS Templates
pull-requests: handle exceptions in state change and improve logging.
marcink -
r3828:fde0bece stable
parent child Browse files
Show More
@@ -3772,21 +3772,35 b' class _SetState(object):'
3772 self._pr = pull_request
3772 self._pr = pull_request
3773 self._org_state = back_state or pull_request.pull_request_state
3773 self._org_state = back_state or pull_request.pull_request_state
3774 self._pr_state = pr_state
3774 self._pr_state = pr_state
3775 self._current_state = None
3775
3776
3776 def __enter__(self):
3777 def __enter__(self):
3777 log.debug('StateLock: entering set state context, setting state to: `%s`',
3778 log.debug('StateLock: entering set state context, setting state to: `%s`',
3778 self._pr_state)
3779 self._pr_state)
3779 self._pr.pull_request_state = self._pr_state
3780 self.set_pr_state(self._pr_state)
3780 Session().add(self._pr)
3781 return self
3781 Session().commit()
3782
3782
3783 def __exit__(self, exc_type, exc_val, exc_tb):
3783 def __exit__(self, exc_type, exc_val, exc_tb):
3784 if exc_val is not None:
3785 log.error(traceback.format_exc(exc_tb))
3786 return None
3787
3788 self.set_pr_state(self._org_state)
3784 log.debug('StateLock: exiting set state context, setting state to: `%s`',
3789 log.debug('StateLock: exiting set state context, setting state to: `%s`',
3785 self._org_state)
3790 self._org_state)
3786 self._pr.pull_request_state = self._org_state
3791 @property
3792 def state(self):
3793 return self._current_state
3794
3795 def set_pr_state(self, pr_state):
3796 try:
3797 self._pr.pull_request_state = pr_state
3787 Session().add(self._pr)
3798 Session().add(self._pr)
3788 Session().commit()
3799 Session().commit()
3789
3800 self._current_state = pr_state
3801 except Exception:
3802 log.exception('Failed to set PullRequest %s state to %s', self._pr, pr_state)
3803 raise
3790
3804
3791 class _PullRequestBase(BaseModel):
3805 class _PullRequestBase(BaseModel):
3792 """
3806 """
@@ -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