def update_pull_base_branch(pull, installation_id, method): try: if method == "merge": branch_updater.update_with_api(pull) else: branch_updater.update_with_git(pull, installation_id, method) except branch_updater.BranchUpdateFailure as e: # NOTE(sileht): Maybe the PR have been rebased and/or merged manually # in the meantime. So double check that to not report a wrong status pull.g_pull.update() output = merge_report(pull) if output: return output else: return ("failure", "Base branch update has failed", e.message) else: # NOTE(sileht): We update g_pull to have the new head.sha, # so future created checks will be posted on the new sha. # Otherwise the checks will be lost the GitHub UI on the # old sha. pull.wait_for_sha_change() return ( None, "Base branch updates done", "The pull request has been automatically " "updated to follow its base branch and will be " "merged soon", )
def _sync_with_base_branch( self, ctxt: context.Context, rule: "rules.EvaluatedRule", q: queue.Queue ) -> check_api.Result: method = self.config["strict_method"] user = self.config["update_bot_account"] or self.config["bot_account"] try: if method == "merge": branch_updater.update_with_api(ctxt) else: output = branch_updater.pre_rebase_check(ctxt) if output: return output branch_updater.rebase_with_git(ctxt, user) except branch_updater.BranchUpdateFailure as e: # NOTE(sileht): Maybe the PR has been rebased and/or merged manually # in the meantime. So double check that to not report a wrong status. ctxt.update() output = self.merge_report(ctxt) if output: return output else: q.remove_pull(ctxt) q.add_pull(ctxt, typing.cast(queue.QueueConfig, self.config)) return check_api.Result( check_api.Conclusion.FAILURE, "Base branch update has failed", e.message, ) else: return self.get_strict_status(ctxt, rule, q, is_behind=False)
def update_pull_base_branch( ctxt: context.Context, rule: rules.Rule, missing_conditions: typing.List[filter.Filter], queue: queue.Queue, config: typing.Dict, ) -> check_api.Result: method = config["strict_method"] user = config["update_bot_account"] or config["bot_account"] try: if method == "merge": branch_updater.update_with_api(ctxt) else: branch_updater.update_with_git(ctxt, method, user) except branch_updater.BranchUpdateFailure as e: # NOTE(sileht): Maybe the PR have been rebased and/or merged manually # in the meantime. So double check that to not report a wrong status ctxt.update() output = merge_report(ctxt, True) if output: return output else: queue.move_pull_at_end(ctxt.pull["number"], config) return check_api.Result(check_api.Conclusion.FAILURE, "Base branch update has failed", e.message) else: return get_strict_status(ctxt, rule, missing_conditions, need_update=False)
def run(ctxt, rule, missing_conditions): try: branch_updater.update_with_api(ctxt) except branch_updater.BranchUpdateFailure as e: return "failure", "Branch update failed", str(e) else: return "success", "Branch has been successfully updated", ""
def _sync_with_base_branch( self, ctxt: context.Context, rule: "rules.EvaluatedRule", q: queue.Queue ) -> check_api.Result: # 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 check_api.Result( check_api.Conclusion.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 check_api.Result( check_api.Conclusion.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.", ) method = self.config["strict_method"] user = self.config["update_bot_account"] or self.config["bot_account"] try: if method == "merge": branch_updater.update_with_api(ctxt) else: branch_updater.update_with_git(ctxt, method, user) except branch_updater.BranchUpdateFailure as e: # NOTE(sileht): Maybe the PR has been rebased and/or merged manually # in the meantime. So double check that to not report a wrong status. ctxt.update() output = self.merge_report(ctxt) if output: return output else: q.move_pull_at_end(ctxt.pull["number"], self.config) return check_api.Result( check_api.Conclusion.FAILURE, "Base branch update has failed", e.message, ) else: return self.get_strict_status(ctxt, rule, q, is_behind=False)
def run(ctxt, rule, missing_conditions) -> check_api.Result: if ctxt.is_behind: try: branch_updater.update_with_api(ctxt) except branch_updater.BranchUpdateFailure as e: return check_api.Result(check_api.Conclusion.FAILURE, "Branch update failed", str(e)) else: return check_api.Result( check_api.Conclusion.SUCCESS, "Branch has been successfully updated", "", ) else: return check_api.Result(check_api.Conclusion.SUCCESS, "Branch already up to date", "")
def update_pull_base_branch(pull, method): try: if method == "merge": branch_updater.update_with_api(pull) else: branch_updater.update_with_git(pull, method) except branch_updater.BranchUpdateFailure as e: # NOTE(sileht): Maybe the PR have been rebased and/or merged manually # in the meantime. So double check that to not report a wrong status pull.update() output = merge_report(pull, True) if output: return output else: return ("failure", "Base branch update has failed", e.message) else: return get_wait_for_ci_report(pull)
def update_pull_base_branch(ctxt, method, user): try: if method == "merge": branch_updater.update_with_api(ctxt) else: branch_updater.update_with_git(ctxt, method, user) except branch_updater.BranchUpdateFailure as e: # NOTE(sileht): Maybe the PR have been rebased and/or merged manually # in the meantime. So double check that to not report a wrong status ctxt.update() output = merge_report(ctxt, True) if output: return output else: return ("failure", "Base branch update has failed", e.message) else: return get_strict_status(ctxt, need_update=False)