Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions bin/github-pr-stats
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ from github3 import GitHub, GitHubEnterprise
from github_pr_stats import VERSION
from github_pr_stats.github_pr_stats import analyze

try:
# Python 2
prompt = raw_input
except NameError:
# Python 3
prompt = input

def two_factor_prompt():
code = ''
while not code:
# The user could accidentally press Enter before being ready,
# let's protect them from doing that.
code = prompt('Enter 2FA code: ')
return code

def authorize(login, password, scopes, note='', note_url='', client_id='',
client_secret='', url=None):
"""Obtain an authorization token for the GitHub API.
Expand All @@ -67,6 +82,7 @@ def authorize(login, password, scopes, note='', note_url='', client_id='',

"""
gh = GitHubEnterprise(url) if url is not None else GitHub()
gh.login(username=login, password=password, two_factor_callback=two_factor_prompt)
return gh.authorize(login, password, scopes, note, note_url, client_id, client_secret)

# Stack traces are ugly; why would we want to print one on ctrl-c?
Expand Down