Esempio n. 1
0
    def proceed_queue(self, branch, branch_rule, collaborators):

        p = self._get_next_pull_to_processed(branch, branch_rule,
                                             collaborators)
        if not p:
            LOG.info("nothing to do",
                     repository=self.repository.full_name,
                     branch=branch)
            return

        if p.mergify_state == MergifyState.READY:
            p.post_check_status("success", "Merged")

            if p.merge(branch_rule["merge_strategy"]["method"],
                       branch_rule["merge_strategy"]["rebase_fallback"]):
                # Wait for the closed event now
                LOG.info("merged", pull_request=p)
            else:  # pragma: no cover
                p.set_and_post_error("Merge fail")
                self._cache_save_pull(p)
                raise tenacity.TryAgain

        elif p.mergify_state == MergifyState.ALMOST_READY:
            LOG.info("waiting for final statuses completion", pull_request=p)

        elif p.mergify_state == MergifyState.NEED_BRANCH_UPDATE:
            if branch_updater.update(p, self._subscription["token"]):
                # Wait for the synchronize event now
                LOG.info("branch updated", pull_request=p)
            else:  # pragma: no cover
                p.set_and_post_error("contributor branch is not updatable, "
                                     "manual update/rebase required.")
                self._cache_save_pull(p)
                raise tenacity.TryAgain
Esempio n. 2
0
def update_pull_base_branch(pull, subscription, method):
    updated = branch_updater.update(pull, subscription["token"], method)
    if updated:
        redis = utils.get_redis_for_cache()
        # NOTE(sileht): We store this for dismissal action
        redis.setex("branch-update-%s" % updated, 60 * 60, updated)

        # 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")
    else:
        # 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", "")
Esempio n. 3
0
def update_pull_base_branch(pull, subscription):
    updated = branch_updater.update(pull, subscription["token"])
    if updated:
        # 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")
    else:  # pragma: no cover
        return ("failure", "Base branch update has failed", "")
Esempio n. 4
0
    def __call__(self, installation_id, installation_token, subscription,
                 event_type, data, pull):
        pull.log.debug("process merge", config=self.config)

        # NOTE(sileht): Take care of all branch protection state
        if pull.g_pull.mergeable_state == "dirty":
            return None, "Merge conflict needs to be solved", " "
        elif pull.g_pull.mergeable_state == "unknown":
            return ("failure", "Pull request state reported as `unknown` by "
                    "GitHub", " ")
        elif pull.g_pull.mergeable_state == "blocked":
            return ("failure", "Branch protection settings are blocking "
                    "automatic merging", " ")
        elif (pull.g_pull.mergeable_state == "behind"
              and not self.config["strict"]):
            # Strict mode has been enabled in branch protection but not in
            # mergify
            return ("failure", "Branch protection setting 'strict' conflicts "
                    "with Mergify configuration", " ")
        # NOTE(sileht): remaining state "behind, clean, unstable, has_hooks"
        # are OK for us

        if self.config["strict"] and pull.is_behind():
            # TODO(sileht): strict: Don't blindly update all PRs, but just one
            # by one.

            updated = branch_updater.update(pull, subscription["token"])
            if not updated:  # pragma: no cover
                raise Exception("branch update of %s have failed" % pull)

            # NOTE(sileht): We update g_pull to have the new head.sha, so
            # future created checks will be post 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")

        else:
            if (self.config["method"] != "rebase"
                    or pull.g_pull.raw_data['rebaseable']):
                return self._merge(pull, self.config["method"])
            elif self.config["rebase_fallback"]:
                return self._merge(pull, self.config["rebase_fallback"])
            else:
                return ("action_required", "Automatic rebasing is not "
                        "possible, manual intervention required", " ")