def _instantiate_github(username):
"""
Gets a github object that has been authenticated.
If authentication fails it asks the user for their
password agains
:param unicode username:
:rtype: Github
"""
password = get_github_password(username)
count = 0
while True:
count += 1
github = Github(login_or_token=username, password=password)
try:
auth = github.get_user().create_authorization(
scopes=['repo'],
note='github-reviewboard-sync {0}'.format(str(uuid4())))
return github, auth
except BadCredentialsException as exc:
_LOG.error('The password was not valid for "{0}"'.format(username))
if count == 3:
raise AuthenticationException('Failed to authenticate three times. '
'Is "{0}" the correct username?'.format(username))
password = get_github_password(username, refresh=True)
except TwoFactorException as exc:
user = github.get_user()
onetime_password =input('Github 2-Factor code: ')
authorization = user.create_authorization(
scopes=['repo'],
note='github-reviewboard-sync {0}'.format(str(uuid4())),
onetime_password=onetime_password)
return Github(authorization.token), authorization
pullrequest.py 文件源码
python
阅读 21
收藏 0
点赞 0
评论 0
评论列表
文章目录