Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): add hardware commit history docs #891

Merged
merged 2 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion backend/kernelCI_app/typeModels/hardwareDetails.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
StatusValues,
Checkout__TreeName,
Checkout__GitRepositoryBranch,
Issue__Version
Issue__Version,
)
from pydantic import BaseModel, BeforeValidator, Field

Expand Down Expand Up @@ -127,4 +127,50 @@ class HardwareDetailsTestsResponse(BaseModel):
tests: List[HardwareTestHistoryItem]


class HardwareCommitHistoryResponse(BaseModel):
commit_history_table: Dict[str, List[CommitHistoryValidCheckout]]
Francisco2002 marked this conversation as resolved.
Show resolved Hide resolved

class Config:
# TODO: Implement this modification (additionalProp{n} -> commit_hash_{n}) dynamically
json_schema_extra = {
"example": {
"commit_history_table": {
"commit_hash_1": [
{
"git_commit_hash": "string",
"tree_name": "string",
"git_repository_branch": "string",
"git_repository_url": "string",
"git_commit_tags": ["string"],
"git_commit_name": "string",
"start_time": "datetime",
}
],
"commit_hash_2": [
{
"git_commit_hash": "string",
"tree_name": "string",
"git_repository_branch": "string",
"git_repository_url": "string",
"git_commit_tags": ["string"],
"git_commit_name": "string",
"start_time": "datetime",
}
],
"commit_hash_3": [
{
"git_commit_hash": "string",
"tree_name": "string",
"git_repository_branch": "string",
"git_repository_url": "string",
"git_commit_tags": ["string"],
"git_commit_name": "string",
"start_time": "datetime",
}
],
}
}
}


PossibleTestType = Literal["test", "boot"]
38 changes: 19 additions & 19 deletions backend/kernelCI_app/typeModels/issueDetails.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,33 @@ class IssueDetailsPathParameters(BaseModel):


class IssueBuildItem(BaseModel):
id: Build__Id = Field(alias="build__id")
architecture: Build__Architecture = Field(alias="build__architecture")
config_name: Build__ConfigName = Field(alias="build__config_name")
valid: Build__Valid = Field(alias="build__valid")
start_time: Build__StartTime = Field(alias="build__start_time")
duration: Build__Duration = Field(alias="build__duration")
compiler: Build__Compiler = Field(alias="build__compiler")
log_url: Build__LogUrl = Field(alias="build__log_url")
tree_name: Checkout__TreeName = Field(alias="build__checkout__tree_name")
id: Build__Id = Field(validation_alias="build__id")
architecture: Build__Architecture = Field(validation_alias="build__architecture")
config_name: Build__ConfigName = Field(validation_alias="build__config_name")
valid: Build__Valid = Field(validation_alias="build__valid")
start_time: Build__StartTime = Field(validation_alias="build__start_time")
duration: Build__Duration = Field(validation_alias="build__duration")
compiler: Build__Compiler = Field(validation_alias="build__compiler")
log_url: Build__LogUrl = Field(validation_alias="build__log_url")
tree_name: Checkout__TreeName = Field(validation_alias="build__checkout__tree_name")
git_repository_branch: Checkout__GitRepositoryBranch = Field(
alias="build__checkout__git_repository_branch"
validation_alias="build__checkout__git_repository_branch"
)


class IssueTestItem(BaseModel):
id: Test__Id = Field(alias="test__id")
status: Test__Status = Field(alias="test__status")
duration: Test__Duration = Field(alias="test__duration")
path: Test__Path = Field(alias="test__path")
start_time: Test__StartTime = Field(alias="test__start_time")
id: Test__Id = Field(validation_alias="test__id")
status: Test__Status = Field(validation_alias="test__status")
duration: Test__Duration = Field(validation_alias="test__duration")
path: Test__Path = Field(validation_alias="test__path")
start_time: Test__StartTime = Field(validation_alias="test__start_time")
environment_compatible: Test__EnvironmentCompatible = Field(
alias="test__environment_compatible"
validation_alias="test__environment_compatible"
)
environment_misc: Test__EnvironmentMisc = Field(alias="test__environment_misc")
tree_name: Checkout__TreeName = Field(alias="test__build__checkout__tree_name")
environment_misc: Test__EnvironmentMisc = Field(validation_alias="test__environment_misc")
tree_name: Checkout__TreeName = Field(validation_alias="test__build__checkout__tree_name")
git_repository_branch: Checkout__GitRepositoryBranch = Field(
alias="test__build__checkout__git_repository_branch"
validation_alias="test__build__checkout__git_repository_branch"
)


Expand Down
2 changes: 1 addition & 1 deletion backend/kernelCI_app/typeModels/treeDetails.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ class TreeDetailsBuildsResponse(BaseModel):


class TreeQueryParameters(BaseModel):
origin: str = "maestro"
origin: str
git_url: str
git_branch: str
38 changes: 26 additions & 12 deletions backend/kernelCI_app/views/hardwareDetailsCommitHistoryView.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@
from django.db import connection
import json
from typing import Dict, List, TypedDict
from kernelCI_app.helpers.errorHandling import create_error_response
from kernelCI_app.helpers.errorHandling import create_api_error_response
from kernelCI_app.helpers.logger import log_message
from django.utils.decorators import method_decorator
from django.views import View
from datetime import datetime, timezone
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from kernelCI_app.helpers.trees import make_tree_identifier_key
from kernelCI_app.typeModels.hardwareDetails import (
CommitHead,
CommitHistoryPostBody,
CommitHistoryValidCheckout,
HardwareCommitHistoryResponse,
)
from pydantic import ValidationError
from http import HTTPStatus
from rest_framework.views import APIView
from rest_framework.response import Response
from drf_spectacular.utils import extend_schema


class GenerateQueryParamsResponse(TypedDict):
Expand Down Expand Up @@ -58,7 +60,7 @@ def generate_query_params(
# also the csrf protection require the usage of cookies which is not currently
# supported in this project
@method_decorator(csrf_exempt, name="dispatch")
class HardwareDetailsCommitHistoryView(View):
class HardwareDetailsCommitHistoryView(APIView):
required_params_get = ["origin"]
cache_key_get_tree_data = "hardwareDetailsTreeData"
cache_key_get_full_data = "hardwareDetailsFullData"
Expand Down Expand Up @@ -178,7 +180,12 @@ def get_commit_history(
return formatted_checkouts

# Using post to receive a body request
def post(self, request, hardware_id) -> JsonResponse:
@extend_schema(
responses=HardwareCommitHistoryResponse,
request=CommitHistoryPostBody,
methods=["POST"],
)
def post(self, request, hardware_id) -> Response:
try:
body = json.loads(request.body)

Expand All @@ -196,14 +203,14 @@ def post(self, request, hardware_id) -> JsonResponse:
commit_heads = post_body.commitHeads

except ValidationError as e:
return create_error_response(e.json())
return Response(data=e.json(), status=HTTPStatus.BAD_REQUEST)
except json.JSONDecodeError:
return create_error_response(
"Invalid body, request body must be a valid json string"
return create_api_error_response(
error_message="Invalid body, request body must be a valid json string"
)
except (ValueError, TypeError):
return create_error_response(
"startTimestampInSeconds and endTimestampInSeconds must be a Unix Timestamp"
return create_api_error_response(
error_message="startTimestampInSeconds and endTimestampInSeconds must be a Unix Timestamp"
)

commit_history = self.get_commit_history(
Expand All @@ -214,8 +221,15 @@ def post(self, request, hardware_id) -> JsonResponse:
)

if not commit_history:
return create_error_response(
return create_api_error_response(
error_message="Commit history not found", status_code=HTTPStatus.OK
)

return JsonResponse({"commit_history_table": commit_history}, safe=False)
try:
valid_response = HardwareCommitHistoryResponse(
commit_history_table=commit_history
)
except ValidationError as e:
return Response(data=e.json(), status=HTTPStatus.INTERNAL_SERVER_ERROR)

return Response(valid_response.model_dump())
4 changes: 3 additions & 1 deletion backend/kernelCI_app/views/treeDetailsSummaryView.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
process_tests_issue,
process_filters,
)
from kernelCI_app.typeModels.treeDetails import SummaryResponse
from kernelCI_app.typeModels.treeDetails import SummaryResponse, TreeQueryParameters
from kernelCI_app.utils import (
convert_issues_dict_to_list,
)
Expand Down Expand Up @@ -153,6 +153,8 @@ def _sanitize_rows(self, rows):

@extend_schema(
responses=SummaryResponse,
parameters=[TreeQueryParameters],
methods=["GET"],
)
def get(self, request, commit_hash: str | None):
rows = get_tree_details_data(request, commit_hash)
Expand Down
4 changes: 2 additions & 2 deletions backend/requests/issue-details-tests-get.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This will get the tests from the issue with the latest version, for a specific version pass ?version=n (n being an integer)
http 'http://localhost:8000/api/issue/maestro:0820fe153b255bf52750bbf1fecb198d8772f5a9/tests'

HTTP/1.1 200 OK
# HTTP/1.1 200 OK
# Allow: GET, HEAD, OPTIONS
# Cache-Control: max-age=0
# Content-Length: 1589
Expand Down Expand Up @@ -92,4 +92,4 @@ HTTP/1.1 200 OK
# "status": "FAIL",
# "tree_name": "net-next"
# }
# ]
# ]
Loading