Skip to content

Commit

Permalink
refactor: reuse Issue class
Browse files Browse the repository at this point in the history
  • Loading branch information
MarceloRobert committed Jan 23, 2025
1 parent ee215ce commit 4ad4d34
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 60 deletions.
2 changes: 1 addition & 1 deletion backend/kernelCI_app/helpers/hardwareDetails.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def update_issues(
issue_report_url: Optional[str],
task: Dict,
is_failed_task: bool,
issue_from: str,
issue_from: Literal["build", "test"],
) -> None:
can_insert_issue = True
if issue_from == "build":
Expand Down
23 changes: 3 additions & 20 deletions backend/kernelCI_app/typeModels/commonDetails.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime
from typing import Dict, List, Optional, Union

from kernelCI_app.typeModels.issues import Issue
from pydantic import BaseModel


Expand Down Expand Up @@ -30,24 +31,6 @@ class BuildConfigs(BuildStatusCount):
null: int


class IncidentsInfo(BaseModel):
incidentsCount: int


class TestIssuesItem(BaseModel):
id: str
comment: Optional[str]
report_url: Optional[str]
incidents_info: IncidentsInfo


class BuildsIssuesItem(BaseModel):
id: str
comment: Optional[str]
report_url: Optional[str]
incidents_info: IncidentsInfo


class BuildArchitectures(BuildStatusCount):
compilers: List[str]

Expand Down Expand Up @@ -89,7 +72,7 @@ class TestSummary(BaseModel):
status: TestStatusCount
architectures: List[TestArchSummaryItem]
configs: Dict[str, TestStatusCount]
issues: List[TestIssuesItem]
issues: List[Issue]
unknown_issues: int
fail_reasons: Dict[str, int]
failed_platforms: List[str]
Expand All @@ -102,7 +85,7 @@ class BuildSummary(BaseModel):
status: BuildStatusCount
architectures: Dict[str, BuildArchitectures]
configs: Dict[str, BuildConfigs]
issues: List[BuildsIssuesItem]
issues: List[Issue]
unknown_issues: int


Expand Down
11 changes: 0 additions & 11 deletions backend/kernelCI_app/typeModels/issueDetails.py

This file was deleted.

22 changes: 22 additions & 0 deletions backend/kernelCI_app/typeModels/issues.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from typing import Dict, Optional, Tuple
from pydantic import BaseModel


class IssueDetailsPathParameters(BaseModel):
issue_id: str
version: int


class IncidentInfo(BaseModel):
incidentsCount: int


class Issue(BaseModel):
id: str
version: int
comment: Optional[str]
report_url: Optional[str]
incidents_info: IncidentInfo


type IssueDict = Dict[Tuple[str, str], Issue]
17 changes: 3 additions & 14 deletions backend/kernelCI_app/utils.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
import json
from typing import Union, TypedDict, List, Optional, Dict
from typing import Union, List, Optional, Dict
from django.utils import timezone
from datetime import timedelta

from kernelCI_app.helpers.logger import log_message
from kernelCI_app.typeModels.issues import Issue

DEFAULT_QUERY_TIME_INTERVAL = {"days": 7}


class IncidentInfo(TypedDict):
incidentsCount: int


class Issue(TypedDict):
id: str
version: str
comment: Optional[str]
report_url: Optional[str]
incidents_info: IncidentInfo


def create_issue(
*,
issue_id: str,
issue_version: str,
issue_version: int,
issue_comment: Optional[str],
issue_report_url: Optional[str]
) -> Issue:
Expand Down
2 changes: 1 addition & 1 deletion backend/kernelCI_app/views/issueDetailsBuildsView.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.views import View
from kernelCI_app.helpers.errorHandling import create_error_response
from kernelCI_app.models import Incidents
from kernelCI_app.typeModels.issueDetails import IssueDetailsPathParameters
from kernelCI_app.typeModels.issues import IssueDetailsPathParameters
from pydantic import ValidationError


Expand Down
2 changes: 1 addition & 1 deletion backend/kernelCI_app/views/issueDetailsTestsView.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.views import View
from kernelCI_app.helpers.errorHandling import create_error_response
from kernelCI_app.models import Incidents
from kernelCI_app.typeModels.issueDetails import IssueDetailsPathParameters
from kernelCI_app.typeModels.issues import IssueDetailsPathParameters
from pydantic import ValidationError


Expand Down
6 changes: 4 additions & 2 deletions backend/kernelCI_app/views/issueDetailsView.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.views import View
from kernelCI_app.helpers.errorHandling import create_error_response
from kernelCI_app.models import Issues
from kernelCI_app.typeModels.issueDetails import IssueDetailsPathParameters
from kernelCI_app.typeModels.issues import IssueDetailsPathParameters
from pydantic import ValidationError


Expand Down Expand Up @@ -34,7 +34,9 @@ def _fetch_issue(self, *, issue_id: str, version: int) -> Optional[Dict]:

return query

def get(self, _request, issue_id: Optional[str], version: Optional[str]) -> JsonResponse:
def get(
self, _request, issue_id: Optional[str], version: Optional[str]
) -> JsonResponse:
try:
parsed_params = IssueDetailsPathParameters(
issue_id=issue_id, version=version
Expand Down
3 changes: 1 addition & 2 deletions backend/kernelCI_app/views/issuesView.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@

from kernelCI_app.helpers.errorHandling import create_error_response
from kernelCI_app.utils import (
Issue,
convert_issues_dict_to_list,
create_issue,
)
from http import HTTPStatus
from kernelCI_app.typeModels.issueDetails import IssueDict
from kernelCI_app.typeModels.issues import Issue, IssueDict


class IssueView(View):
Expand Down
4 changes: 1 addition & 3 deletions backend/kernelCI_app/views/treeDetailsBootsView.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from http import HTTPStatus

from drf_spectacular.utils import extend_schema
from kernelCI_app.typeModels.issues import Issue
from pydantic import ValidationError
from kernelCI_app.helpers.errorHandling import create_error_response
from kernelCI_app.helpers.filters import (
Expand All @@ -23,9 +24,6 @@
from kernelCI_app.typeModels.commonDetails import (
TestHistoryItem
)
from kernelCI_app.utils import (
Issue,
)


type IssueDict = Dict[Tuple[str, str], Issue]
Expand Down
4 changes: 1 addition & 3 deletions backend/kernelCI_app/views/treeDetailsTestsView.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Dict, Tuple
from drf_spectacular.utils import extend_schema
from kernelCI_app.typeModels.issues import Issue
from pydantic import ValidationError
from rest_framework.response import Response
from rest_framework.views import APIView
Expand All @@ -22,9 +23,6 @@
from kernelCI_app.typeModels.commonDetails import (
TestHistoryItem
)
from kernelCI_app.utils import (
Issue,
)


type IssueDict = Dict[Tuple[str, str], Issue]
Expand Down
3 changes: 1 addition & 2 deletions backend/kernelCI_app/views/treeDetailsView.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@
process_filters,
)
from kernelCI_app.utils import (
Issue,
convert_issues_dict_to_list,
)

from collections import defaultdict

from kernelCI_app.viewCommon import create_details_build_summary

from kernelCI_app.typeModels.issueDetails import IssueDict
from kernelCI_app.typeModels.issues import Issue, IssueDict


class TreeDetails(View):
Expand Down

0 comments on commit 4ad4d34

Please sign in to comment.