Skip to content

Commit

Permalink
fixing jira file attachments (#31297)
Browse files Browse the repository at this point in the history
fixing jira file attachments, fixing mapping of newly created tickets #31297
  • Loading branch information
kobymeir committed Dec 5, 2023
1 parent a356448 commit bbb7c2d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
16 changes: 7 additions & 9 deletions Tests/scripts/convert_test_playbook_result_to_jira_issues.py
Expand Up @@ -18,8 +18,8 @@
from Tests.scripts.jira_issues import JIRA_SERVER_URL, JIRA_VERIFY_SSL, JIRA_API_KEY, \
JIRA_PROJECT_ID, JIRA_ISSUE_TYPE, JIRA_COMPONENT, JIRA_ISSUE_UNRESOLVED_TRANSITION_NAME, JIRA_LABELS, \
find_existing_jira_ticket, JIRA_ADDITIONAL_FIELDS, generate_ticket_summary, generate_build_markdown_link, \
jira_server_information, jira_search_all_by_query, generate_query_by_component_and_issue_type, jira_ticket_to_json_data, \
jira_file_link, jira_sanitize_file_name, jira_color_text
jira_server_information, jira_search_all_by_query, generate_query_by_component_and_issue_type, jira_file_link, \
jira_sanitize_file_name, jira_color_text
from Tests.scripts.test_playbooks_report import calculate_test_playbooks_results, \
TEST_PLAYBOOKS_BASE_HEADERS, get_jira_tickets_for_playbooks, TEST_PLAYBOOKS_JIRA_BASE_HEADERS, \
write_test_playbook_to_jira_mapping, TEST_PLAYBOOKS_TO_JIRA_TICKETS_CONVERTED
Expand Down Expand Up @@ -144,12 +144,9 @@ def main():
playbooks_results, server_versions = calculate_test_playbooks_results(test_playbooks_result_files_list)

issues = jira_search_all_by_query(jira_server, generate_query_by_component_and_issue_type())
jira_tickets_for_playbooks = get_jira_tickets_for_playbooks(list(playbooks_results.keys()), issues)
jira_tickets_for_playbooks: dict[str, Issue] = get_jira_tickets_for_playbooks(list(playbooks_results.keys()), issues)
logging.info(f"Found {len(jira_tickets_for_playbooks)} Jira tickets out of {len(playbooks_results)} playbooks")

write_test_playbook_to_jira_mapping(artifacts_path, jira_tickets_for_playbooks)
open(artifacts_path / TEST_PLAYBOOKS_TO_JIRA_TICKETS_CONVERTED, "w")

# Search if we have too many test playbooks that failed beyond the max allowed limit to open, if so we print the
# list and exit. This is to avoid opening too many Jira issues.
failed_playbooks = get_all_failed_results(playbooks_results)
Expand All @@ -165,7 +162,6 @@ def main():
f"which is more than the max allowed limit of {options.max_failures_to_handle} to handle.")

sys.exit(1)
playbook_to_jira_mapping = {}
for playbook_id, test_suites in playbooks_results.items():
# We create the table without Jira tickets columns, as we don't want to have them within the Jira issue.
# We also add the skipped tests, as we want to have them within the Jira issue.
Expand All @@ -190,16 +186,18 @@ def main():
if jira_ticket or total_errors:
# if the ticket isn't resolved, or we found new errors, we update it, otherwise we skip it.
if jira_ticket and jira_ticket.get_field("resolution") and not total_errors:
playbook_to_jira_mapping[playbook_id] = jira_ticket_to_json_data(jira_ticket)
jira_tickets_for_playbooks[playbook_id] = jira_ticket
logging.debug(f"Skipped updating Jira issue for resolved test playbook:{playbook_id}")
continue
junit_file_name = get_attachment_file_name(playbook_id, options.build_number)
jira_ticket = create_jira_issue(jira_server, jira_ticket, xml, playbook_id, options.build_number, tabulate_data,
options.max_days_to_reopen, now, junit_file_name, total_errors > 0)
playbook_to_jira_mapping[playbook_id] = jira_ticket_to_json_data(jira_ticket)
jira_tickets_for_playbooks[playbook_id] = jira_ticket
else:
logging.debug(f"Skipped creating Jira issue for successful test playbook:{playbook_id}")

write_test_playbook_to_jira_mapping(artifacts_path, jira_tickets_for_playbooks)
open(artifacts_path / TEST_PLAYBOOKS_TO_JIRA_TICKETS_CONVERTED, "w")
logging.info("Finished creating/updating Jira issues")

except Exception as e:
Expand Down
3 changes: 2 additions & 1 deletion Tests/scripts/test_modeling_rule_report.py
Expand Up @@ -72,7 +72,8 @@ def create_jira_issue_for_test_modeling_rule(jira_server: JIRA,
xml = JUnitXml()
xml.add_testsuite(test_suite)
xml.write(attachment_file_name.name, pretty=True)
jira_server.add_attachment(issue=jira_issue.key, attachment=attachment_file_name.name, filename=junit_file_name)
jira_server.add_attachment(issue=jira_issue.key, attachment=attachment_file_name.name,
filename=junit_file_name_with_suffix)

back_link_to = f" with back link to {link_to_issue.key}" if link_to_issue else ""
logging.info(f"{'Updated' if use_existing_issue else 'Created'} Jira issue: {jira_issue.key} {back_link_to}"
Expand Down

0 comments on commit bbb7c2d

Please sign in to comment.