Esempio n. 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
Esempio n. 2
0
    async def add_pull(
        self, ctxt: context.Context, config: queue.PullQueueConfig
    ) -> None:
        await self._remove_pull_from_other_queues(ctxt)

        async with await self.repository.installation.redis.pipeline() as pipeline:
            await pipeline.set(
                self._config_redis_queue_key(ctxt.pull["number"]),
                json.dumps(config),
            )

            score = utils.utcnow().timestamp() / config["effective_priority"]
            await pipeline.zaddoption(
                self._redis_queue_key, "NX", **{str(ctxt.pull["number"]): score}
            )
            added = (await pipeline.execute())[-1]

        if added:
            self.log.info(
                "pull request added to merge queue",
                gh_pull=ctxt.pull["number"],
                config=config,
            )

            await self._refresh_pulls(
                ctxt.pull["base"]["repo"], except_pull_request=ctxt.pull["number"]
            )
        else:
            self.log.info(
                "pull request already in merge queue",
                gh_pull=ctxt.pull["number"],
                config=config,
            )
Esempio n. 3
0
    def add_pull(self, ctxt: context.Context, config: QueueConfig) -> None:
        self._remove_pull_from_other_queues(ctxt)

        self.redis.set(
            self._config_redis_queue_key(ctxt.pull["number"]),
            json.dumps(config),
        )

        score = utils.utcnow().timestamp() / config["effective_priority"]
        added = self.redis.zadd(self._redis_queue_key,
                                {str(ctxt.pull["number"]): score},
                                nx=True)

        if added:
            self.log.info(
                "pull request added to merge queue",
                gh_pull=ctxt.pull["number"],
                config=config,
            )
            pull_requests_to_refresh = [
                p for p in self.get_pulls() if p != ctxt.pull["number"]
            ]
            self._refresh_pulls(pull_requests_to_refresh)
        else:
            self.log.info(
                "pull request already in merge queue",
                gh_pull=ctxt.pull["number"],
                config=config,
            )
Esempio n. 4
0
 async def _save(self):
     if self._waiting_pulls or self._cars:
         prepared = self.Serialized(
             waiting_pulls=self._waiting_pulls,
             current_base_sha=self._current_base_sha,
             cars=[c.serialized() for c in self._cars],
         )
         raw = json.dumps(prepared)
         await self.repository.installation.redis.set(
             self._get_redis_key(), raw)
     else:
         await self.repository.installation.redis.delete(
             self._get_redis_key())
Esempio n. 5
0
async def report(args: argparse.Namespace) -> None:
    redis_links = redis_utils.RedisLinks()
    if args.daemon:
        service.setup("count-seats")
        await count_and_send(redis_links.cache)
    else:
        service.setup("count-seats", dump_config=False)
        if config.SUBSCRIPTION_TOKEN is None:
            LOG.error("on-premise subscription token missing")
        else:
            seats = await Seats.get(redis_links.cache)
            if args.json:
                print(json.dumps(seats.jsonify()))
            else:
                seats_count = seats.count()
                LOG.info("collaborators with write_users access: %s",
                         seats_count.write_users)
                LOG.info("active_users collaborators: %s",
                         seats_count.active_users)
Esempio n. 6
0
def test_decode_enum():
    json_file = mergify_json.dumps(with_enum)
    assert mergify_json.loads(json_file) == with_enum
Esempio n. 7
0
def test_encode_enum():
    assert json.loads(mergify_json.dumps(with_enum)) == with_enum_encode
Esempio n. 8
0
def test_encode() -> None:
    assert json.loads(mergify_json.dumps(payload_decoded)) == payload_encoded