From e621f44bd2090c1e06f8b628e81dc864d7d62559 Mon Sep 17 00:00:00 2001 From: Tomas Sebestik Date: Fri, 6 Sep 2024 13:41:58 +0200 Subject: [PATCH] change(action-log): specifics (json response, JQL query) print only in debug mode --- sync_jira_actions/sync_issue.py | 7 ++++++- sync_jira_actions/sync_pr.py | 1 + sync_jira_actions/sync_to_jira.py | 21 ++++++++++++--------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/sync_jira_actions/sync_issue.py b/sync_jira_actions/sync_issue.py index 9d09959..6e32992 100755 --- a/sync_jira_actions/sync_issue.py +++ b/sync_jira_actions/sync_issue.py @@ -45,6 +45,7 @@ def handle_issue_opened(jira, event): print('Creating new JIRA issue for new GitHub issue') _create_jira_issue(jira, event['issue']) + print(f'✔️ Successfully synchronized new GitHub issue #{gh_issue["number"]} to JIRA issue {issue.key}') def handle_issue_edited(jira, event): @@ -134,6 +135,7 @@ def handle_comment_created(jira, event): jira_issue = _find_jira_issue(jira, event['issue'], True) jira.add_comment(jira_issue.id, _get_jira_comment_body(gh_comment)) + print(f'✔️ Successfully synchronized comment for JIRA issue {jira_issue.key}') def handle_comment_edited(jira, event): @@ -153,6 +155,7 @@ def handle_comment_edited(jira, event): if not found: # if we didn't find the old comment, make a new comment about the edit jira.add_comment(jira_issue.id, _get_jira_comment_body(gh_comment)) + print(f'✔️ Successfully synchronized edited comment for JIRA issue {jira_issue.key}') def handle_comment_deleted(jira, event): @@ -161,6 +164,7 @@ def handle_comment_deleted(jira, event): jira.add_comment( jira_issue.id, f"@{gh_comment['user']['login']} deleted [GitHub issue comment|{gh_comment['html_url']}]" ) + print(f'✔️ Successfully synchronized deleted comment for JIRA issue {jira_issue.key}') # Works both for issues and pull requests @@ -446,7 +450,8 @@ def _find_jira_issue(jira, gh_issue, make_new=False, retries=5): """ url = gh_issue['html_url'] jql_query = f'issue in issuesWithRemoteLinksByGlobalId("{url}") order by updated desc' - print(f'JQL query: {jql_query}') + if os.environ.get('ACTIONS_RUNNER_DEBUG') == 'true': + print(f'JQL query: {jql_query}') # Print the JQL query only in debug mode res = jira.search_issues(jql_query) if not res: print(f"WARNING: No JIRA issues have a remote link with globalID '{url}'") diff --git a/sync_jira_actions/sync_pr.py b/sync_jira_actions/sync_pr.py index 9474067..5b11e67 100755 --- a/sync_jira_actions/sync_pr.py +++ b/sync_jira_actions/sync_pr.py @@ -44,3 +44,4 @@ def sync_remain_prs(jira): issue = _find_jira_issue(jira, gh_issue) if issue is None: _create_jira_issue(jira, gh_issue) + print(f'✔️ Successfully synchronized PR #{pr.number} to JIRA issue {issue.key}') diff --git a/sync_jira_actions/sync_to_jira.py b/sync_jira_actions/sync_to_jira.py index 607990a..d3c9ed4 100755 --- a/sync_jira_actions/sync_to_jira.py +++ b/sync_jira_actions/sync_to_jira.py @@ -40,16 +40,16 @@ def applicationlinks(self): def main(): if 'GITHUB_REPOSITORY' not in os.environ: - print('Not running in GitHub action context, nothing to do') + print('❌ Not running in GitHub action context, nothing to do') return if not os.environ['GITHUB_REPOSITORY'].startswith('espressif/'): - print('Not an Espressif repo, nothing to sync to JIRA') + print('❌ Not an Espressif repo, nothing to sync to JIRA') return # For backward compatibility; handles situation if JIRA_PROJECT is not set in caller workflow either as input or ENV if 'JIRA_PROJECT' not in os.environ: - print('JIRA_PROJECT not set, fail!') + print('❌ JIRA_PROJECT not set, fail!') raise SystemExit(1) # Connect to Jira server @@ -58,11 +58,13 @@ def main(): # Check if the JIRA_PASS is token or password token_or_pass = os.environ['JIRA_PASS'] if token_or_pass.startswith('token:'): - print('Authenticating with JIRA_TOKEN ...') + if os.environ.get('ACTIONS_RUNNER_DEBUG') == 'true': + print('Authenticating with JIRA_TOKEN ...') token = token_or_pass[6:] # Strip the 'token:' prefix jira = _JIRA(os.environ['JIRA_URL'], token_auth=token) else: - print('Authenticating with JIRA_USER and JIRA_PASS ...') + if os.environ.get('ACTIONS_RUNNER_DEBUG') == 'true': + print('Authenticating with JIRA_USER and JIRA_PASS ...') jira = _JIRA(os.environ['JIRA_URL'], basic_auth=(os.environ['JIRA_USER'], token_or_pass)) # Check if it's a cron job @@ -74,7 +76,8 @@ def main(): # The path of the file with the complete webhook event payload. For example, /github/workflow/event.json. with open(os.environ['GITHUB_EVENT_PATH'], 'r', encoding='utf-8') as file: event = json.load(file) - print(json.dumps(event, indent=4)) + if os.environ.get('ACTIONS_RUNNER_DEBUG') == 'true': + print(json.dumps(event, indent=4)) event_name = os.environ['GITHUB_EVENT_NAME'] @@ -84,16 +87,16 @@ def main(): inputs = event.get('inputs') if not inputs: - print('Triggered workflow_dispatch event without correct inputs. Exiting...') + print('❌ Triggered workflow_dispatch event without correct inputs. Exiting...') return input_action = inputs.get('action') issue_numbers = inputs.get('issue-numbers') if input_action != 'mirror-issues': - print('This action needs input "mirror-issues". Exiting...') + print('❌ This action needs input "mirror-issues". Exiting...') return if not issue_numbers: - print('This action needs inputs "issue-numbers". Exiting...') + print('❌ This action needs inputs "issue-numbers". Exiting...') return print(f'Starting manual sync of issues: {issue_numbers}')