-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(views): add tree details endpoints
Added new endpoints to fetch tree details: - TreeDetailsBootsView - TreeDetailsBuildsView - TreeDetailsTestsView Updated `urls.py` to include the new endpoints for boots, builds, and tests. These endpoints process and return the respective data for a given tree commit hash. Part of #720 #721 #722
- Loading branch information
Showing
5 changed files
with
268 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
from typing import Dict, Tuple | ||
from http import HTTPStatus | ||
|
||
from drf_spectacular.utils import extend_schema | ||
from pydantic import ValidationError | ||
from kernelCI_app.helpers.errorHandling import create_error_response | ||
from kernelCI_app.helpers.filters import ( | ||
FilterParams, | ||
) | ||
from rest_framework.views import APIView | ||
from rest_framework.response import Response | ||
from kernelCI_app.helpers.treeDetails import ( | ||
decide_if_is_boot_filtered_out, | ||
decide_if_is_full_row_filtered_out, | ||
get_current_row_data, | ||
get_tree_details_data, | ||
is_test_boots_test, | ||
) | ||
from kernelCI_app.typeModels.treeDetails import BootResponse, TestHistory | ||
from kernelCI_app.utils import ( | ||
Issue, | ||
) | ||
|
||
|
||
type IssueDict = Dict[Tuple[str, str], Issue] | ||
|
||
|
||
class TreeDetailsBoots(APIView): | ||
def __init__(self): | ||
self.processedTests = set() | ||
self.filters = None | ||
self.bootHistory = [] | ||
|
||
def _process_boots_test(self, row_data): | ||
test_id = row_data["test_id"] | ||
history_item = row_data["history_item"] | ||
|
||
if decide_if_is_boot_filtered_out(self, row_data): | ||
return | ||
|
||
if test_id in self.processedTests: | ||
return | ||
self.processedTests.add(test_id) | ||
TestHistory(**history_item) | ||
self.bootHistory.append(history_item) | ||
|
||
def _sanitize_rows(self, rows): | ||
for row in rows: | ||
row_data = get_current_row_data(row) | ||
|
||
is_record_filter_out = decide_if_is_full_row_filtered_out(self, row_data) | ||
|
||
if is_record_filter_out: | ||
continue | ||
|
||
if row_data["test_id"] is None: | ||
continue | ||
|
||
if is_test_boots_test(row_data): | ||
self._process_boots_test(row_data) | ||
|
||
@extend_schema( | ||
responses=BootResponse, | ||
) | ||
def get(self, request, commit_hash: str | None): | ||
rows = get_tree_details_data(request, commit_hash) | ||
|
||
self.filters = FilterParams(request) | ||
|
||
if len(rows) == 0: | ||
return create_error_response( | ||
error_message="Tree not found", status_code=HTTPStatus.NOT_FOUND | ||
) | ||
|
||
try: | ||
self._sanitize_rows(rows) | ||
except ValidationError as e: | ||
return Response(data=e.errors(), status=HTTPStatus.BAD_REQUEST) | ||
|
||
return Response( | ||
{ | ||
"bootHistory": self.bootHistory, | ||
} | ||
) |
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,80 @@ | ||
from http import HTTPStatus | ||
from drf_spectacular.utils import extend_schema | ||
from pydantic import ValidationError | ||
from rest_framework.response import Response | ||
from rest_framework.views import APIView | ||
from kernelCI_app.helpers.errorHandling import create_error_response | ||
from kernelCI_app.helpers.filters import ( | ||
FilterParams, | ||
) | ||
from kernelCI_app.helpers.treeDetails import ( | ||
decide_if_is_build_filtered_out, | ||
decide_if_is_full_row_filtered_out, | ||
get_build, | ||
get_current_row_data, | ||
get_tree_details_data, | ||
) | ||
from kernelCI_app.typeModels.treeDetails import BuildItem, BuildsResponse | ||
|
||
|
||
class TreeDetailsBuilds(APIView): | ||
def __init__(self): | ||
self.processedTests = set() | ||
self.filters = None | ||
|
||
self.builds = [] | ||
self.processed_builds = set() | ||
self.tree_url = "" | ||
|
||
def _process_builds(self, row_data): | ||
build_id = row_data["build_id"] | ||
|
||
if decide_if_is_build_filtered_out(self, row_data): | ||
return | ||
|
||
if build_id in self.processed_builds: | ||
return | ||
|
||
self.processed_builds.add(build_id) | ||
|
||
build_item = get_build(row_data) | ||
|
||
BuildItem(**build_item) | ||
|
||
self.builds.append(build_item) | ||
|
||
def _sanitize_rows(self, rows): | ||
for row in rows: | ||
row_data = get_current_row_data(row) | ||
|
||
is_record_filter_out = decide_if_is_full_row_filtered_out(self, row_data) | ||
|
||
if is_record_filter_out: | ||
continue | ||
|
||
if row_data["build_id"] is not None: | ||
self._process_builds(row_data) | ||
|
||
@extend_schema( | ||
responses=BuildsResponse, | ||
) | ||
def get(self, request, commit_hash: str | None): | ||
rows = get_tree_details_data(request, commit_hash) | ||
|
||
self.filters = FilterParams(request) | ||
|
||
if len(rows) == 0: | ||
return create_error_response( | ||
error_message="Tree not found", status_code=HTTPStatus.NOT_FOUND | ||
) | ||
|
||
try: | ||
self._sanitize_rows(rows) | ||
except ValidationError as e: | ||
return Response(data=e.errors(), status=HTTPStatus.BAD_REQUEST) | ||
|
||
return Response( | ||
{ | ||
"builds": self.builds, | ||
} | ||
) |
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,89 @@ | ||
from typing import Dict, Tuple | ||
from drf_spectacular.utils import extend_schema | ||
from pydantic import ValidationError | ||
from rest_framework.response import Response | ||
from rest_framework.views import APIView | ||
from http import HTTPStatus | ||
from kernelCI_app.helpers.errorHandling import create_error_response | ||
from kernelCI_app.helpers.filters import ( | ||
FilterParams, | ||
) | ||
from kernelCI_app.helpers.treeDetails import ( | ||
decide_if_is_full_row_filtered_out, | ||
decide_if_is_test_filtered_out, | ||
get_current_row_data, | ||
get_tree_details_data, | ||
is_test_boots_test, | ||
) | ||
from kernelCI_app.typeModels.treeDetails import TestHistory, TestResponse | ||
from kernelCI_app.utils import ( | ||
Issue, | ||
) | ||
|
||
|
||
type IssueDict = Dict[Tuple[str, str], Issue] | ||
|
||
|
||
class TreeDetailsTests(APIView): | ||
def __init__(self): | ||
self.processedTests = set() | ||
self.filters = None | ||
|
||
self.testHistory = [] | ||
|
||
def _process_non_boots_test(self, row_data): | ||
test_id = row_data["test_id"] | ||
history_item = row_data["history_item"] | ||
|
||
if decide_if_is_test_filtered_out(self, row_data): | ||
return | ||
|
||
if test_id in self.processedTests: | ||
return | ||
|
||
self.processedTests.add(test_id) | ||
|
||
TestHistory(**history_item) | ||
|
||
self.testHistory.append(history_item) | ||
|
||
def _sanitize_rows(self, rows): | ||
for row in rows: | ||
row_data = get_current_row_data(row) | ||
|
||
is_record_filter_out = decide_if_is_full_row_filtered_out(self, row_data) | ||
|
||
if is_record_filter_out: | ||
continue | ||
|
||
if row_data["test_id"] is None: | ||
continue | ||
|
||
if is_test_boots_test(row_data): | ||
continue | ||
else: | ||
self._process_non_boots_test(row_data) | ||
|
||
@extend_schema( | ||
responses=TestResponse, | ||
) | ||
def get(self, request, commit_hash: str | None): | ||
rows = get_tree_details_data(request, commit_hash) | ||
|
||
self.filters = FilterParams(request) | ||
|
||
if len(rows) == 0: | ||
return create_error_response( | ||
error_message="Tree not found", status_code=HTTPStatus.NOT_FOUND | ||
) | ||
|
||
try: | ||
self._sanitize_rows(rows) | ||
except ValidationError as e: | ||
return Response(data=e.errors()) | ||
|
||
return Response( | ||
{ | ||
"testHistory": self.testHistory, | ||
} | ||
) |