Skip to content

Commit

Permalink
change(action-log): specifics (json response, JQL query) print only i…
Browse files Browse the repository at this point in the history
…n debug mode
  • Loading branch information
tomassebestik committed Sep 6, 2024
1 parent 8c43b5b commit e621f44
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
7 changes: 6 additions & 1 deletion sync_jira_actions/sync_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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}'")
Expand Down
1 change: 1 addition & 0 deletions sync_jira_actions/sync_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
21 changes: 12 additions & 9 deletions sync_jira_actions/sync_to_jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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']

Expand All @@ -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}')
Expand Down

0 comments on commit e621f44

Please sign in to comment.