in scripts/metric_reporter/parser/coverage_json_parser.py [0:0]
def parse(self, artifact_file_names: list[str]) -> list[CoverageJsonGroup]:
"""Parse coverage JSON data from the specified directory.
Args:
artifact_file_names (list[str]): File names of the coverage JSON files.
Returns:
list[CoverageJsonGroup]: Parsed coverage JSON files grouped by repository, workflow and
test suite.
Raises:
ParserError: If there are errors reading files, or if there are issues with parsing the
JSON data.
"""
coverage_json_groups: list[CoverageJsonGroup] = []
for artifact_file_name in artifact_file_names:
self.logger.info(f"Parsing {artifact_file_name}")
file: ArtifactFile = self._parse_artifact_file_name(artifact_file_name)
group: CoverageJsonGroup = self._get_coverage_json_group(file, coverage_json_groups)
try:
content: str = self._gcs_client.get_coverage_artifact_content(
file.repository, artifact_file_name
)
json_data: dict[str, Any] = json.loads(content)
coverage_json: CoverageJson = self._parse_json_data(file, json_data)
group.coverage_jsons.append(coverage_json)
except (JSONDecodeError, ValidationError) as error:
error_mapping: dict[type, str] = {
JSONDecodeError: f"Invalid JSON format for file {artifact_file_name}",
ValidationError: f"Unexpected value or schema in file {artifact_file_name}",
}
error_msg: str = next(m for t, m in error_mapping.items() if isinstance(error, t))
self.logger.error(error_msg, exc_info=error)
raise ParserError(error_msg) from error
return coverage_json_groups