def cancel(self, ctxt, rule, missing_conditions) -> check_api.Result: self._set_effective_priority(ctxt) q = queue.Queue.from_context(ctxt) if ctxt.pull["state"] == "closed": output = helpers.merge_report(ctxt, self.config["strict"]) if output: q.remove_pull(ctxt.pull["number"]) return output # We just rebase the pull request, don't cancel it yet if CIs are # running. The pull request will be merge if all rules match again. # if not we will delete it when we received all CIs termination if self.config["strict"] and self._required_statuses_in_progress( ctxt, missing_conditions): if self._should_be_merged(ctxt, q): # Just wait for CIs to finish return helpers.get_strict_status(ctxt, rule, missing_conditions, need_update=ctxt.is_behind) else: # Something got merged in the base branch in the meantime: rebase it again return self._sync_with_base_branch(ctxt, rule, missing_conditions, q) q.remove_pull(ctxt.pull["number"]) return self.cancelled_check_report
def _sync_with_base_branch(self, ctxt): # If PR from a public fork but cannot be edited if (ctxt.pull_from_fork and not ctxt.pull["base"]["repo"]["private"] and not ctxt.pull["maintainer_can_modify"]): return ( "failure", "Pull request can't be updated with latest base branch changes", "Mergify needs the permission to update the base branch of the pull request.\n" f"{ctxt.pull['base']['repo']['owner']['login']} needs to " "[authorize modification on its base branch]" "(https://help.github.com/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork/).", ) # If PR from a private fork but cannot be edited: # NOTE(jd): GitHub removed the ability to configure `maintainer_can_modify` on private fork we which make strict mode broken elif (ctxt.pull_from_fork and ctxt.pull["base"]["repo"]["private"] and not ctxt.pull["maintainer_can_modify"]): return ( "failure", "Pull request can't be updated with latest base branch changes", "Mergify needs the permission to update the base branch of the pull request.\n" "GitHub does not allow a GitHub App to modify base branch for a private fork.\n" "You cannot use strict mode with a pull request from a private fork.", ) elif self.config["strict"] in ("smart+fasttrack", "smart+ordered"): return helpers.get_strict_status(ctxt, need_update=ctxt.is_behind) else: return helpers.update_pull_base_branch( ctxt, self.config["strict_method"], self.config["bot_account"], )
def cancel(self, ctxt, rule, missing_conditions): q = queue.Queue.from_context(ctxt) if ctxt.pull["state"] == "closed": output = helpers.merge_report(ctxt, self.config["strict"]) if output: q.remove_pull(ctxt.pull["number"]) return output # We just rebase the pull request, don't cancel it yet if CIs are # running. The pull request will be merge if all rules match again. # if not we will delete it when we received all CIs termination if self.config["strict"] and self._required_statuses_in_progress( ctxt, missing_conditions ): return helpers.get_strict_status( ctxt, rule, missing_conditions, need_update=ctxt.is_behind ) q.remove_pull(ctxt.pull["number"]) return self.cancelled_check_report