diff options
author | 2011-08-27 14:44:19 -0400 | |
---|---|---|
committer | 2011-08-27 14:44:19 -0400 | |
commit | 640c35e94368d7d3b4d226dab6c2d0cb5f152ced (patch) | |
tree | 24f7e3cbc6b773e0af88ccbedfeb07814212abd9 /github3/core.py | |
parent | require envoy (diff) | |
download | python-github3-640c35e94368d7d3b4d226dab6c2d0cb5f152ced.tar.xz python-github3-640c35e94368d7d3b4d226dab6c2d0cb5f152ced.zip |
setup github object from git config values
Diffstat (limited to 'github3/core.py')
-rw-r--r-- | github3/core.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/github3/core.py b/github3/core.py index 725d09d..0a338c7 100644 --- a/github3/core.py +++ b/github3/core.py @@ -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
\ No newline at end of file |