Returns the expected next state based on the event and the current state.
(self, current_state)
| 175 | self.pull.remove_from_labels(label) |
| 176 | |
| 177 | def compute_next_state(self, current_state): |
| 178 | """ |
| 179 | Returns the expected next state based on the event and |
| 180 | the current state. |
| 181 | """ |
| 182 | if (self.event_name == "pull_request_target" and |
| 183 | self.event_payload['action'] == 'opened'): |
| 184 | if self.is_committer('pull_request'): |
| 185 | return PullRequestState.committer_review |
| 186 | else: |
| 187 | return PullRequestState.review |
| 188 | elif (self.event_name == "pull_request_review" and |
| 189 | self.event_payload["action"] == "submitted"): |
| 190 | review_state = self.event_payload["review"]["state"].lower() |
| 191 | if not self.is_committer('review'): |
| 192 | # Non-committer reviews cannot change state once committer has already |
| 193 | # reviewed, requested changes or approved |
| 194 | if current_state in ( |
| 195 | PullRequestState.change_review, |
| 196 | PullRequestState.changes, |
| 197 | PullRequestState.merge): |
| 198 | return current_state |
| 199 | else: |
| 200 | return PullRequestState.committer_review |
| 201 | if review_state == 'approved': |
| 202 | return PullRequestState.merge |
| 203 | else: |
| 204 | return PullRequestState.changes |
| 205 | elif (self.event_name == "pull_request_target" and |
| 206 | self.event_payload['action'] == 'synchronize' and |
| 207 | current_state == PullRequestState.changes): |
| 208 | return PullRequestState.change_review |
| 209 | # Default already opened PRs to Review state. |
| 210 | if current_state is None: |
| 211 | current_state = PullRequestState.review |
| 212 | return current_state |
| 213 | |
| 214 | def set_state(self, state): |
| 215 | """Sets the State label to the PR.""" |