mirror of
https://github.com/kennethreitz/python-github3.git
synced 2026-06-05 23:10:17 +00:00
setup github object from git config values
This commit is contained in:
@@ -11,9 +11,13 @@ __version__ = '0.0.0'
|
||||
__license__ = 'MIT'
|
||||
__author__ = 'Kenneth Reitz'
|
||||
|
||||
|
||||
import envoy
|
||||
|
||||
from .api import Github, settings
|
||||
|
||||
|
||||
|
||||
def no_auth():
|
||||
"""Returns an un-authenticated Github object."""
|
||||
|
||||
@@ -33,4 +37,25 @@ def basic_auth(username, password):
|
||||
gh.is_authenticated = True
|
||||
gh._requests_pre_hook = enable_auth
|
||||
|
||||
return gh
|
||||
|
||||
|
||||
|
||||
def git_config():
|
||||
"""Returns an authenticated Github object, via HTTP Basic.
|
||||
|
||||
GitHub API token is taken from `git config`.
|
||||
"""
|
||||
|
||||
username = envoy.run('git config github.user').std_out.strip()
|
||||
token = envoy.run('git config github.token').std_out.strip()
|
||||
|
||||
def enable_auth(*args, **kwargs):
|
||||
kwargs['auth'] = (username, token)
|
||||
return args, kwargs
|
||||
|
||||
gh = Github()
|
||||
gh.is_authenticated = True
|
||||
gh._requests_pre_hook = enable_auth
|
||||
|
||||
return gh
|
||||
Reference in New Issue
Block a user