Skip to content

Commit

Permalink
feat(abr-testing): Link relevant JIRA tickets (#15849)
Browse files Browse the repository at this point in the history
<!--
Thanks for taking the time to open a Pull Request (PR)! Please make sure
you've read the "Opening Pull Requests" section of our Contributing
Guide:


https://github.com/Opentrons/opentrons/blob/edge/CONTRIBUTING.md#opening-pull-requests

GitHub provides robust markdown to format your PR. Links, diagrams,
pictures, and videos along with text formatting make it possible to
create a rich and informative PR. For more information on GitHub
markdown, see:


https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax

To ensure your code is reviewed quickly and thoroughly, please fill out
the sections below to the best of your ability!
-->

# Overview

The create jira script will now link relevant tickets to a newly created
ticket.


## Test Plan and Hands on Testing

It was run multiple times on multiple accounts.

## Changelog

Fixed issues_on_board to grab recent issues, created match issues that
matches relevant issues, and created link tickets that links tickets.
Called all three functions in the Create Jira script.

## Review requests

<!--
- Nothing
-->

## Risk assessment

<!--
- Indicate the level of attention this PR needs.
- Provide context to guide reviewers.
- Discuss trade-offs, coupling, and side effects.
- Look for the possibility, even if you think it's small, that your
change may affect some other part of the system.
- For instance, changing return tip behavior may also change the
behavior of labware calibration.
- How do your unit tests and on hands on testing mitigate this PR's
risks and the risk of future regressions?
- Especially in high risk PRs, explain how you know your testing is
enough.
-->
  • Loading branch information
nbshiland authored Jul 31, 2024
1 parent 0869f43 commit 39297bb
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 4 deletions.
60 changes: 57 additions & 3 deletions abr-testing/abr_testing/automation/jira_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,79 @@ 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, project_key: str) -> List[List[Any]]:
"""Print Issues on board."""
params = {"jql": f"project = {project_key}"}
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()
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
issue_ids = []
for i in all_issues:
issue_id = i.get("id")
issue_ids.append(issue_id)
issue_summary = i["fields"].get("summary")
issue_ids.append([issue_id, issue_summary])
return issue_ids

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]
# 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:
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(self, to_link: list, ticket_key: str) -> None:
"""Links relevant issues in Jira."""
for issue in to_link:
link_data = json.dumps(
{
"inwardIssue": {"key": ticket_key},
"outwardIssue": {"id": issue},
"type": {"name": "Relates"},
}
)
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."""
url = f"{self.url}/browse/{issue_key}"
Expand Down
9 changes: 8 additions & 1 deletion abr-testing/abr_testing/data_collection/abr_robot_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down Expand Up @@ -519,6 +518,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(project_key)

# TODO: read board to see if ticket for run id already exists.
# CREATE TICKET
issue_key, raw_issue_url = ticket.create_ticket(
Expand All @@ -533,6 +535,11 @@ def get_run_error_info_from_robot(
affects_version,
parent_key,
)

# Link Tickets
to_link = ticket.match_issues(all_issues, summary)
ticket.link_issues(to_link, issue_key)

# OPEN TICKET
issue_url = ticket.open_issue(issue_key)
# MOVE FILES TO ERROR FOLDER.
Expand Down

0 comments on commit 39297bb

Please sign in to comment.