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

fix(abr-testing): Make JIRA post_attachment_to_ticket function work #15878

Merged
merged 13 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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])
Loading