forked from packit/packit-service
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
148 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Copyright Contributors to the Packit project. | ||
# SPDX-License-Identifier: MIT | ||
|
||
from http import HTTPStatus | ||
from logging import getLogger | ||
|
||
from flask_restx import Namespace, Resource | ||
|
||
from packit_service.models import ( | ||
OSHScanModel, | ||
optional_timestamp, | ||
) | ||
from packit_service.service.api.parsers import indices, pagination_arguments | ||
from packit_service.service.api.utils import get_project_info_from_build, response_maker | ||
|
||
logger = getLogger("packit_service") | ||
|
||
ns = Namespace("osh-scans", description="OpenScanHub scans") | ||
|
||
|
||
@ns.route("") | ||
class ScansList(Resource): | ||
@ns.expect(pagination_arguments) | ||
@ns.response(HTTPStatus.PARTIAL_CONTENT.value, "Scans list follows") | ||
def get(self): | ||
"""List all scans.""" | ||
|
||
first, last = indices() | ||
result = [] | ||
|
||
for scan in OSHScanModel.get_range(first, last): | ||
update_dict = { | ||
"packit_id": scan.id, | ||
"task_id": scan.task_id, | ||
"status": scan.status, | ||
"url": scan.url, | ||
"issues_added_url": scan.issues_added_url, | ||
"issues_fixed_url": scan.issues_fixed_url, | ||
"scan_results_url": scan.scan_results_url, | ||
"copr_build_target_id": scan.copr_build_target_id, | ||
"submitted_time": optional_timestamp(scan.submitted_time), | ||
} | ||
|
||
if project := scan.copr_build_target.get_project(): | ||
update_dict["project_url"] = project.project_url | ||
update_dict["repo_namespace"] = project.namespace | ||
update_dict["repo_name"] = project.repo_name | ||
|
||
result.append(update_dict) | ||
|
||
resp = response_maker( | ||
result, | ||
status=HTTPStatus.PARTIAL_CONTENT, | ||
) | ||
resp.headers["Content-Range"] = f"osh-scans {first + 1}-{last}/*" | ||
return resp | ||
|
||
|
||
@ns.route("/<int:id>") | ||
@ns.param("id", "Packit id of the scan") | ||
class ScanItem(Resource): | ||
@ns.response(HTTPStatus.OK.value, "OK, scan details follow") | ||
@ns.response(HTTPStatus.NOT_FOUND.value, "Scan identifier not in db/hash") | ||
def get(self, id): | ||
"""A specific copr build details for one chroot.""" | ||
scan = OSHScanModel.get_by_id(int(id)) | ||
if not scan: | ||
return response_maker( | ||
{"error": "No info about scan stored in DB"}, | ||
status=HTTPStatus.NOT_FOUND, | ||
) | ||
|
||
scan_dict = { | ||
"task_id": scan.task_id, | ||
"status": scan.status, | ||
"url": scan.url, | ||
"issues_added_url": scan.issues_added_url, | ||
"issues_fixed_url": scan.issues_fixed_url, | ||
"scan_results_url": scan.scan_results_url, | ||
"copr_build_target_id": scan.copr_build_target_id, | ||
"submitted_time": optional_timestamp(scan.submitted_time), | ||
} | ||
|
||
scan_dict.update(get_project_info_from_build(scan.copr_build_target)) | ||
return response_maker(scan_dict) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters