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",
        )
Beispiel #2
0
    def run(self, ctxt, rule, missing_conditions):
        if not config.GITHUB_APP:
            return (
                "failure",
                "Unavailable with GitHub Action",
                "Due to GitHub Action limitation, the `rebase` command is only available "
                "with the Mergify GitHub App.",
            )

        if ctxt.is_behind:
            if ctxt.github_workflow_changed():
                return (
                    "action_required",
                    "Pull request must be rebased manually.",
                    "GitHub App like Mergify are not allowed to rebase pull request where `.github/workflows` is changed.",
                )

            try:
                branch_updater.update_with_git(ctxt, "rebase",
                                               self.config["bot_account"])
                return "success", "Branch has been successfully rebased", ""
            except branch_updater.BranchUpdateFailure as e:
                return "failure", "Branch rebase failed", str(e)
        else:
            return "success", "Branch already up to date", ""
Beispiel #3
0
    def run(self, ctxt, rule, missing_conditions) -> check_api.Result:
        if not config.GITHUB_APP:
            return check_api.Result(
                check_api.Conclusion.FAILURE,
                "Unavailable with GitHub Action",
                "Due to GitHub Action limitation, the `rebase` command is only available "
                "with the Mergify GitHub App.",
            )

        if ctxt.is_behind:
            if ctxt.github_workflow_changed():
                return check_api.Result(
                    check_api.Conclusion.ACTION_REQUIRED,
                    "Pull request must be rebased manually.",
                    "GitHub App like Mergify are not allowed to rebase pull request where `.github/workflows` is changed.",
                )

            try:
                branch_updater.update_with_git(ctxt, "rebase",
                                               self.config["bot_account"])
                return check_api.Result(
                    check_api.Conclusion.SUCCESS,
                    "Branch has been successfully rebased",
                    "",
                )
            except branch_updater.BranchUpdateFailure as e:
                return check_api.Result(check_api.Conclusion.FAILURE,
                                        "Branch rebase failed", str(e))
        else:
            return check_api.Result(check_api.Conclusion.SUCCESS,
                                    "Branch already up to date", "")
Beispiel #4
0
 def run(pull, sources, missing_conditions):
     try:
         branch_updater.update_with_git(pull, "rebase")
     except branch_updater.BranchUpdateFailure as e:
         return "failure", "Branch rebase failed", str(e)
     else:
         return "success", "Branch has been successfully rebased", ""
Beispiel #5
0
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)
Beispiel #6
0
 def run(installation_id, installation_token, event_type, data, pull,
         missing_conditions):
     try:
         branch_updater.update_with_git(pull, installation_id, "rebase")
     except branch_updater.BranchUpdateFailure as e:
         return "failure", "Branch rebase failed", str(e)
     else:
         return "success", "Branch has been successfully rebased", ""
Beispiel #7
0
    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)
Beispiel #8
0
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)
Beispiel #9
0
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)
Beispiel #10
0
    def run(self, ctxt, rule, missing_conditions):
        if not config.GITHUB_APP:
            return (
                "failure",
                "Unavailable with GitHub Action",
                "Due to GitHub Action limitation, the `rebase` command is only available "
                "with the Mergify GitHub App.",
            )

        if ctxt.is_behind:
            try:
                branch_updater.update_with_git(ctxt, "rebase",
                                               self.config["bot_account"])
            except branch_updater.BranchUpdateFailure as e:
                return "failure", "Branch rebase failed", str(e)
        else:
            return "success", "Branch already up to date", ""