Skip to content

Commit

Permalink
[AIRFLOW-207] Improve JIRA auth workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
jlowin committed Jun 2, 2016
1 parent f72b0d3 commit 5ccf224
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 28 deletions.
2 changes: 1 addition & 1 deletion dev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ origin https://github.com/<USER>/airflow (push)
```

#### JIRA
Users should set environment variables `JIRA_USERNAME` and `JIRA_PASSWORD` corresponding to their ASF JIRA login. This will allow the tool to automatically close issues.
Users should set environment variables `JIRA_USERNAME` and `JIRA_PASSWORD` corresponding to their ASF JIRA login. This will allow the tool to automatically close issues. If they are not set, the user will be prompted every time.

#### GitHub OAuth Token
Unauthenticated users can only make 60 requests/hour to the Github API. If you get an error about exceeding the rate, you will need to set a `GITHUB_OAUTH_KEY` environment variable that contains a token value. Users can generate tokens from their GitHub profile.
68 changes: 41 additions & 27 deletions dev/airflow-pr
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ except ImportError:
if sys.version_info[0] == 3:
raw_input = input

try:
import jira.client
JIRA_IMPORTED = True
except ImportError:
JIRA_IMPORTED = False

try:
import click
except ImportError:
Expand All @@ -63,10 +57,6 @@ AIRFLOW_GIT_LOCATION = os.environ.get("AIRFLOW_GIT", os.getcwd())
GITHUB_REMOTE_NAME = os.environ.get("GITHUB_REMOTE_NAME", "github")
# Remote name which points to Apache git
APACHE_REMOTE_NAME = os.environ.get("APACHE_REMOTE_NAME", "apache")
# ASF JIRA username
JIRA_USERNAME = os.environ.get("JIRA_USERNAME", "")
# ASF JIRA password
JIRA_PASSWORD = os.environ.get("JIRA_PASSWORD", "")
# OAuth key used for issuing requests against the GitHub API. If this is not defined, then requests
# will be unauthenticated. You should only need to configure this if you find yourself regularly
# exceeding your IP's unauthenticated request rate limit. You can create an OAuth key at
Expand Down Expand Up @@ -405,21 +395,41 @@ def resolve_jira_issue(comment=None, jira_id=None, merge_branches=None):
jira_id: an Airflow JIRA id, either an integer or a string with the form
AIRFLOW-X. If not provided, the user will be prompted to provide one.
"""
if merge_branches is None:
merge_branches = []

if JIRA_IMPORTED:
if not JIRA_USERNAME and not JIRA_PASSWORD:
raise PRToolError(
"JIRA_USERNAME and JIRA_PASSWORD not set; exiting.")
else:
try:
import jira.client
except ImportError:
raise PRToolError(
"Could not find jira-python library; exiting. Run "
"'sudo pip install jira' to install.")

asf_jira = jira.client.JIRA(
{'server': JIRA_API_BASE},
basic_auth=(JIRA_USERNAME, JIRA_PASSWORD))
if merge_branches is None:
merge_branches = []

# ASF JIRA username
JIRA_USERNAME = os.environ.get("JIRA_USERNAME", "")
# ASF JIRA password
JIRA_PASSWORD = os.environ.get("JIRA_PASSWORD", "")

if not JIRA_USERNAME:
JIRA_USERNAME = click.prompt(
click.style('Username for Airflow JIRA', fg='blue', bold=True),
type=str)
click.echo(
'Set the JIRA_USERNAME env var to avoid this prompt in the future.')
if not JIRA_PASSWORD:
JIRA_PASSWORD = click.prompt(
click.style('Password for Airflow JIRA', fg='blue', bold=True),
type=str,
hide_input=True)
click.echo(
'Set the JIRA_PASSWORD env var to avoid this prompt in the future.')

try:
asf_jira = jira.client.JIRA(
{'server': JIRA_API_BASE},
basic_auth=(JIRA_USERNAME, JIRA_PASSWORD))
except:
raise ValueError('Could not log in to JIRA!')

if jira_id is None:
jira_id = click.prompt(click.style(
Expand Down Expand Up @@ -618,10 +628,12 @@ def main(pr_num, local=False):
Apache git remote name (defaults to "apache")
- JIRA_USERNAME
ASF JIRA username. Required to automatically close JIRA issues
ASF JIRA username for automatically closing JIRA issues. Users will be
prompted if it is not set.
- JIRA_PASSWORD
ASF JIRA password. Required to automatically close JIRA issues
ASF JIRA password for automatically closing JIRA issues. Users will be
prompted if it is not set.
- GITHUB_OAUTH_KEY
Only required if you are exceeding the rate limit for a single IP
Expand Down Expand Up @@ -719,8 +731,8 @@ def main(pr_num, local=False):
if local:
return

pick_prompt = "Would you like to pick %s into another branch?" % merge_hash
while click.confirm(click.style("pick_prompt", fg='blue', bold=True)):
msg = "Would you like to pick {} into another branch?".format(merge_hash)
while click.confirm(click.style(msg, fg='blue', bold=True)):
merged_refs = merged_refs + [cherry_pick(pr_num, merge_hash, latest_branch)]

continue_maybe("Would you like to update associated JIRA issues?")
Expand Down Expand Up @@ -787,10 +799,12 @@ def merge(pr_num):
Apache git remote name (defaults to "apache")
- JIRA_USERNAME
ASF JIRA username. Required to automatically close JIRA issues
ASF JIRA username for automatically closing JIRA issues. Users will be
prompted if it is not set.
- JIRA_PASSWORD
ASF JIRA password. Required to automatically close JIRA issues
ASF JIRA password for automatically closing JIRA issues. Users will be
prompted if it is not set.
- GITHUB_OAUTH_KEY
Only required if you are exceeding the rate limit for a single IP
Expand Down

0 comments on commit 5ccf224

Please sign in to comment.