Skip to content

Commit

Permalink
feat(abr-testing): add error lines as comments to jira ticket (#15544)
Browse files Browse the repository at this point in the history
<!--
Thanks for taking the time to open a pull request! 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

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

# Overview

<!--
Use this section to describe your pull-request at a high level. If the
PR addresses any open issues, please tag the issues here.
-->

# Test Plan

<!--
Use this section to describe the steps that you took to test your Pull
Request.
If you did not perform any testing provide justification why.

OT-3 Developers: You should default to testing on actual physical
hardware.
Once again, if you did not perform testing against hardware, justify
why.

Note: It can be helpful to write a test plan before doing development

Example Test Plan (HTTP API Change)

- Verified that new optional argument `dance-party` causes the robot to
flash its lights, move the pipettes,
then home.
- Verified that when you omit the `dance-party` option the robot homes
normally
- Added protocol that uses `dance-party` argument to G-Code Testing
Suite
- Ran protocol that did not use `dance-party` argument and everything
was successful
- Added unit tests to validate that changes to pydantic model are
correct

-->

# Changelog

<!--
List out the changes to the code in this PR. Please try your best to
categorize your changes and describe what has changed and why.

Example changelog:
- Fixed app crash when trying to calibrate an illegal pipette
- Added state to API to track pipette usage
- Updated API docs to mention only two pipettes are supported

IMPORTANT: MAKE SURE ANY BREAKING CHANGES ARE PROPERLY COMMUNICATED
-->

# Review requests

<!--
Describe any requests for your reviewers here.
-->

# Risk assessment

<!--
Carefully go over your pull request and look at the other parts of the
codebase it may affect. 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 in protocol may also change the
behavior of labware calibration.

Identify the other parts of the system your codebase may affect, so that
in addition to your own review and testing, other people who may not
have the system internalized as much as you can focus their attention
and testing there.
-->
  • Loading branch information
rclarke0 authored Jul 8, 2024
1 parent d4ee4af commit 2ba194c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
31 changes: 26 additions & 5 deletions abr-testing/abr_testing/automation/jira_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import json
import webbrowser
import argparse
from typing import List, Dict, Any
from typing import List, Dict, Any, Tuple
import os


Expand Down Expand Up @@ -61,7 +61,7 @@ def create_ticket(
components: list,
affects_versions: str,
robot: str,
) -> str:
) -> Tuple[str, str]:
"""Create ticket."""
data = {
"fields": {
Expand Down Expand Up @@ -98,15 +98,15 @@ def create_ticket(
response_str = str(response.content)
issue_url = response.json().get("self")
issue_key = response.json().get("key")
print(f"issue key {issue_key}")
print(f"issue url{issue_url}")
print(f"issue key: {issue_key}")
print(f"issue url: {issue_url}")
if issue_key is None:
print("Error: Could not create issue. No key returned.")
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}")
return issue_key
return issue_key, issue_url

def post_attachment_to_ticket(self, issue_id: str, attachment_path: str) -> None:
"""Adds attachments to ticket."""
Expand Down Expand Up @@ -185,6 +185,27 @@ def get_project_components(self, project_id: str) -> List[Dict[str, str]]:
components_list = response.json()
return components_list

def comment(self, comment_str: str, issue_url: str, comment_type: str) -> None:
"""Leave comment on JIRA Ticket."""
comment_url = issue_url + "/comment"
payload = json.dumps(
{
"body": {
"type": "doc",
"version": 1,
"content": [
{
"type": comment_type,
"content": [{"type": "text", "text": comment_str}],
}
],
}
}
)
requests.request(
"POST", comment_url, data=payload, headers=self.headers, auth=self.auth
)


if __name__ == "__main__":
"""Create ticket for specified robot."""
Expand Down
30 changes: 28 additions & 2 deletions abr-testing/abr_testing/data_collection/abr_robot_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,30 @@
import re


def read_each_log(folder_path: str, issue_url: str) -> None:
"""Read log and comment error portion on JIRA ticket."""
for file_name in os.listdir(folder_path):
file_path = os.path.join(folder_path, file_name)
print(file_path)
if file_path.endswith(".log"):
with open(file_path) as file:
lines = file.readlines()
word = "error"
error_lines = ""
for line_index, line in enumerate(lines):
if word in line:
lines_before = max(0, line_index - 20)
lines_after = min(len(lines), line_index + 20)
print("Line Number:", line_index + 1)
error_lines = "".join(lines[lines_before:lines_after])
message = f"Error found in {file_path}"
ticket.comment(error_lines, issue_url, "codeBlock")
break
if len(error_lines) < 1:
message = f"No error found in {file_name}"
ticket.comment(message, issue_url, "paragraph")


def match_error_to_component(
project_id: str, error_message: str, components: List[str]
) -> List[str]:
Expand Down Expand Up @@ -252,14 +276,15 @@ 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 {summary}.")
# TODO: make argument or see if I can get rid of with using board_id.
project_key = "RABR"
print(robot)
parent_key = project_key + "-" + robot.split("ABR")[1]
# TODO: read board to see if ticket for run id already exists.
# CREATE TICKET
issue_key = ticket.create_ticket(
issue_key, raw_issue_url = ticket.create_ticket(
summary,
whole_description_str,
project_key,
Expand Down Expand Up @@ -288,7 +313,8 @@ def get_run_error_info_from_robot(
continue
# OPEN FOLDER DIRECTORY
subprocess.Popen(["explorer", error_folder_path])

# ADD ERROR COMMENTS TO TICKET
read_each_log(error_folder_path, raw_issue_url)
# WRITE ERRORED RUN TO GOOGLE SHEET
if len(run_or_other) < 1:
# CONNECT TO GOOGLE DRIVE
Expand Down

0 comments on commit 2ba194c

Please sign in to comment.