Exemple #1
0
    async def get_config(
        self, pull_number: github_types.GitHubPullRequestNumber
    ) -> queue.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 = 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.QueueConfig({
                "strict_method": "merge",
                "priority": 2000,
                "effective_priority": 2000,
                "bot_account": None,
                "update_bot_account": None,
                "name": rules.QueueName(""),
            })
        config: queue.QueueConfig = json.loads(config_str)
        return config
Exemple #2
0
async def test_train_add_remove_pull_idempotant(repository, monkepatched_traincar):
    t = merge_train.Train(repository, "branch")
    await t.load()

    config = queue.QueueConfig(
        name="foo",
        strict_method="merge",
        priority=0,
        effective_priority=0,
        bot_account=None,
        update_bot_account=None,
    )

    await t.add_pull(await fake_context(repository, 1), config)
    await t.add_pull(await fake_context(repository, 2), config)
    await t.add_pull(await fake_context(repository, 3), config)
    await t.refresh()
    assert [[1], [1, 2], [1, 2, 3]] == get_cars_content(t)

    config = queue.QueueConfig(
        name="foo",
        strict_method="merge",
        priority=10,
        effective_priority=10,
        bot_account=None,
        update_bot_account=None,
    )
    await t.add_pull(await fake_context(repository, 1), config)
    await t.refresh()
    assert [[1], [1, 2], [1, 2, 3]] == get_cars_content(t)

    t = merge_train.Train(repository, "branch")
    await t.load()
    assert [[1], [1, 2], [1, 2, 3]] == get_cars_content(t)

    await t.remove_pull(await fake_context(repository, 2))
    await t.refresh()
    assert [[1], [1, 3]] == get_cars_content(t)

    await t.remove_pull(await fake_context(repository, 2))
    await t.refresh()
    assert [[1], [1, 3]] == get_cars_content(t)

    t = merge_train.Train(repository, "branch")
    await t.load()
    assert [[1], [1, 3]] == get_cars_content(t)
Exemple #3
0
    async def test_create_pull_conflicts(self):
        await self.setup_repo(yaml.dump({}), files={"conflicts": "foobar"})

        p, _ = await self.create_pr(files={"conflicts": "well"})
        p1, _ = await self.create_pr()
        p2, _ = await self.create_pr()
        p3, _ = await self.create_pr(files={"conflicts": "boom"})

        p.merge()
        await self.wait_for("pull_request", {"action": "closed"})

        ctxt = context.Context(self.repository_ctxt, p.raw_data)
        q = await merge_train.Train.from_context(ctxt)
        head_sha = await q.get_head_sha()

        config = queue.QueueConfig(
            name="foo",
            strict_method="merge",
            priority=0,
            effective_priority=0,
            bot_account=None,
            update_bot_account=None,
        )

        car = merge_train.TrainCar(
            q,
            p3.number,
            [p1.number, p2.number],
            config,
            head_sha,
            head_sha,
        )
        with pytest.raises(merge_train.TrainCarPullRequestCreationFailure) as exc_info:
            await car.create_pull()
            assert exc_info.value.car == car
            assert car.queue_pull_request_number is None

        p3.update()
        ctxt_p3 = context.Context(self.repository_ctxt, p3.raw_data)
        check = first(
            await ctxt_p3.pull_engine_check_runs,
            key=lambda c: c["name"] == constants.MERGE_QUEUE_SUMMARY_NAME,
        )
        assert (
            check["output"]["title"] == "This pull request cannot be embarked for merge"
        )
        assert (
            check["output"]["summary"]
            == "The merge-queue pull request can't be created\nDetails: `Merge conflict`"
        )
Exemple #4
0
    async def test_create_pull_basic(self):
        await self.setup_repo(yaml.dump({}))

        p1, _ = await self.create_pr()
        p2, _ = await self.create_pr()

        ctxt = context.Context(self.repository_ctxt, p1.raw_data)
        q = await merge_train.Train.from_context(ctxt)
        head_sha = await q.get_head_sha()

        config = queue.QueueConfig(
            name="foo",
            strict_method="merge",
            priority=0,
            effective_priority=0,
            bot_account=None,
            update_bot_account=None,
        )

        car = merge_train.TrainCar(
            q,
            p2.number,
            [p1.number],
            config,
            head_sha,
            head_sha,
        )
        await car.create_pull()
        assert car.queue_pull_request_number is not None
        pulls = list(self.r_o_admin.get_pulls())
        assert len(pulls) == 3

        await car.delete_pull()

        # NOTE(sileht): When branch is deleted the associated Pull is deleted in an async
        # fashion on GitHub side.
        time.sleep(1)
        pulls = list(self.r_o_admin.get_pulls())
        assert len(pulls) == 2