Skip to content

Commit

Permalink
fix(abr-testing): Make JIRA post_attachment_to_ticket function work (#…
Browse files Browse the repository at this point in the history
…15878)

<!--
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

Attach files to jira ticket upon creation.

## Test Plan and Hands on Testing

<!--
Describe your testing of the PR. Emphasize testing not reflected in the
code. Attach protocols, logs, screenshots and any other assets that
support your testing.
-->

## Changelog

Changed headers in `post_attachment_to_ticket` 
Changed file description
Added command in `abr_robot_error`
also small fix increase number of columns to add to google_sheet when
making new tab.
## Review requests

<!--
- What do you need from reviewers to feel confident this PR is ready to
merge?
- Ask questions.
-->

## 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
rclarke0 authored Aug 7, 2024
1 parent 3bcd4c9 commit 76525cd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion abr-testing/abr_testing/automation/google_sheets_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def open_worksheet(self, tab_number: int) -> Any:
def create_worksheet(self, title: str) -> Optional[str]:
"""Create a worksheet with tab name. Existing spreadsheet needed."""
try:
new_sheet = self.spread_sheet.add_worksheet(title, rows="2500", cols="40")
new_sheet = self.spread_sheet.add_worksheet(title, rows="2500", cols="50")
return new_sheet.id
except gspread.exceptions.APIError:
print("Sheet already exists.")
Expand Down
9 changes: 5 additions & 4 deletions abr-testing/abr_testing/automation/jira_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,18 @@ def create_ticket(

def post_attachment_to_ticket(self, issue_id: str, attachment_path: str) -> None:
"""Adds attachments to ticket."""
# TODO: Ensure that file is actually uploaded.
file = {"file": open(attachment_path, "rb")}
JSON_headers = {"Accept": "application/json"}
file = {
"file": (attachment_path, open(attachment_path, "rb"), "application-type")
}
JSON_headers = {"Accept": "application/json", "X-Atlassian-Token": "no-check"}
try:
response = requests.post(
f"{self.url}/rest/api/3/issue/{issue_id}/attachments",
headers=JSON_headers,
auth=self.auth,
files=file,
)
print(response)
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
12 changes: 7 additions & 5 deletions abr-testing/abr_testing/data_collection/abr_robot_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,15 +535,12 @@ 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.

error_files = [saved_file_path_calibration, run_log_file_path] + file_paths
error_folder_path = os.path.join(storage_directory, issue_key)
os.makedirs(error_folder_path, exist_ok=True)
Expand All @@ -555,8 +552,11 @@ def get_run_error_info_from_robot(
shutil.move(source_file, destination_file)
except shutil.Error:
continue
# OPEN FOLDER DIRECTORY
subprocess.Popen(["explorer", error_folder_path])
# POST FILES TO TICKET
list_of_files = os.listdir(error_folder_path)
for file in list_of_files:
file_to_attach = os.path.join(error_folder_path, file)
ticket.post_attachment_to_ticket(issue_key, file_to_attach)
# ADD ERROR COMMENTS TO TICKET
read_each_log(error_folder_path, raw_issue_url)
# WRITE ERRORED RUN TO GOOGLE SHEET
Expand Down Expand Up @@ -601,3 +601,5 @@ def get_run_error_info_from_robot(
google_sheet_lpc.batch_update_cells(runs_and_lpc, "A", start_row_lpc, "0")
else:
print("Ticket created.")
# Open folder directory incase uploads to ticket were incomplete
subprocess.Popen(["explorer", error_folder_path])

0 comments on commit 76525cd

Please sign in to comment.