@@ -96,7 +96,7 @@ def authorize(self, login, password, scopes, note='', note_url=''):
9696if isinstance (scopes ,list )and auth :
9797url = self ._build_url ('authorizations' )
9898data = dumps ({'scopes' :scopes ,'note' :note ,
99- 'note_url' :note_url })
99+ 'note_url' :note_url })
100100if self ._session .auth :
101101json = self ._json (self ._post (url ,data = data ),201 )
102102else :
@@ -120,20 +120,20 @@ def create_gist(self, description, files, public=True):
120120 :returns: :class:`Gist <github3.gists.Gist>`
121121 """
122122new_gist = {'description' :description ,'public' :public ,
123- 'files' :files }
123+ 'files' :files }
124124url = self ._build_url ('gists' )
125125json = self ._json (self ._post (url ,dumps (new_gist )),201 )
126126return Gist (json ,self )if json else None
127127
128128@requires_auth
129129def 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 = []):
137137"""Create an issue on the project 'repository' owned by 'owner'
138138 with title 'title'.
139139
@@ -191,15 +191,15 @@ def create_key(self, title, key):
191191
192192@requires_auth
193193def 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 = '' ):
203203"""Create a repository for the authenticated user.
204204
205205 :param str name: (required), name of the repository
@@ -222,10 +222,10 @@ def create_repo(self,
222222 """
223223url = self ._build_url ('user' ,'repos' )
224224data = 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 })
229229json = self ._json (self ._post (url ,data ),201 )
230230return Repository (json ,self )if json else None
231231
@@ -444,7 +444,7 @@ def iter_notifications(self, all=False, participating=False, number=-1):
444444
445445@requires_auth
446446def iter_org_issues (self ,name ,filter = '' ,state = '' ,labels = '' ,sort = '' ,
447- direction = '' ,since = '' ,number = - 1 ):
447+ direction = '' ,since = '' ,number = - 1 ):
448448"""Iterate over the organnization's issues if the authenticated user
449449 belongs to it.
450450
@@ -472,7 +472,7 @@ def iter_org_issues(self, name, filter='', state='', labels='', sort='',
472472
473473@requires_auth
474474def iter_issues (self ,filter = '' ,state = '' ,labels = '' ,sort = '' ,
475- direction = '' ,since = '' ,number = - 1 ):
475+ direction = '' ,since = '' ,number = - 1 ):
476476"""List all of the authenticated user's (and organization's) issues.
477477
478478 :param str filter: accepted values:
@@ -498,7 +498,7 @@ def iter_issues(self, filter='', state='', labels='', sort='',
498498
499499@requires_auth
500500def iter_user_issues (self ,filter = '' ,state = '' ,labels = '' ,sort = '' ,
501- direction = '' ,since = '' ,number = - 1 ):
501+ direction = '' ,since = '' ,number = - 1 ):
502502"""List only the authenticated user's issues. Will not list
503503 organization's issues
504504
@@ -524,8 +524,8 @@ def iter_user_issues(self, filter='', state='', labels='', sort='',
524524return self ._iter (int (number ),url ,Issue ,params = params )
525525
526526def 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 ):
529529"""List issues on owner/repository. Only owner and repository are
530530 required.
531531
@@ -552,7 +552,7 @@ def iter_repo_issues(self, owner, repository, milestone=None,
552552if owner and repository :
553553repo = self .repository (owner ,repository )
554554return repo .iter_issues (milestone ,state ,assignee ,mentioned ,
555- labels ,sort ,direction ,since ,number )
555+ labels ,sort ,direction ,since ,number )
556556return self ._iter (0 ,'' ,type )
557557
558558@requires_auth
@@ -585,7 +585,7 @@ def iter_orgs(self, login=None, number=-1):
585585return self ._iter (int (number ),url ,Organization )
586586
587587def iter_repos (self ,login = None ,type = '' ,sort = '' ,direction = '' ,
588- number = - 1 ):
588+ number = - 1 ):
589589"""List public repositories for the specified ``login`` or all
590590 repositories for the authenticated user if ``login`` is not
591591 provided.
@@ -668,8 +668,7 @@ def login(self, username=None, password=None, token=None):
668668self ._session .auth = (username ,password )
669669elif token :
670670self ._session .headers .update ({
671- 'Authorization' :'token ' + token
672- })
671+ 'Authorization' :'token ' + token })
673672
674673def markdown (self ,text ,mode = '' ,context = '' ,raw = False ):
675674"""Render an arbitrary markdown document.
@@ -771,7 +770,7 @@ def search_issues(self, owner, repo, state, keyword):
771770 :returns: list of :class:`LegacyIssue <github3.legacy.LegacyIssue>`\ s
772771 """
773772url = self ._build_url ('legacy' ,'issues' ,'search' ,owner ,repo ,
774- state ,keyword )
773+ state ,keyword )
775774json = self ._json (self ._get (url ),200 )
776775issues = json .get ('issues' , [])
777776return [LegacyIssue (l ,self )for l in issues ]
@@ -899,7 +898,7 @@ def unsubscribe(self, login, repo):
899898
900899@requires_auth
901900def 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 ):
903902"""If authenticated as this user, update the information with
904903 the information provided in the parameters. All parameters are
905904 optional.
@@ -922,7 +921,7 @@ def update_user(self, name=None, email=None, blog=None,
922921 """
923922user = self .user ()
924923return user .update (name ,email ,blog ,company ,location ,hireable ,
925- bio )
924+ bio )
926925
927926def user (self ,login = None ):
928927"""Returns a User object for the specified login name if
@@ -948,3 +947,34 @@ def watch(self, login, repo):
948947def unwatch (self ,login ,repo ):
949948"""DEPRECATED: Use unsubscribe/unstar instead."""
950949raise 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