async def get_pull_rule_checks_status(
        self, ctxt: context.Context, rule: "rules.EvaluatedRule"
    ) -> check_api.Conclusion:
        need_look_at_checks = []
        for condition in rule.missing_conditions:
            attribute_name = condition.get_attribute_name()
            if attribute_name.startswith("check-") or attribute_name.startswith(
                "status-"
            ):
                # TODO(sileht): Just return True here, no need to checks checks anymore,
                # this method is no more used by teh merge queue
                need_look_at_checks.append(condition)
            else:
                # something else does not match anymore
                return check_api.Conclusion.FAILURE

        if need_look_at_checks:
            if not await ctxt.checks:
                return check_api.Conclusion.PENDING

            states = [
                state
                for name, state in (await ctxt.checks).items()
                for cond in need_look_at_checks
                if await cond(utils.FakePR(cond.get_attribute_name(), name))
            ]
            if not states:
                return check_api.Conclusion.PENDING

            for state in states:
                if state in ("pending", None):
                    return check_api.Conclusion.PENDING

        return check_api.Conclusion.FAILURE
示例#2
0
async def get_queue_rule_checks_status(
        ctxt: context.Context,
        queue_rule: rules.EvaluatedQueueRule) -> check_api.Conclusion:
    if not queue_rule.missing_conditions:
        return check_api.Conclusion.SUCCESS

    missing_checks_conditions = [
        condition for condition in queue_rule.missing_conditions
        if condition.attribute_name.startswith("check-")
        or condition.attribute_name.startswith("status-")
    ]
    if not missing_checks_conditions:
        return check_api.Conclusion.PENDING

    states_of_missing_checks = [
        state for name, state in (await ctxt.checks).items()
        for cond in missing_checks_conditions
        if await cond(utils.FakePR(cond.attribute_name, name))
    ]
    #  We have missing conditions but no associated states, this means
    #  that some checks are missing, we assume they are pending
    if not states_of_missing_checks:
        return check_api.Conclusion.PENDING

    for state in states_of_missing_checks:
        # We found a missing condition with the check pending, keep the PR
        # in queue
        if state in ("pending", None):
            return check_api.Conclusion.PENDING

    # We don't have any checks pending, but some conditions still don't match,
    # so can never ever merge this PR, removing it from the queue
    return check_api.Conclusion.FAILURE
示例#3
0
    async def _should_be_cancel(self, ctxt: context.Context,
                                rule: "rules.EvaluatedRule") -> bool:
        # It's closed, it's not going to change
        if ctxt.pull["state"] == "closed":
            return True

        if ctxt.have_been_synchronized():
            return True

        need_look_at_checks = await self._get_branch_protection_conditions(ctxt
                                                                           )
        for condition in rule.missing_conditions:
            attribute_name = condition.get_attribute_name()
            if attribute_name.startswith(
                    "check-") or attribute_name.startswith("status-"):
                # TODO(sileht): Just return True here, no need to checks checks anymore,
                # this method is no more used by teh merge queue
                need_look_at_checks.append(condition)
            else:
                # something else does not match anymore
                return True

        if need_look_at_checks:
            if not await ctxt.checks:
                return False

            states = [
                state for name, state in (await ctxt.checks).items()
                for cond in need_look_at_checks
                if await cond(utils.FakePR(cond.get_attribute_name(), name))
            ]
            if not states:
                return False

            for state in states:
                if state in ("pending", None):
                    return False

        return True