setup github object from git config values

This commit is contained in:
Kenneth Reitz
2011-08-27 14:44:19 -04:00
parent 3cbc11f827
commit 640c35e943
+25
View File
@@ -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