From 528f389ed472ad78d2b98631688ce133bc1589c9 Mon Sep 17 00:00:00 2001 From: Nicholas Shiland Date: Fri, 26 Jul 2024 11:19:35 -0400 Subject: [PATCH 1/9] grabbing current ticket robot and error and all --- .../abr_testing/automation/jira_tool.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/abr-testing/abr_testing/automation/jira_tool.py b/abr-testing/abr_testing/automation/jira_tool.py index df31c5231e8..216488e285b 100644 --- a/abr-testing/abr_testing/automation/jira_tool.py +++ b/abr-testing/abr_testing/automation/jira_tool.py @@ -36,12 +36,35 @@ def issues_on_board(self, board_id: str) -> List[str]: all_issues = board_data["issues"] except json.JSONDecodeError as e: print("Error decoding json: ", e) + #convert issue id's into dict and have one key as the issue key and one be summary, return entire dict issue_ids = [] for i in all_issues: issue_id = i.get("id") issue_ids.append(issue_id) return issue_ids + def match_issues(issue_ids, ticket_summary: str): + current_error = ticket_summary.split("_")[3] + robot = ticket_summary.split("_")[0] + """Grab all issues from board.""" + response = requests.get( + f"{self.url}/rest/agile/1.0/board/{board_id}/issue", + headers=self.headers, + auth=self.auth, + ) + response.raise_for_status() + try: + board_data = response.json() + all_issues = board_data["issues"] + except json.JSONDecodeError as e: + print("Error decoding json: ", e) + #for every issue see if both match, if yes then grab issue ID and add it to a list + for i in all_issues: + issue_error = ticket_summary.split("_")[3] + issue_robot = ticket_summary.split("_")[0] + + #function: "match_issues", input would be the list from above, another input is summary of ticket created (ticket_summary: string), + def open_issue(self, issue_key: str) -> str: """Open issue on web browser.""" url = f"{self.url}/browse/{issue_key}" @@ -260,3 +283,5 @@ def comment(self, content_list: List[Dict[str, Any]], issue_url: str) -> None: board_id = args.board_id[0] reporter_id = args.reporter_id[0] ticket = JiraTicket(url, api_token, email) + ticket.issues_on_board() + ticket.match_issues() From 622f15ec8b32648ea98ac764907d4941cf2700ca Mon Sep 17 00:00:00 2001 From: Nicholas Shiland Date: Fri, 26 Jul 2024 12:24:43 -0400 Subject: [PATCH 2/9] making an array with summary and id, grabbing summary and id --- .../abr_testing/automation/jira_tool.py | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/abr-testing/abr_testing/automation/jira_tool.py b/abr-testing/abr_testing/automation/jira_tool.py index 216488e285b..56c33f56ba9 100644 --- a/abr-testing/abr_testing/automation/jira_tool.py +++ b/abr-testing/abr_testing/automation/jira_tool.py @@ -40,28 +40,19 @@ def issues_on_board(self, board_id: str) -> List[str]: issue_ids = [] for i in all_issues: issue_id = i.get("id") - issue_ids.append(issue_id) + issue_summary = i.get("summary") + issue_ids.append([issue_id, issue_summary]) return issue_ids def match_issues(issue_ids, ticket_summary: str): current_error = ticket_summary.split("_")[3] robot = ticket_summary.split("_")[0] - """Grab all issues from board.""" - response = requests.get( - f"{self.url}/rest/agile/1.0/board/{board_id}/issue", - headers=self.headers, - auth=self.auth, - ) - response.raise_for_status() - try: - board_data = response.json() - all_issues = board_data["issues"] - except json.JSONDecodeError as e: - print("Error decoding json: ", e) #for every issue see if both match, if yes then grab issue ID and add it to a list - for i in all_issues: - issue_error = ticket_summary.split("_")[3] - issue_robot = ticket_summary.split("_")[0] + for i in issue_ids: + summary = issue_ids[i][1] + issue_error = summary.split("_")[3] + issue_robot = summary.split("_")[0] + issue_id = issue_ids[i][0] #function: "match_issues", input would be the list from above, another input is summary of ticket created (ticket_summary: string), From 94cde2892503b91d532a0970eaf5a5dacb78b7c5 Mon Sep 17 00:00:00 2001 From: Nicholas Shiland Date: Fri, 26 Jul 2024 12:34:03 -0400 Subject: [PATCH 3/9] returns list of issues to link --- abr-testing/abr_testing/automation/jira_tool.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/abr-testing/abr_testing/automation/jira_tool.py b/abr-testing/abr_testing/automation/jira_tool.py index 56c33f56ba9..7b94cb1287b 100644 --- a/abr-testing/abr_testing/automation/jira_tool.py +++ b/abr-testing/abr_testing/automation/jira_tool.py @@ -45,7 +45,8 @@ def issues_on_board(self, board_id: str) -> List[str]: return issue_ids def match_issues(issue_ids, ticket_summary: str): - current_error = ticket_summary.split("_")[3] + to_link = [] + error = ticket_summary.split("_")[3] robot = ticket_summary.split("_")[0] #for every issue see if both match, if yes then grab issue ID and add it to a list for i in issue_ids: @@ -53,6 +54,15 @@ def match_issues(issue_ids, ticket_summary: str): issue_error = summary.split("_")[3] issue_robot = summary.split("_")[0] issue_id = issue_ids[i][0] + if robot == issue_robot and error == issue_error: + to_link.append(issue_id) + + return to_link + + def link_issues(to_link, ticket_summary: str): + print("oh no") + + #function: "match_issues", input would be the list from above, another input is summary of ticket created (ticket_summary: string), From dd7f702314abde8106623e5e848f38b64a119fa4 Mon Sep 17 00:00:00 2001 From: Nicholas Shiland Date: Fri, 26 Jul 2024 13:00:55 -0400 Subject: [PATCH 4/9] small changes --- abr-testing/abr_testing/automation/jira_tool.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/abr-testing/abr_testing/automation/jira_tool.py b/abr-testing/abr_testing/automation/jira_tool.py index 7b94cb1287b..ff8eb93d75d 100644 --- a/abr-testing/abr_testing/automation/jira_tool.py +++ b/abr-testing/abr_testing/automation/jira_tool.py @@ -36,7 +36,7 @@ def issues_on_board(self, board_id: str) -> List[str]: all_issues = board_data["issues"] except json.JSONDecodeError as e: print("Error decoding json: ", e) - #convert issue id's into dict and have one key as the issue key and one be summary, return entire dict + #convert issue id's into array and have one key as the issue key and one be summary, return entire array issue_ids = [] for i in all_issues: issue_id = i.get("id") From 70e99ffd975b4fc1c2b7aa000dbf0a47f852d55b Mon Sep 17 00:00:00 2001 From: Nicholas Shiland Date: Tue, 30 Jul 2024 16:12:51 -0400 Subject: [PATCH 5/9] made most things work --- .../abr_testing/automation/jira_tool.py | 51 ++++++++++++++----- .../data_collection/abr_robot_error.py | 9 ++++ 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/abr-testing/abr_testing/automation/jira_tool.py b/abr-testing/abr_testing/automation/jira_tool.py index ff8eb93d75d..6249d1de9a4 100644 --- a/abr-testing/abr_testing/automation/jira_tool.py +++ b/abr-testing/abr_testing/automation/jira_tool.py @@ -25,11 +25,14 @@ def __init__(self, url: str, api_token: str, email: str) -> None: def issues_on_board(self, board_id: str) -> List[str]: """Print Issues on board.""" + params = {"jql": "project = RABR"} response = requests.get( - f"{self.url}/rest/agile/1.0/board/{board_id}/issue", + f"{self.url}/rest/api/3/search", headers=self.headers, + params = params, auth=self.auth, ) + response.raise_for_status() try: board_data = response.json() @@ -40,29 +43,51 @@ def issues_on_board(self, board_id: str) -> List[str]: issue_ids = [] for i in all_issues: issue_id = i.get("id") - issue_summary = i.get("summary") + issue_summary = i["fields"].get("summary") + #print(f"summary: {issue_summary} {issue_id}") issue_ids.append([issue_id, issue_summary]) return issue_ids - def match_issues(issue_ids, ticket_summary: str): + def match_issues(self, issue_ids: List[List[str]], ticket_summary: str): to_link = [] error = ticket_summary.split("_")[3] robot = ticket_summary.split("_")[0] + print(error) + print(robot) #for every issue see if both match, if yes then grab issue ID and add it to a list - for i in issue_ids: - summary = issue_ids[i][1] - issue_error = summary.split("_")[3] - issue_robot = summary.split("_")[0] - issue_id = issue_ids[i][0] + for issue in issue_ids: + summary = issue[1] + try: + issue_error = summary.split("_")[3] + issue_robot = summary.split("_")[0] + except IndexError: + continue + issue_id = issue[0] if robot == issue_robot and error == issue_error: to_link.append(issue_id) - return to_link - def link_issues(to_link, ticket_summary: str): - print("oh no") - - + def link_issues(self, to_link: list, ticket_id: str): + for issue in to_link: + link_data = { + "type": {"name": "Related Issues"}, + "inwardIssue": {"id": ticket_id}, + "outwardIssue": {"id": issue}, + "comment": {"body": "comment if needed"}, + } + try: + response = requests.post( + f"{self.url}/rest/api/2/issueLink", + headers=self.headers, + auth=self.auth, + json=link_data, + ) + response.raise_for_status() + response_str = str(response.content) + except requests.exceptions.HTTPError: + print(f"HTTP error occurred. Response content: {response_str}") + except json.JSONDecodeError: + print(f"JSON decoding error occurred. Response content: {response_str}") #function: "match_issues", input would be the list from above, another input is summary of ticket created (ticket_summary: string), 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 98af232304d..11dbd98ac49 100644 --- a/abr-testing/abr_testing/data_collection/abr_robot_error.py +++ b/abr-testing/abr_testing/data_collection/abr_robot_error.py @@ -533,6 +533,15 @@ def get_run_error_info_from_robot( affects_version, parent_key, ) + + #Link Tickets (hopefully) + all_issues = ticket.issues_on_board(board_id) + print(type(all_issues)) + print(type(summary)) + to_link = ticket.match_issues(all_issues, summary) + print(to_link) + ticket.link_issues(to_link, issue_key) + # OPEN TICKET issue_url = ticket.open_issue(issue_key) # MOVE FILES TO ERROR FOLDER. From 3ebadeb5816219289081807fe98c7ffee7349c4c Mon Sep 17 00:00:00 2001 From: Nicholas Shiland Date: Tue, 30 Jul 2024 17:00:33 -0400 Subject: [PATCH 6/9] everything but actually linking works --- .../abr_testing/automation/jira_tool.py | 80 +++++++++++-------- .../data_collection/abr_robot_error.py | 2 +- 2 files changed, 49 insertions(+), 33 deletions(-) diff --git a/abr-testing/abr_testing/automation/jira_tool.py b/abr-testing/abr_testing/automation/jira_tool.py index 6249d1de9a4..3c726a2b60e 100644 --- a/abr-testing/abr_testing/automation/jira_tool.py +++ b/abr-testing/abr_testing/automation/jira_tool.py @@ -23,41 +23,43 @@ def __init__(self, url: str, api_token: str, email: str) -> None: "Content-Type": "application/json", } - def issues_on_board(self, board_id: str) -> List[str]: + def issues_on_board(self, board_id: str) -> List[List[Any]]: """Print Issues on board.""" params = {"jql": "project = RABR"} response = requests.get( f"{self.url}/rest/api/3/search", headers=self.headers, - params = params, + params=params, auth=self.auth, ) - + response.raise_for_status() try: board_data = response.json() all_issues = board_data["issues"] except json.JSONDecodeError as e: print("Error decoding json: ", e) - #convert issue id's into array and have one key as the issue key and one be summary, return entire array + # convert issue id's into array and have one key as + # the issue key and one be summary, return entire array issue_ids = [] for i in all_issues: issue_id = i.get("id") issue_summary = i["fields"].get("summary") - #print(f"summary: {issue_summary} {issue_id}") + # print(f"summary: {issue_summary} {issue_id}") issue_ids.append([issue_id, issue_summary]) return issue_ids - def match_issues(self, issue_ids: List[List[str]], ticket_summary: str): + def match_issues(self, issue_ids: List[List[str]], ticket_summary: str) -> List: + """Matches related ticket ID's.""" to_link = [] error = ticket_summary.split("_")[3] robot = ticket_summary.split("_")[0] print(error) print(robot) - #for every issue see if both match, if yes then grab issue ID and add it to a list + # for every issue see if both match, if yes then grab issue ID and add it to a list for issue in issue_ids: - summary = issue[1] - try: + summary = issue[1] + try: issue_error = summary.split("_")[3] issue_robot = summary.split("_")[0] except IndexError: @@ -67,29 +69,45 @@ def match_issues(self, issue_ids: List[List[str]], ticket_summary: str): to_link.append(issue_id) return to_link - def link_issues(self, to_link: list, ticket_id: str): + def link_issues(self, to_link: list, ticket_key: str) -> None: + """Links relevant issues in Jira.""" for issue in to_link: - link_data = { - "type": {"name": "Related Issues"}, - "inwardIssue": {"id": ticket_id}, - "outwardIssue": {"id": issue}, - "comment": {"body": "comment if needed"}, - } - try: - response = requests.post( - f"{self.url}/rest/api/2/issueLink", - headers=self.headers, - auth=self.auth, - json=link_data, - ) - response.raise_for_status() - response_str = str(response.content) - except requests.exceptions.HTTPError: - print(f"HTTP error occurred. Response content: {response_str}") - except json.JSONDecodeError: - print(f"JSON decoding error occurred. Response content: {response_str}") + link_data = json.dumps( + { + "comment": { + "body": { + "content": [ + { + "content": [ + { + "text": "Linked related issue!", + "type": "text", + } + ], + "type": "paragraph", + } + ], + "type": "doc", + "version": 1, + }, + }, + "inwardIssue": {"key": ticket_key}, + "outwardIssue": {"id": issue}, + "type": {"name": "Relates"}, + } + ) + response = requests.post( + f"{self.url}/rest/api/3/issueLink", + headers=self.headers, + auth=self.auth, + data=link_data, + ) + # print(response.raise_for_status()) - #function: "match_issues", input would be the list from above, another input is summary of ticket created (ticket_summary: string), + # except requests.exceptions.HTTPError: + # print("HTTP ERROR OH NO") + # except json.JSONDecodeError: + # print("JSON decoding error") def open_issue(self, issue_key: str) -> str: """Open issue on web browser.""" @@ -309,5 +327,3 @@ def comment(self, content_list: List[Dict[str, Any]], issue_url: str) -> None: board_id = args.board_id[0] reporter_id = args.reporter_id[0] ticket = JiraTicket(url, api_token, email) - ticket.issues_on_board() - ticket.match_issues() 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 11dbd98ac49..6544545030b 100644 --- a/abr-testing/abr_testing/data_collection/abr_robot_error.py +++ b/abr-testing/abr_testing/data_collection/abr_robot_error.py @@ -534,7 +534,7 @@ def get_run_error_info_from_robot( parent_key, ) - #Link Tickets (hopefully) + # Link Tickets (hopefully) all_issues = ticket.issues_on_board(board_id) print(type(all_issues)) print(type(summary)) From 0f180e160435e79fd3290c4d7a9a95ce98d42903 Mon Sep 17 00:00:00 2001 From: Nicholas Shiland Date: Wed, 31 Jul 2024 11:04:02 -0400 Subject: [PATCH 7/9] deleting excess comment and making issue list before new ticket --- .../abr_testing/automation/jira_tool.py | 27 +------------------ .../data_collection/abr_robot_error.py | 9 +++---- 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/abr-testing/abr_testing/automation/jira_tool.py b/abr-testing/abr_testing/automation/jira_tool.py index 3c726a2b60e..f0de39db8da 100644 --- a/abr-testing/abr_testing/automation/jira_tool.py +++ b/abr-testing/abr_testing/automation/jira_tool.py @@ -45,7 +45,6 @@ def issues_on_board(self, board_id: str) -> List[List[Any]]: for i in all_issues: issue_id = i.get("id") issue_summary = i["fields"].get("summary") - # print(f"summary: {issue_summary} {issue_id}") issue_ids.append([issue_id, issue_summary]) return issue_ids @@ -54,8 +53,6 @@ def match_issues(self, issue_ids: List[List[str]], ticket_summary: str) -> List: to_link = [] error = ticket_summary.split("_")[3] robot = ticket_summary.split("_")[0] - print(error) - print(robot) # for every issue see if both match, if yes then grab issue ID and add it to a list for issue in issue_ids: summary = issue[1] @@ -74,23 +71,6 @@ def link_issues(self, to_link: list, ticket_key: str) -> None: for issue in to_link: link_data = json.dumps( { - "comment": { - "body": { - "content": [ - { - "content": [ - { - "text": "Linked related issue!", - "type": "text", - } - ], - "type": "paragraph", - } - ], - "type": "doc", - "version": 1, - }, - }, "inwardIssue": {"key": ticket_key}, "outwardIssue": {"id": issue}, "type": {"name": "Relates"}, @@ -102,12 +82,7 @@ def link_issues(self, to_link: list, ticket_key: str) -> None: auth=self.auth, data=link_data, ) - # print(response.raise_for_status()) - - # except requests.exceptions.HTTPError: - # print("HTTP ERROR OH NO") - # except json.JSONDecodeError: - # print("JSON decoding error") + print(response) def open_issue(self, issue_key: str) -> str: """Open issue on web browser.""" 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 6544545030b..e4ef6cf9645 100644 --- a/abr-testing/abr_testing/data_collection/abr_robot_error.py +++ b/abr-testing/abr_testing/data_collection/abr_robot_error.py @@ -519,6 +519,9 @@ def get_run_error_info_from_robot( print(robot) parent_key = project_key + "-" + robot.split("ABR")[1] + # Grab all previous issues + all_issues = ticket.issues_on_board(board_id) + # TODO: read board to see if ticket for run id already exists. # CREATE TICKET issue_key, raw_issue_url = ticket.create_ticket( @@ -534,12 +537,8 @@ def get_run_error_info_from_robot( parent_key, ) - # Link Tickets (hopefully) - all_issues = ticket.issues_on_board(board_id) - print(type(all_issues)) - print(type(summary)) + # Link Tickets to_link = ticket.match_issues(all_issues, summary) - print(to_link) ticket.link_issues(to_link, issue_key) # OPEN TICKET From a36632f4c73230e6d3cd4191e9fced830e436fa8 Mon Sep 17 00:00:00 2001 From: Nicholas Shiland Date: Wed, 31 Jul 2024 12:08:16 -0400 Subject: [PATCH 8/9] removing redundancy --- abr-testing/abr_testing/automation/jira_tool.py | 5 ++--- abr-testing/abr_testing/data_collection/abr_robot_error.py | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/abr-testing/abr_testing/automation/jira_tool.py b/abr-testing/abr_testing/automation/jira_tool.py index f0de39db8da..2e85a622d07 100644 --- a/abr-testing/abr_testing/automation/jira_tool.py +++ b/abr-testing/abr_testing/automation/jira_tool.py @@ -23,9 +23,9 @@ def __init__(self, url: str, api_token: str, email: str) -> None: "Content-Type": "application/json", } - def issues_on_board(self, board_id: str) -> List[List[Any]]: + def issues_on_board(self, project_key: str) -> List[List[Any]]: """Print Issues on board.""" - params = {"jql": "project = RABR"} + params = {"jql": f"project = {project_key}"} response = requests.get( f"{self.url}/rest/api/3/search", headers=self.headers, @@ -82,7 +82,6 @@ def link_issues(self, to_link: list, ticket_key: str) -> None: auth=self.auth, data=link_data, ) - print(response) def open_issue(self, issue_key: str) -> str: """Open issue on web browser.""" 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 e4ef6cf9645..a35a93f54ae 100644 --- a/abr-testing/abr_testing/data_collection/abr_robot_error.py +++ b/abr-testing/abr_testing/data_collection/abr_robot_error.py @@ -481,7 +481,6 @@ def get_run_error_info_from_robot( reporter_id = args.reporter_id[0] file_paths = read_robot_logs.get_logs(storage_directory, ip) ticket = jira_tool.JiraTicket(url, api_token, email) - ticket.issues_on_board(board_id) users_file_path = ticket.get_jira_users(storage_directory) assignee_id = get_user_id(users_file_path, assignee) run_log_file_path = "" @@ -520,7 +519,7 @@ def get_run_error_info_from_robot( parent_key = project_key + "-" + robot.split("ABR")[1] # Grab all previous issues - all_issues = ticket.issues_on_board(board_id) + all_issues = ticket.issues_on_board(project_key) # TODO: read board to see if ticket for run id already exists. # CREATE TICKET From 3010f9ba1a3f16db04ad17284c4136887fc0689d Mon Sep 17 00:00:00 2001 From: Nicholas Shiland Date: Wed, 31 Jul 2024 14:31:53 -0400 Subject: [PATCH 9/9] adding error recovery to linking tickets --- .../abr_testing/automation/jira_tool.py | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/abr-testing/abr_testing/automation/jira_tool.py b/abr-testing/abr_testing/automation/jira_tool.py index 2e85a622d07..4bc8ba4686b 100644 --- a/abr-testing/abr_testing/automation/jira_tool.py +++ b/abr-testing/abr_testing/automation/jira_tool.py @@ -76,12 +76,25 @@ def link_issues(self, to_link: list, ticket_key: str) -> None: "type": {"name": "Relates"}, } ) - response = requests.post( - f"{self.url}/rest/api/3/issueLink", - headers=self.headers, - auth=self.auth, - data=link_data, - ) + try: + response = requests.post( + f"{self.url}/rest/api/3/issueLink", + headers=self.headers, + auth=self.auth, + data=link_data, + ) + response.raise_for_status() + except requests.exceptions.HTTPError: + print( + f"HTTP error occurred. Ticket ID {issue} was not linked. \ + Check user permissions and authentication credentials" + ) + except requests.exceptions.ConnectionError: + print(f"Connection error occurred. Ticket ID {issue} was not linked.") + except json.JSONDecodeError: + print( + f"JSON decoding error occurred. Ticket ID {issue} was not linked." + ) def open_issue(self, issue_key: str) -> str: """Open issue on web browser."""