def get(self):
        """ List all Copr builds. """

        # Return relevant info thats concise
        # Usecases like the packit-dashboard copr-builds table

        result = []

        first, last = indices()
        for build in CoprBuildModel.get_merged_chroots(first, last):
            build_info = CoprBuildModel.get_by_build_id(build.build_id, None)
            project_info = build_info.get_project()
            build_dict = {
                "project": build_info.project_name,
                "build_id": build.build_id,
                "status_per_chroot": {},
                "build_submitted_time": optional_time(build_info.build_submitted_time),
                "web_url": build_info.web_url,
                "ref": build_info.commit_sha,
                "pr_id": build_info.get_pr_id(),
                "branch_name": build_info.get_branch_name(),
                "repo_namespace": project_info.namespace,
                "repo_name": project_info.repo_name,
            }

            for count, chroot in enumerate(build.target):
                # [0] because sqlalchemy returns a single element sub-list
                build_dict["status_per_chroot"][chroot[0]] = build.status[count][0]

            result.append(build_dict)

        resp = response_maker(result, status=HTTPStatus.PARTIAL_CONTENT,)
        resp.headers["Content-Range"] = f"copr-builds {first + 1}-{last}/*"
        return resp
Exemple #2
0
def test_get_merged_chroots(clean_before_and_after, too_many_copr_builds):
    # fetch 10 merged groups of builds
    builds_list = list(CoprBuildModel.get_merged_chroots(10, 20))
    assert len(builds_list) == 10
    # two merged chroots so two statuses
    assert len(builds_list[0].status) == 2
    assert len(builds_list[0].target) == 2
    assert builds_list[1].status[0][0] == "success"
    assert builds_list[2].target[0][0] == "fedora-42-x86_64"