Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
change(jira-auth): change JIRA auth method to use PAT
Browse files Browse the repository at this point in the history
  • Loading branch information
tomassebestik committed Oct 24, 2023
1 parent 7d62cce commit cc2c87d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion sync_issues_to_jira/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,14 @@ The environment variables should be set in the GitHub Workflow:
- `JIRA_ISSUE_TYPE` (optional) the JIRA issue type for new issues. If unset, "Task" is used.
- `JIRA_COMPONENT` (optional) the name of a JIRA component to add to every issue which is synced from GitHub. The component must already exist in the JIRA project.

The following secrets should be set in the workflow:
The following secrets are needed for the workflow:

- `JIRA_URL` is the main JIRA URL (doesn't have to be secret).
- `JIRA_USER` is the JIRA username to log in with (JIRA basic auth)
- `JIRA_PASS` is the JIRA password to log in with (JIRA basic auth)

***IMPORTANT:** These secrets are inherited from the GitHub organizational secrets (as they are common to all Espressif GitHub projects) and should not be set at the repository level. (If set at the repository level, repo secrets take precedence over org secrets.)*

# Tests

test_sync_issue.py is a Python unittest framework that uses unittest.mock to create a mock JIRA API, then calls unit_test.py with various combinations of payloads similar to real GitHub Actions payloads.
Expand Down
11 changes: 10 additions & 1 deletion sync_issues_to_jira/sync_to_jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,16 @@ def main():

# Connect to Jira server
print('Connecting to Jira Server...')
jira = _JIRA(os.environ['JIRA_URL'], basic_auth=(os.environ['JIRA_USER'], os.environ['JIRA_PASS']))

# 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 ...")
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 ...")
jira = _JIRA(os.environ['JIRA_URL'], basic_auth=(os.environ['JIRA_USER'], token_or_pass))

# Check if it's a cron job
if os.environ.get('INPUT_CRON_JOB'):
Expand Down

0 comments on commit cc2c87d

Please sign in to comment.