@@ -96,7 +96,7 @@ def authorize(self, login, password, scopes, note='', note_url=''):
96
96
if isinstance (scopes ,list )and auth :
97
97
url = self ._build_url ('authorizations' )
98
98
data = dumps ({'scopes' :scopes ,'note' :note ,
99
- 'note_url' :note_url })
99
+ 'note_url' :note_url })
100
100
if self ._session .auth :
101
101
json = self ._json (self ._post (url ,data = data ),201 )
102
102
else :
@@ -120,20 +120,20 @@ def create_gist(self, description, files, public=True):
120
120
:returns: :class:`Gist <github3.gists.Gist>`
121
121
"""
122
122
new_gist = {'description' :description ,'public' :public ,
123
- 'files' :files }
123
+ 'files' :files }
124
124
url = self ._build_url ('gists' )
125
125
json = self ._json (self ._post (url ,dumps (new_gist )),201 )
126
126
return Gist (json ,self )if json else None
127
127
128
128
@requires_auth
129
129
def create_issue (self ,
130
- owner ,
131
- repository ,
132
- title ,
133
- body = None ,
134
- assignee = None ,
135
- milestone = None ,
136
- labels = []):
130
+ owner ,
131
+ repository ,
132
+ title ,
133
+ body = None ,
134
+ assignee = None ,
135
+ milestone = None ,
136
+ labels = []):
137
137
"""Create an issue on the project 'repository' owned by 'owner'
138
138
with title 'title'.
139
139
@@ -191,15 +191,15 @@ def create_key(self, title, key):
191
191
192
192
@requires_auth
193
193
def create_repo (self ,
194
- name ,
195
- description = '' ,
196
- homepage = '' ,
197
- private = False ,
198
- has_issues = True ,
199
- has_wiki = True ,
200
- has_downloads = True ,
201
- auto_init = False ,
202
- gitignore_template = '' ):
194
+ name ,
195
+ description = '' ,
196
+ homepage = '' ,
197
+ private = False ,
198
+ has_issues = True ,
199
+ has_wiki = True ,
200
+ has_downloads = True ,
201
+ auto_init = False ,
202
+ gitignore_template = '' ):
203
203
"""Create a repository for the authenticated user.
204
204
205
205
:param str name: (required), name of the repository
@@ -222,10 +222,10 @@ def create_repo(self,
222
222
"""
223
223
url = self ._build_url ('user' ,'repos' )
224
224
data = dumps ({'name' :name ,'description' :description ,
225
- 'homepage' :homepage ,'private' :private ,
226
- 'has_issues' :has_issues ,'has_wiki' :has_wiki ,
227
- 'has_downloads' :has_downloads ,'auto_init' :auto_init ,
228
- 'gitignore_template' :gitignore_template })
225
+ 'homepage' :homepage ,'private' :private ,
226
+ 'has_issues' :has_issues ,'has_wiki' :has_wiki ,
227
+ 'has_downloads' :has_downloads ,'auto_init' :auto_init ,
228
+ 'gitignore_template' :gitignore_template })
229
229
json = self ._json (self ._post (url ,data ),201 )
230
230
return Repository (json ,self )if json else None
231
231
@@ -444,7 +444,7 @@ def iter_notifications(self, all=False, participating=False, number=-1):
444
444
445
445
@requires_auth
446
446
def iter_org_issues (self ,name ,filter = '' ,state = '' ,labels = '' ,sort = '' ,
447
- direction = '' ,since = '' ,number = - 1 ):
447
+ direction = '' ,since = '' ,number = - 1 ):
448
448
"""Iterate over the organnization's issues if the authenticated user
449
449
belongs to it.
450
450
@@ -472,7 +472,7 @@ def iter_org_issues(self, name, filter='', state='', labels='', sort='',
472
472
473
473
@requires_auth
474
474
def iter_issues (self ,filter = '' ,state = '' ,labels = '' ,sort = '' ,
475
- direction = '' ,since = '' ,number = - 1 ):
475
+ direction = '' ,since = '' ,number = - 1 ):
476
476
"""List all of the authenticated user's (and organization's) issues.
477
477
478
478
:param str filter: accepted values:
@@ -498,7 +498,7 @@ def iter_issues(self, filter='', state='', labels='', sort='',
498
498
499
499
@requires_auth
500
500
def iter_user_issues (self ,filter = '' ,state = '' ,labels = '' ,sort = '' ,
501
- direction = '' ,since = '' ,number = - 1 ):
501
+ direction = '' ,since = '' ,number = - 1 ):
502
502
"""List only the authenticated user's issues. Will not list
503
503
organization's issues
504
504
@@ -524,8 +524,8 @@ def iter_user_issues(self, filter='', state='', labels='', sort='',
524
524
return self ._iter (int (number ),url ,Issue ,params = params )
525
525
526
526
def iter_repo_issues (self ,owner ,repository ,milestone = None ,
527
- state = '' ,assignee = '' ,mentioned = '' ,labels = '' , sort = '' , direction = '' ,
528
- since = '' ,number = - 1 ):
527
+ state = '' ,assignee = '' ,mentioned = '' ,labels = '' ,
528
+ sort = '' , direction = '' , since = '' ,number = - 1 ):
529
529
"""List issues on owner/repository. Only owner and repository are
530
530
required.
531
531
@@ -552,7 +552,7 @@ def iter_repo_issues(self, owner, repository, milestone=None,
552
552
if owner and repository :
553
553
repo = self .repository (owner ,repository )
554
554
return repo .iter_issues (milestone ,state ,assignee ,mentioned ,
555
- labels ,sort ,direction ,since ,number )
555
+ labels ,sort ,direction ,since ,number )
556
556
return self ._iter (0 ,'' ,type )
557
557
558
558
@requires_auth
@@ -585,7 +585,7 @@ def iter_orgs(self, login=None, number=-1):
585
585
return self ._iter (int (number ),url ,Organization )
586
586
587
587
def iter_repos (self ,login = None ,type = '' ,sort = '' ,direction = '' ,
588
- number = - 1 ):
588
+ number = - 1 ):
589
589
"""List public repositories for the specified ``login`` or all
590
590
repositories for the authenticated user if ``login`` is not
591
591
provided.
@@ -668,8 +668,7 @@ def login(self, username=None, password=None, token=None):
668
668
self ._session .auth = (username ,password )
669
669
elif token :
670
670
self ._session .headers .update ({
671
- 'Authorization' :'token ' + token
672
- })
671
+ 'Authorization' :'token ' + token })
673
672
674
673
def markdown (self ,text ,mode = '' ,context = '' ,raw = False ):
675
674
"""Render an arbitrary markdown document.
@@ -771,7 +770,7 @@ def search_issues(self, owner, repo, state, keyword):
771
770
:returns: list of :class:`LegacyIssue <github3.legacy.LegacyIssue>`\ s
772
771
"""
773
772
url = self ._build_url ('legacy' ,'issues' ,'search' ,owner ,repo ,
774
- state ,keyword )
773
+ state ,keyword )
775
774
json = self ._json (self ._get (url ),200 )
776
775
issues = json .get ('issues' , [])
777
776
return [LegacyIssue (l ,self )for l in issues ]
@@ -899,7 +898,7 @@ def unsubscribe(self, login, repo):
899
898
900
899
@requires_auth
901
900
def update_user (self ,name = None ,email = None ,blog = None ,
902
- company = None ,location = None ,hireable = False ,bio = None ):
901
+ company = None ,location = None ,hireable = False ,bio = None ):
903
902
"""If authenticated as this user, update the information with
904
903
the information provided in the parameters. All parameters are
905
904
optional.
@@ -922,7 +921,7 @@ def update_user(self, name=None, email=None, blog=None,
922
921
"""
923
922
user = self .user ()
924
923
return user .update (name ,email ,blog ,company ,location ,hireable ,
925
- bio )
924
+ bio )
926
925
927
926
def user (self ,login = None ):
928
927
"""Returns a User object for the specified login name if
@@ -948,3 +947,34 @@ def watch(self, login, repo):
948
947
def unwatch (self ,login ,repo ):
949
948
"""DEPRECATED: Use unsubscribe/unstar instead."""
950
949
raise DeprecationWarning ('Use unsubscribe/unstar instead.' )
950
+
951
+
952
+ class GitHubEnterprise (GitHub ):
953
+ """For GitHub Enterprise users, this object will act as the public API to
954
+ your instance. You must provide the URL to your instance upon
955
+ initializaiton and can provide the rest of the login details just like in
956
+ the :class:`GitHub <GitHub>` object.
957
+
958
+ There is no need to provide the end of the url (e.g., /api/v3/), that will
959
+ be taken care of by us.
960
+ """
961
+ def __init__ (self ,url ,login = '' ,password = '' ,token = '' ):
962
+ super (GitHubEnterprise ,self ).__init__ (login ,password ,token )
963
+ self ._github_url = url .rstrip ('/' )+ '/api/v3'
964
+
965
+ @requires_auth
966
+ def admin_stats (self ,option ):
967
+ """This is a simple way to get statistics about your system.
968
+
969
+ :param str option: (required), accepted values: ('all', 'repos',
970
+ 'hooks', 'pages', 'orgs', 'users', 'pulls', 'issues',
971
+ 'milestones', 'gists', 'comments')
972
+ :returns: dict
973
+ """
974
+ stats = {}
975
+ if option .lower ()in ('all' ,'repos' ,'hooks' ,'pages' ,'orgs' ,
976
+ 'users' ,'pulls' ,'issues' ,'milestones' ,
977
+ 'gists' ,'comments' ):
978
+ url = self ._build_url ('enterprise' ,'stats' ,option .lower ())
979
+ stats = self ._json (self ._get (url ),200 )
980
+ return stats