Skip to content

Commit 640c35e

Browse files
author
Kenneth Reitz
committed
setup github object from git config values
1 parent 3cbc11f commit 640c35e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

github3/core.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@
1111
__license__ = 'MIT'
1212
__author__ = 'Kenneth Reitz'
1313

14+
15+
import envoy
16+
1417
from .api import Github, settings
1518

1619

20+
1721
def no_auth():
1822
"""Returns an un-authenticated Github object."""
1923

@@ -33,4 +37,25 @@ def enable_auth(*args, **kwargs):
3337
gh.is_authenticated = True
3438
gh._requests_pre_hook = enable_auth
3539

40+
return gh
41+
42+
43+
44+
def git_config():
45+
"""Returns an authenticated Github object, via HTTP Basic.
46+
47+
GitHub API token is taken from `git config`.
48+
"""
49+
50+
username = envoy.run('git config github.user').std_out.strip()
51+
token = envoy.run('git config github.token').std_out.strip()
52+
53+
def enable_auth(*args, **kwargs):
54+
kwargs['auth'] = (username, token)
55+
return args, kwargs
56+
57+
gh = Github()
58+
gh.is_authenticated = True
59+
gh._requests_pre_hook = enable_auth
60+
3661
return gh

0 commit comments

Comments
 (0)