예제 #1
0
def test_embarked_pull_old_serialization() -> None:
    queue_config = rules.QueueConfig(
        priority=0,
        speculative_checks=5,
        batch_size=1,
        batch_max_wait_time=datetime.timedelta(seconds=0),
        allow_inplace_checks=True,
        disallow_checks_interruption_from_queues=[],
        checks_timeout=None,
        draft_bot_account=None,
    )
    config = queue.PullQueueConfig(
        name=rules.QueueName("foo"),
        strict_method="merge",
        update_method="merge",
        priority=0,
        effective_priority=0,
        bot_account=None,
        update_bot_account=None,
        queue_config=queue_config,
    )

    now = date.utcnow()
    old_typed = merge_train.EmbarkedPull.OldSerialized(
        github_types.GitHubPullRequestNumber(1234), config, now
    )
    old_untyped = json.loads(json.dumps(old_typed))
    ep = merge_train.EmbarkedPull.deserialize(mock.Mock(), old_untyped)
    assert ep.user_pull_request_number == 1234
    assert ep.config == config
    assert ep.queued_at == now
예제 #2
0
    async def get_config(
        self, pull_number: github_types.GitHubPullRequestNumber
    ) -> queue.PullQueueConfig:
        """Return merge config for a pull request.

        Do not use it for logic, just for displaying the queue summary.

        :param pull_number: The pull request number.
        """
        config_str = await self.repository.installation.redis.get(
            self._config_redis_queue_key(pull_number)
        )
        if config_str is None:
            self.log.error(
                "pull request queued without associated configuration",
                gh_pull=pull_number,
            )
            return queue.PullQueueConfig(
                {
                    "strict_method": "merge",
                    "priority": 2000,
                    "effective_priority": 2000,
                    "bot_account": None,
                    "update_bot_account": None,
                    "name": rules.QueueName(""),
                    "queue_config": rules.QueueConfig(
                        {"priority": 1, "speculative_checks": 1}
                    ),
                }
            )
        config: queue.PullQueueConfig = json.loads(config_str)
        return config
예제 #3
0
파일: queue.py 프로젝트: jd/mergify-engine
    def get_config(
            self,
            pull_number: github_types.GitHubPullRequestNumber) -> QueueConfig:
        """Return merge config for a pull request.

        Do not use it for logic, just for displaying the queue summary.

        :param pull_number: The pull request number.
        """
        config_str = self.redis.get(self._config_redis_queue_key(pull_number))
        if config_str is None:
            # TODO(sileht): Everything about queue should be done in redis transaction
            # e.g.: add/update/get/del of a pull in queue
            return QueueConfig({
                "strict_method": "merge",
                "priority": 2000,
                "effective_priority": 2000,
                "bot_account": None,
                "update_bot_account": None,
            })
        config: QueueConfig = json.loads(config_str)
        # TODO(sileht): for compatibility purpose, we can drop that in a couple of week
        config.setdefault("effective_priority", config["priority"])
        config.setdefault("bot_account", None)
        config.setdefault("update_bot_account", None)
        return config
예제 #4
0
파일: root.py 프로젝트: v1v/mergify-engine
async def queues(
    owner_id: github_types.GitHubAccountIdType,
    redis_cache: utils.RedisCache = fastapi.Depends(  # noqa: B008
        redis.get_redis_cache
    ),
) -> responses.Response:
    queues: typing.Dict[
        str, typing.Dict[str, typing.List[int]]
    ] = collections.defaultdict(dict)
    async for queue in redis_cache.scan_iter(
        match=f"merge-*~{owner_id}~*", count=10000
    ):
        queue_type, _, repo_id, branch = queue.split("~")
        if queue_type == "merge-queue":
            queues[repo_id][branch] = [
                int(pull) async for pull, _ in redis_cache.zscan_iter(queue)
            ]
        elif queue_type == "merge-train":
            train_raw = await redis_cache.get(queue)
            train = typing.cast(merge_train.Train.Serialized, json.loads(train_raw))
            _, _, repo_id, branch = queue.split("~")
            queues[repo_id][branch] = [
                int(c["user_pull_request_number"]) for c in train["cars"]
            ] + [int(wp[0]) for wp in train["waiting_pulls"]]

    return responses.JSONResponse(status_code=200, content=queues)
예제 #5
0
    async def load(self) -> None:
        train_raw = await self.repository.installation.redis.get(
            self._get_redis_key())

        if train_raw:
            train = typing.cast(Train.Serialized, json.loads(train_raw))
            self._waiting_pulls = [
                WaitingPull(*wp) for wp in train["waiting_pulls"]
            ]
            self._current_base_sha = train["current_base_sha"]
            self._cars = [TrainCar.deserialize(self, c) for c in train["cars"]]
        else:
            self._cars = []
            self._waiting_pulls = []
            self._current_base_sha = None
예제 #6
0
    async def test_run_count_seats_report(self) -> None:
        await self.setup_repo()
        await self.create_pr()
        await self.run_engine()
        if github_types.GitHubAccountIdType(
                config.TESTING_MERGIFY_TEST_1_ID) is None:
            raise RuntimeError("client_admin owner_id is None")
        if github_types.GitHubAccountIdType(
                config.TESTING_MERGIFY_TEST_2_ID) is None:
            raise RuntimeError("client_fork owner_id is None")
        if github_types.GitHubLogin("mergify-test1") is None:
            raise RuntimeError("client_admin owner is None")
        if github_types.GitHubLogin("mergify-test2") is None:
            raise RuntimeError("client_fork owner is None")
        args = argparse.Namespace(json=True, daemon=False)
        with mock.patch("sys.stdout") as stdout:
            with mock.patch.object(config, "SUBSCRIPTION_TOKEN"):
                await count_seats.report(args)
                s = "".join(call.args[0] for call in stdout.write.mock_calls)
                json_reports = json.loads(s)
                assert list(json_reports.keys()) == ["organizations"]
                assert len(json_reports["organizations"]) == 1

                org = json_reports["organizations"][0]
                assert org["id"] == config.TESTING_ORGANIZATION_ID
                assert org["login"] == config.TESTING_ORGANIZATION_NAME

                repos = (await self.client_admin.get(
                    url=
                    f"{config.GITHUB_REST_API_URL}/orgs/mergifyio-testing/repos"
                )).json()
                expected_repositories = sorted([(repo["id"], repo["name"])
                                                for repo in repos])
                assert (sorted([
                    (repo["id"], repo["name"]) for repo in org["repositories"]
                ]) == expected_repositories)

                members = (await self.client_admin.get(
                    url=
                    f"{config.GITHUB_REST_API_URL}/orgs/mergifyio-testing/members"
                )).json()
                users_expected = {(member["id"], member["login"])
                                  for member in members}
                for repo in org["repositories"]:
                    if repo["name"] == "functional-testing-repo":
                        users_retrieved = {
                            (write_user["id"], write_user["login"])
                            for write_user in repo["collaborators"]
                            ["write_users"]
                        }
                        assert users_retrieved.issubset(users_expected)
                        assert len(repo["collaborators"]
                                   ["write_users"]) == len(members)
                    if repo["id"] == self.repository_ctxt.repo["id"]:
                        assert sorted(
                            repo["collaborators"]["active_users"],
                            key=operator.itemgetter("id"),
                        ) == sorted(
                            [
                                {
                                    "id":
                                    github_types.GitHubAccountIdType(
                                        config.TESTING_MERGIFY_TEST_1_ID),
                                    "login":
                                    github_types.GitHubLogin("mergify-test1"),
                                },
                                {
                                    "id":
                                    github_types.GitHubAccountIdType(
                                        config.TESTING_MERGIFY_TEST_2_ID),
                                    "login":
                                    github_types.GitHubLogin("mergify-test2"),
                                },
                            ],
                            key=operator.itemgetter("id"),
                        )
                        assert len(repo["collaborators"]["active_users"]) == 2
예제 #7
0
def test_decode_enum():
    json_file = mergify_json.dumps(with_enum)
    assert mergify_json.loads(json_file) == with_enum
예제 #8
0
def test_decode() -> None:
    json_file = json.dumps(payload_encoded)
    assert mergify_json.loads(json_file) == payload_decoded