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: add documentation to some endpoints #890

Merged
merged 3 commits into from
Feb 10, 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
91 changes: 0 additions & 91 deletions backend/kernelCI_app/serializers.py

This file was deleted.

1 change: 1 addition & 0 deletions backend/kernelCI_app/typeModels/databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
type Checkout__GitCommitTags = Optional[List[str]]
type Checkout__GitRepositoryBranch = Optional[str]
type Checkout__GitRepositoryUrl = Optional[str]
type Checkout__PatchsetHash = Optional[str]

type Build__Id = str
type Build__Architecture = Optional[str]
Expand Down
17 changes: 4 additions & 13 deletions backend/kernelCI_app/typeModels/treeCommits.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
from datetime import datetime
from typing import List
from pydantic import BaseModel, RootModel, Field
from pydantic import BaseModel, RootModel

from kernelCI_app.typeModels.commonDetails import BuildStatusCount
from kernelCI_app.typeModels.treeListing import TestStatusCount
from kernelCI_app.typeModels.databases import (
Checkout__GitCommitHash,
Checkout__GitCommitName
)


class TreeCommitsTestStatusCount(BaseModel):
fail_count: int = Field(alias="fail")
error_count: int = Field(alias="error")
miss_count: int = Field(alias="miss")
pass_count: int = Field(alias="pass")
done_count: int = Field(alias="done")
skip_count: int = Field(alias="skip")
null_count: int = Field(alias="null")


class TreeCommitsQueryParameters(BaseModel):
origin: str
git_url: str
Expand All @@ -33,8 +24,8 @@ class TreeCommitsData(BaseModel):
git_commit_name: Checkout__GitCommitName
earliest_start_time: datetime
builds: BuildStatusCount
boots: TreeCommitsTestStatusCount
tests: TreeCommitsTestStatusCount
boots: TestStatusCount
tests: TestStatusCount


class TreeCommitsResponse(RootModel):
Expand Down
23 changes: 22 additions & 1 deletion backend/kernelCI_app/typeModels/treeDetails.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,27 @@
BuildHistoryItem,
DetailsFilters,
Summary,
CommonDetailsBootsResponse,
CommonDetailsTestsResponse,
)
from kernelCI_app.typeModels.treeListing import BaseCheckouts
from pydantic import BaseModel
from kernelCI_app.constants.general import DEFAULT_ORIGIN


class TreeLatestPathParameters(BaseModel):
tree_name: str
branch: str


class TreeLatestQueryParameters(BaseModel):
origin: str = DEFAULT_ORIGIN
murilx marked this conversation as resolved.
Show resolved Hide resolved


class TreeLatestResponse(BaseCheckouts):
api_url: str


class TreeCommon(BaseModel):
hardware: Optional[List[str]]
tree_url: Optional[str]
Expand All @@ -30,6 +42,15 @@ class TreeDetailsBuildsResponse(BaseModel):


class TreeQueryParameters(BaseModel):
origin: str = "maestro"
origin: str
git_url: str
git_branch: str


class TreeDetailsFullResponse(
TreeDetailsBuildsResponse,
CommonDetailsBootsResponse,
CommonDetailsTestsResponse,
SummaryResponse
):
pass
Comment on lines +50 to +56
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this makes sense in this code (since the full endpoint must be the combination of all the other tree endpoints) but I wanna see what the others think as well

63 changes: 63 additions & 0 deletions backend/kernelCI_app/typeModels/treeListing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from typing import List
from kernelCI_app.typeModels.commonDetails import BuildStatusCount
from kernelCI_app.typeModels.databases import (
Checkout__GitCommitHash,
Checkout__GitCommitName,
Checkout__GitCommitTags,
Checkout__TreeName,
Checkout__Id,
Checkout__PatchsetHash,
Checkout__GitRepositoryBranch,
Checkout__GitRepositoryUrl,
Timestamp
)
from pydantic import BaseModel, Field, RootModel


class TestStatusCount(BaseModel):
pass_count: int = Field(alias='pass')
error_count: int = Field(alias='error')
fail_count: int = Field(alias='fail')
skip_count: int = Field(alias='skip')
miss_count: int = Field(alias='miss')
done_count: int = Field(alias='done')
null_count: int = Field(alias='null')


class BaseCheckouts(BaseModel):
git_repository_url: Checkout__GitRepositoryUrl
git_commit_hash: Checkout__GitCommitHash
git_commit_name: Checkout__GitCommitName


class CommonCheckouts(BaseCheckouts):
git_repository_branch: Checkout__GitRepositoryBranch
start_time: Timestamp


class Checkout(CommonCheckouts):
build_status: BuildStatusCount
test_status: TestStatusCount
boot_status: TestStatusCount
tree_names: List[Checkout__TreeName]
git_commit_tags: List[Checkout__GitCommitTags]


class CheckoutFast(CommonCheckouts):
id: Checkout__Id
tree_name: Checkout__TreeName
patchset_hash: Checkout__PatchsetHash
git_commit_tags: Checkout__GitCommitTags


class TreeListingResponse(RootModel):
root: List[Checkout]


class TreeListingFastResponse(RootModel):
root: List[CheckoutFast]


class TreeListingQueryParameters(BaseModel):
origin: str
intervalInDays: int
49 changes: 32 additions & 17 deletions backend/kernelCI_app/views/treeDetailsView.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from typing import List
from django.http import JsonResponse
from http import HTTPStatus
from django.views import View
from kernelCI_app.helpers.errorHandling import create_error_response
from rest_framework.views import APIView
from rest_framework.response import Response
from kernelCI_app.helpers.filters import (
FilterParams,
)
from drf_spectacular.utils import extend_schema
from pydantic import ValidationError
from kernelCI_app.helpers.errorHandling import create_api_error_response
from kernelCI_app.helpers.treeDetails import (
call_based_on_compatible_and_misc_platform,
decide_if_is_boot_filtered_out,
Expand Down Expand Up @@ -33,9 +35,13 @@
from kernelCI_app.viewCommon import create_details_build_summary

from kernelCI_app.typeModels.issues import Issue, IssueDict
from kernelCI_app.typeModels.treeDetails import (
TreeDetailsFullResponse,
TreeQueryParameters
)


class TreeDetails(View):
class TreeDetails(APIView):
def __init__(self):
self.processedTests = set()
self.filters = None
Expand Down Expand Up @@ -159,24 +165,29 @@ def _sanitize_rows(self, rows):
self.build_summary = create_details_build_summary(self.builds)
self.build_issues = convert_issues_dict_to_list(self.processed_build_issues)

@extend_schema(
responses=TreeDetailsFullResponse,
parameters=[TreeQueryParameters],
methods=["GET"]
)
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(
return create_api_error_response(
error_message="Tree not found", status_code=HTTPStatus.OK
)

self._sanitize_rows(rows)

return JsonResponse(
{
"builds": self.builds,
"boots": self.bootHistory,
"tests": self.testHistory,
"summary": {
try:
valid_response = TreeDetailsFullResponse(
builds=self.builds,
boots=self.bootHistory,
tests=self.testHistory,
summary={
"builds": {
"status": self.build_summary["builds"],
"architectures": self.build_summary["architectures"],
Expand Down Expand Up @@ -207,12 +218,12 @@ def get(self, request, commit_hash: str | None):
"failed_platforms": list(self.testPlatformsWithErrors),
},
},
"common": {
common={
"hardware": list(self.hardwareUsed),
"tree_url": self.tree_url,
"git_commit_tags": self.git_commit_tags,
},
"filters": {
filters={
"all": {
"configs": list(self.global_configs),
"architectures": list(self.global_architectures),
Expand All @@ -227,7 +238,11 @@ def get(self, request, commit_hash: str | None):
"tests": {
"issues": list(self.unfiltered_test_issues),
},
},
},
safe=False,
)
}
)
except ValidationError as e:
return create_api_error_response(
error_message=e.json(), status_code=HTTPStatus.INTERNAL_SERVER_ERROR
)

return Response(valid_response.model_dump())
Loading