diff --git a/abr-testing/abr_testing/automation/jira_tool.py b/abr-testing/abr_testing/automation/jira_tool.py index 1fd2b50b7f2..58f4af669bf 100644 --- a/abr-testing/abr_testing/automation/jira_tool.py +++ b/abr-testing/abr_testing/automation/jira_tool.py @@ -178,6 +178,13 @@ def get_jira_users(self, storage_directory: str) -> str: print("JSON decoding error occurred.") return file_path + def get_project_components(self, project_id: str) -> List[Dict[str, str]]: + """Get list of components on JIRA board.""" + component_url = f"{self.url}/rest/api/3/project/{project_id}/components" + response = requests.get(component_url, headers=self.headers, auth=self.auth) + components_list = response.json() + return components_list + if __name__ == "__main__": """Create ticket for specified robot.""" diff --git a/abr-testing/abr_testing/data_collection/abr_robot_error.py b/abr-testing/abr_testing/data_collection/abr_robot_error.py index d2b44a34e43..373ca1c3031 100644 --- a/abr-testing/abr_testing/data_collection/abr_robot_error.py +++ b/abr-testing/abr_testing/data_collection/abr_robot_error.py @@ -9,6 +9,21 @@ import subprocess import sys import json +import re + + +def match_error_to_component( + project_id: str, error_message: str, components: List[str] +) -> List[str]: + """Match error to component based on error message.""" + project_components = ticket.get_project_components(project_id) + component_names = [proj_comp["name"] for proj_comp in project_components] + for component in component_names: + pattern = re.compile(component, re.IGNORECASE) + matches = pattern.findall(error_message) + if matches: + components.append(component) + return components def get_user_id(user_file_path: str, assignee_name: str) -> str: @@ -76,9 +91,10 @@ def get_robot_state( ) module_data = response.json() for module in module_data["data"]: - print(module) description[module["moduleType"]] = module components = ["Flex-RABR"] + components = match_error_to_component("RABR", reported_string, components) + print(components) whole_description_str = ( "{" + "\n".join("{!r}: {!r},".format(k, v) for k, v in description.items()) @@ -116,6 +132,8 @@ def get_run_error_info_from_robot( failure_level = "Level " + str(error_level) + " Failure" components = [failure_level, "Flex-RABR"] + components = match_error_to_component("RABR", error_type, components) + print(components) affects_version = results["API_Version"] parent = results.get("robot_name", "") print(parent) @@ -211,8 +229,8 @@ def get_run_error_info_from_robot( except requests.exceptions.InvalidURL: print("Invalid IP address.") sys.exit() - one_run = error_runs[-1] # Most recent run with error. if len(run_or_other) < 1: + one_run = error_runs[-1] # Most recent run with error. ( summary, robot, @@ -234,7 +252,7 @@ def get_run_error_info_from_robot( ip, storage_directory ) file_paths = read_robot_logs.get_logs(storage_directory, ip) - print(f"Making ticket for run: {one_run} on robot {robot}.") + print(f"Making ticket for {summary}.") # TODO: make argument or see if I can get rid of with using board_id. project_key = "RABR" parent_key = project_key + "-" + robot[-1] diff --git a/abr-testing/abr_testing/data_collection/read_robot_logs.py b/abr-testing/abr_testing/data_collection/read_robot_logs.py index a41688ac8fa..0d5dd5491e8 100644 --- a/abr-testing/abr_testing/data_collection/read_robot_logs.py +++ b/abr-testing/abr_testing/data_collection/read_robot_logs.py @@ -383,6 +383,9 @@ def get_error_info(file_results: Dict[str, Any]) -> Tuple[int, str, str, str, st error_str = 0 if error_str > 1: error_type = run_command_error["error"].get("errorType", "") + if error_type == "PythonException": + # Reassign error_type to be more descriptive + error_type = run_command_error["detail"].split(":")[0] error_code = run_command_error["error"].get("errorCode", "") try: # Instrument Error