Skip to content

Commit

Permalink
Add DomainSpecificInfo to Result
Browse files Browse the repository at this point in the history
Signed-off-by: patrickpa <[email protected]>
  • Loading branch information
patrickpa committed Jun 11, 2024
1 parent 75db6fc commit 0765454
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
24 changes: 20 additions & 4 deletions qc_baselib/models/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
# with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
import enum

from typing import List, Any, Set, Dict

from typing import List, Any, Set
from pydantic import model_validator
from pydantic_xml import BaseXmlModel, attr, element
from pydantic_xml import BaseXmlModel, attr, element, computed_element
from lxml import etree

from .common import ParamType, IssueSeverity

Expand Down Expand Up @@ -148,7 +150,18 @@ def check_any_empty(self) -> Any:
return self


class IssueType(BaseXmlModel, tag="Issue"):
class DomainSpecificInfoType(
BaseXmlModel,
tag="DomainSpecificInfo",
):
name: str = attr(name="name")


class IssueType(
BaseXmlModel,
tag="Issue",
arbitrary_types_allowed=True,
):
locations: List[LocationType] = []
issue_id: int = attr(name="issueId")
description: str = attr(name="description")
Expand All @@ -158,6 +171,9 @@ class IssueType(BaseXmlModel, tag="Issue"):
default="",
pattern=r"^((\w+(\.\w+)+)):(([a-z]+)):(([0-9]+(\.[0-9]+)+)):((([a-z][\w_]*)\.)*)([a-z][\w_]*)$",
)
domain_specific_info_raw: etree._Element = element(
tag="DomainSpecificInfo", default=None, excluded=True
)


class MetadataType(BaseXmlModel, tag="Metadata"):
Expand All @@ -176,7 +192,7 @@ class CheckerType(BaseXmlModel, tag="Checker", validate_assignment=True):
addressed_rule: List[RuleType] = []
issues: List[IssueType] = []
metadata: List[MetadataType] = []
status: StatusType = attr(name="status", default="")
status: StatusType = attr(name="status", default=None)
checker_id: str = attr(name="checkerId")
description: str = attr(name="description")
summary: str = attr(name="summary")
Expand Down
32 changes: 32 additions & 0 deletions qc_baselib/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

from typing import Union, List, Dict, Any
from lxml import etree
from .models import IssueSeverity, result

REPORT_OUTPUT_FORMAT = "xqar"
Expand Down Expand Up @@ -87,6 +88,7 @@ def write_to_file(self, xml_output_file_path: str) -> None:
xml_declaration=True,
standalone=False,
encoding="UTF-8",
skip_empty=True,
)
report_xml_file.write(xml_text)

Expand Down Expand Up @@ -286,6 +288,24 @@ def add_xml_location(
result.LocationType(xml_location=[xml_location], description=description)
)

def add_domain_specific_info(
self,
checker_bundle_name: str,
checker_id: str,
issue_id: int,
domain_specific_info_name: str,
xml_info: etree._Element,
) -> None:
bundle = self._get_checker_bundle(checker_bundle_name=checker_bundle_name)

checker = self._get_checker(bundle=bundle, checker_id=checker_id)
issue = self._get_issue(checker=checker, issue_id=issue_id)
domain_specific_tag = etree.Element(
"DomainSpecificInfo", attrib={"name": domain_specific_info_name}
)
domain_specific_tag.append(xml_info)
issue.domain_specific_info_raw = domain_specific_tag

def set_checker_status(
self, checker_bundle_name: str, checker_id: str, status: result.StatusType
) -> None:
Expand Down Expand Up @@ -379,3 +399,15 @@ def get_issue_count(self) -> int:
)

return issue_count

def get_domain_specific_info(
self,
checker_bundle_name: str,
checker_id: str,
issue_id: int,
) -> etree._Element:
bundle = self._get_checker_bundle(checker_bundle_name=checker_bundle_name)
checker = self._get_checker(bundle=bundle, checker_id=checker_id)
issue = self._get_issue(checker=checker, issue_id=issue_id)

return issue.domain_specific_info_raw[0]

0 comments on commit 0765454

Please sign in to comment.