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 (hardware-testing): add JIRA functionality to testing scripts #16013

Merged
merged 15 commits into from
Aug 19, 2024
35 changes: 30 additions & 5 deletions abr-testing/abr_testing/automation/jira_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,16 @@ def post_attachment_to_ticket(self, issue_id: str, attachment_path: str) -> None
"file": (attachment_path, open(attachment_path, "rb"), "application-type")
}
JSON_headers = {"Accept": "application/json", "X-Atlassian-Token": "no-check"}
attachment_url = f"{self.url}/rest/api/3/issue/{issue_id}/attachments"
try:
response = requests.post(
f"{self.url}/rest/api/3/issue/{issue_id}/attachments",
response = requests.request(
"POST",
attachment_url,
headers=JSON_headers,
auth=self.auth,
files=file,
)
print(f"File: {attachment_path} posted to ticket {issue_id}")
print(f"File: {attachment_path} posted to ticket {issue_id}.")
except json.JSONDecodeError:
error_message = str(response.content)
print(f"JSON decoding error occurred. Response content: {error_message}.")
Expand Down Expand Up @@ -257,9 +259,9 @@ def get_project_components(self, project_id: str) -> List[Dict[str, str]]:
components_list = response.json()
return components_list

def comment(self, content_list: List[Dict[str, Any]], issue_url: str) -> None:
def comment(self, content_list: List[Dict[str, Any]], issue_key: str) -> None:
"""Leave comment on JIRA Ticket."""
comment_url = issue_url + "/comment"
comment_url = f"{self.url}/rest/api/3/issue/{issue_key}/comment"
payload = json.dumps(
{
"body": {
Expand All @@ -273,6 +275,29 @@ def comment(self, content_list: List[Dict[str, Any]], issue_url: str) -> None:
"POST", comment_url, data=payload, headers=self.headers, auth=self.auth
)

def format_jira_comment(self, comment_info: Any) -> List[Dict[str, Any]]:
"""Formats a string input to work with the "comment" function."""
content_list: List = []
line_1 = {
"type": "paragraph",
"content": [{"type": "text", "text": comment_info}],
}
content_list.insert(0, line_1)
return content_list

def get_ticket(self) -> str:
"""Gets and confirms jira ticket number."""
while True:
issue_key = input("Ticket Key: ")
url = f"{self.url}/rest/api/3/issue/{issue_key}"
headers = {"Accept": "application/json"}
response = requests.request("GET", url, headers=headers, auth=self.auth)
if str(response) == "<Response [200]>":
break
else:
print("Please input a valid JIRA Key")
return issue_key


if __name__ == "__main__":
"""Create ticket for specified robot."""
Expand Down
37 changes: 21 additions & 16 deletions abr-testing/abr_testing/data_collection/abr_robot_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def read_each_log(folder_path: str, issue_url: str) -> None:
"content": [{"type": "text", "text": message}],
}
content_list.insert(0, line_1)
ticket.comment(content_list, issue_url)
ticket.comment(content_list, issue_key)
no_word_found_message = (
f"Key words '{not_found_words} were not found in {file_name}."
)
Expand All @@ -209,7 +209,7 @@ def read_each_log(folder_path: str, issue_url: str) -> None:
"content": [{"type": "text", "text": no_word_found_message}],
}
content_list.append(no_word_found_dict)
ticket.comment(content_list, issue_url)
ticket.comment(content_list, issue_key)


def match_error_to_component(
Expand Down Expand Up @@ -383,21 +383,26 @@ def get_run_error_info_from_robot(
errored_labware_dict["Slot"] = labware["location"].get("slotName", "")
errored_labware_dict["Labware Type"] = labware.get("definitionUri", "")
offset_id = labware.get("offsetId", "")
for lpc in lpc_dict:
if lpc.get("id", "") == offset_id:
errored_labware_dict["X"] = lpc["vector"].get("x", "")
errored_labware_dict["Y"] = lpc["vector"].get("y", "")
errored_labware_dict["Z"] = lpc["vector"].get("z", "")
errored_labware_dict["Module"] = lpc["location"].get(
"moduleModel", ""
)
errored_labware_dict["Adapter"] = lpc["location"].get(
"definitionUri", ""
)
if offset_id == "":
labware_slot = errored_labware_dict["Slot"]
lpc_message = f"The current LPC coords found at {labware_slot} are (0, 0, 0). \
Please confirm with the ABR-LPC sheet and re-LPC."
else:
for lpc in lpc_dict:
if lpc.get("id", "") == offset_id:
errored_labware_dict["X"] = lpc["vector"].get("x", "")
errored_labware_dict["Y"] = lpc["vector"].get("y", "")
errored_labware_dict["Z"] = lpc["vector"].get("z", "")
errored_labware_dict["Module"] = lpc["location"].get(
"moduleModel", ""
)
errored_labware_dict["Adapter"] = lpc["location"].get(
"definitionUri", ""
)

lpc_message = compare_lpc_to_historical_data(
errored_labware_dict, parent, storage_directory
)
lpc_message = compare_lpc_to_historical_data(
errored_labware_dict, parent, storage_directory
)

description["protocol_step"] = protocol_step
description["right_mount"] = results.get("right", "No attachment")
Expand Down
Loading
Loading