Skip to content

Commit

Permalink
fix(abr-testing): Make JIRA attachment function work
Browse files Browse the repository at this point in the history
  • Loading branch information
rclarke0 committed Aug 2, 2024
1 parent ebf6c72 commit 40c2c12
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
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 40c2c12

Please sign in to comment.