async def _parse_entities(self, responses: SourceResponses) -> Entities: """Override to parse the cards.""" api_url = await self._api_url() board_slug = self._board["slug"] entities = Entities() for lst in self._lists: for card in self._cards.get(lst["_id"], []): entities.append( self.__card_to_entity(card, api_url, board_slug, lst["title"])) return entities
async def _parse_entities(self, responses: SourceResponses) -> Entities: """Override to parse the jobs/pipelines.""" entities = Entities() for job in (await responses[0].json())["value"]: if not self._include_job(job): continue name = self.__job_name(job) url = job["_links"]["web"]["href"] build_status = self._latest_build_result(job) build_date_time = self._latest_build_date_time(job) entities.append( Entity(key=name, name=name, url=url, build_date=str(build_date_time.date()), build_status=build_status) ) return entities
def __violations(self, tree: Element, namespaces: Namespaces, severities: list[str]) -> Entities: """Return the violations.""" models = self.__model_file_paths(tree, namespaces) violation_elements = tree.findall(".//ns:violation", namespaces) violations = Entities() for element in violation_elements: violation = self.__violation(element, namespaces, models, severities) if violation is not None: violations.append(violation) # Add the duplication counts for violation in violations: violation["count"] = str(self.violation_counts[str( violation["key"])]) return violations
async def _parse_entities(self, responses: SourceResponses) -> Entities: """Override to parse the security warnings from the JSON.""" entities = Entities() for response in responses: json = await response.json(content_type=None) vulnerabilities = json.get("vulnerabilities", []) for vulnerability in vulnerabilities: key = md5_hash( f'{vulnerability["title"]}:{vulnerability["description"]}') entities.append( Entity( key=key, title=vulnerability["title"], description=vulnerability["description"], severity=vulnerability["severity"], )) return entities
async def _entities(self, metrics: dict[str, str]) -> Entities: """Override to return the effort entities.""" entities = Entities() api_values = self._data_model["sources"][ self.source_type]["parameters"]["effort_types"]["api_values"] for effort_type in self.__effort_types(): effort_type_description = [ param for param, api_key in api_values.items() if effort_type == api_key ][0] entities.append( Entity( key=effort_type, effort_type=effort_type_description, effort=metrics[effort_type], url=await self.__effort_type_landing_url(effort_type), )) return entities
async def _parse_source_responses(self, responses: SourceResponses) -> SourceMeasurement: """Override to parse the tests from the Robot Framework XML.""" count = 0 total = 0 entities = Entities() test_results = cast(list[str], self._parameter("test_result")) all_test_results = self._data_model["sources"][self.source_type]["parameters"]["test_result"]["values"] for response in responses: tree = await parse_source_response_xml(response) stats = tree.findall("statistics/total/stat")[1] for test_result in all_test_results: total += int(stats.get(test_result, 0)) if test_result in test_results: count += int(stats.get(test_result, 0)) for test in tree.findall(f".//test/status[@status='{test_result.upper()}']/.."): entities.append( Entity(key=test.get("id", ""), name=test.get("name", ""), test_result=test_result) ) return SourceMeasurement(value=str(count), total=str(total), entities=entities)
async def _parse_source_responses( self, responses: SourceResponses) -> SourceMeasurement: """Override to parse the LOC from the JSON responses.""" loc = 0 entities = Entities() languages_to_ignore = self._parameter("languages_to_ignore") for response in responses: for key, value in (await response.json(content_type=None)).items(): if key not in ("header", "SUM" ) and not match_string_or_regular_expression( key, languages_to_ignore): loc += value["code"] entities.append( Entity( key=key, language=key, blank=str(value["blank"]), comment=str(value["comment"]), code=str(value["code"]), nr_files=str(value["nFiles"]), )) return SourceMeasurement(value=str(loc), entities=entities)
async def _parse_source_responses( self, responses: SourceResponses) -> SourceMeasurement: """Override to parse the tests from the JUnit XML.""" entities = Entities() test_statuses_to_count = cast(list[str], self._parameter("test_result")) junit_status_nodes = dict(errored="error", failed="failure", skipped="skipped") total = 0 for response in responses: tree = await parse_source_response_xml(response) for test_case in tree.findall(".//testcase"): for test_result, junit_status_node in junit_status_nodes.items( ): if test_case.find(junit_status_node) is not None: break else: test_result = "passed" if test_result in test_statuses_to_count: entities.append(self.__entity(test_case, test_result)) total += 1 return SourceMeasurement(entities=entities, total=str(total))
async def _parse_source_responses( self, responses: SourceResponses) -> SourceMeasurement: """Get the metric entities from the responses.""" status_to_count = self._parameter("status") landing_url = await self._landing_url(responses) metrics_and_entities = await self.__get_metrics_and_entities( responses[0]) entities = Entities() for metric, entity in metrics_and_entities: recent_measurements: Measurements = cast( Measurements, metric.get("recent_measurements", [])) status, value = self.__get_status_and_value( metric, recent_measurements[-1] if recent_measurements else {}) if status in status_to_count: entity[ "report_url"] = report_url = f"{landing_url}/{metric['report_uuid']}" entity[ "subject_url"] = f"{report_url}#{metric['subject_uuid']}" entity["metric_url"] = f"{report_url}#{entity['key']}" entity["metric"] = str( metric.get("name") or self._data_model["metrics"][metric["type"]]["name"]) entity["status"] = status unit = metric.get("unit") or self._data_model["metrics"][ metric["type"]]["unit"] entity["measurement"] = f"{value or '?'} {unit}" direction = str( metric.get("direction") or self._data_model["metrics"][metric["type"]]["direction"]) direction = {"<": "≦", ">": "≧"}.get(direction, direction) target = metric.get("target") or self._data_model["metrics"][ metric["type"]]["target"] entity["target"] = f"{direction} {target} {unit}" entities.append(entity) return SourceMeasurement(total=str(len(metrics_and_entities)), entities=entities)