Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(abr-testing): Link relevant JIRA tickets #15849

Merged
merged 9 commits into from
Jul 31, 2024
48 changes: 45 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,67 @@ 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/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"},
}
)
response = requests.post(
f"{self.url}/rest/api/3/issueLink",
headers=self.headers,
auth=self.auth,
data=link_data,
)
rclarke0 marked this conversation as resolved.
Show resolved Hide resolved
print(response)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to print response every time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and lets add error handling around the requests.post()
try: response = requests.post( f"{self.url}/rest/api/3/issueLink", headers=self.headers, auth=self.auth, data=link_data, ) response_str = str(response.content) except requests.exceptions.HTTPError: print(f"HTTP error occurred. Response content: {response_str}")


def open_issue(self, issue_key: str) -> str:
"""Open issue on web browser."""
url = f"{self.url}/browse/{issue_key}"
Expand Down
8 changes: 8 additions & 0 deletions abr-testing/abr_testing/data_collection/abr_robot_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,9 @@ def get_run_error_info_from_robot(
print(robot)
rclarke0 marked this conversation as resolved.
Show resolved Hide resolved
parent_key = project_key + "-" + robot.split("ABR")[1]

# Grab all previous issues
all_issues = ticket.issues_on_board(board_id)

rclarke0 marked this conversation as resolved.
Show resolved Hide resolved
# 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 +536,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
Loading