Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9a1905f

Browse files
committed
Add support for GitHub Enterprise.
I don't know why I didn't think of adding this before, but now any companiesthat need it have it accessible. Thanks to@pengwynn and@watsonian for theirhelp.
1 parentb444ee0 commit9a1905f

File tree

4 files changed

+89
-39
lines changed

4 files changed

+89
-39
lines changed

‎docs/api.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,23 @@ Or you can simply use the following functions
8282
------
8383

8484
..autofunction::github3.ratelimit_remaining
85+
86+
------
87+
88+
Enterprise Use
89+
--------------
90+
91+
If you're using github3.py to interact with an enterprise installation of
92+
GitHub, you must use the
93+
:class:`GitHubEnterprise <github3.github.GitHubEnterprise>` object. Upon
94+
initialization, the only parameter you must supply is the URL of your
95+
enterprise installation, e.g.
96+
97+
::
98+
99+
from github import GitHubEnterprise
100+
101+
g = GitHubEnterprise('https://github.examplesintl.com')
102+
stats = g.admin_stats('all')
103+
assert 'issues' in stats, ('Key issues is not included in the admin'
104+
'statistics')

‎github3/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
"""
99

10-
from .githubimportGitHub
10+
from .githubimportGitHub,GitHubEnterprise# NOQA
1111

1212
gh=GitHub()
1313

@@ -70,12 +70,12 @@ def list_following(username):
7070

7171

7272
deflist_repo_issues(owner,repository,filter='',state='',labels='',
73-
sort='',direction='',since=''):
73+
sort='',direction='',since=''):
7474
"""See :func:`github3.github.GitHub.list_issues`"""
7575
issues= []
7676
ifownerandrepository:
7777
issues=gh.list_repo_issues(owner,repository,filter,state,labels,
78-
sort,direction,since)
78+
sort,direction,since)
7979
returnissues
8080

8181

‎github3/github.py

Lines changed: 64 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def authorize(self, login, password, scopes, note='', note_url=''):
9696
ifisinstance(scopes,list)andauth:
9797
url=self._build_url('authorizations')
9898
data=dumps({'scopes':scopes,'note':note,
99-
'note_url':note_url})
99+
'note_url':note_url})
100100
ifself._session.auth:
101101
json=self._json(self._post(url,data=data),201)
102102
else:
@@ -120,20 +120,20 @@ def create_gist(self, description, files, public=True):
120120
:returns: :class:`Gist <github3.gists.Gist>`
121121
"""
122122
new_gist= {'description':description,'public':public,
123-
'files':files}
123+
'files':files}
124124
url=self._build_url('gists')
125125
json=self._json(self._post(url,dumps(new_gist)),201)
126126
returnGist(json,self)ifjsonelseNone
127127

128128
@requires_auth
129129
defcreate_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
193193
defcreate_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
"""
223223
url=self._build_url('user','repos')
224224
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})
229229
json=self._json(self._post(url,data),201)
230230
returnRepository(json,self)ifjsonelseNone
231231

@@ -444,7 +444,7 @@ def iter_notifications(self, all=False, participating=False, number=-1):
444444

445445
@requires_auth
446446
defiter_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
474474
defiter_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
500500
defiter_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='',
524524
returnself._iter(int(number),url,Issue,params=params)
525525

526526
defiter_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,
552552
ifownerandrepository:
553553
repo=self.repository(owner,repository)
554554
returnrepo.iter_issues(milestone,state,assignee,mentioned,
555-
labels,sort,direction,since,number)
555+
labels,sort,direction,since,number)
556556
returnself._iter(0,'',type)
557557

558558
@requires_auth
@@ -585,7 +585,7 @@ def iter_orgs(self, login=None, number=-1):
585585
returnself._iter(int(number),url,Organization)
586586

587587
defiter_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):
668668
self._session.auth= (username,password)
669669
eliftoken:
670670
self._session.headers.update({
671-
'Authorization':'token '+token
672-
})
671+
'Authorization':'token '+token})
673672

674673
defmarkdown(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
"""
773772
url=self._build_url('legacy','issues','search',owner,repo,
774-
state,keyword)
773+
state,keyword)
775774
json=self._json(self._get(url),200)
776775
issues=json.get('issues', [])
777776
return [LegacyIssue(l,self)forlinissues]
@@ -899,7 +898,7 @@ def unsubscribe(self, login, repo):
899898

900899
@requires_auth
901900
defupdate_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
"""
923922
user=self.user()
924923
returnuser.update(name,email,blog,company,location,hireable,
925-
bio)
924+
bio)
926925

927926
defuser(self,login=None):
928927
"""Returns a User object for the specified login name if
@@ -948,3 +947,34 @@ def watch(self, login, repo):
948947
defunwatch(self,login,repo):
949948
"""DEPRECATED: Use unsubscribe/unstar instead."""
950949
raiseDeprecationWarning('Use unsubscribe/unstar instead.')
950+
951+
952+
classGitHubEnterprise(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+
defadmin_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+
ifoption.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+
returnstats

‎github3/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def __init__(self, json, ses=None):
7474
self._github_url='https://api.github.com'
7575
self._remaining=5000
7676
self._rel_reg=compile(r'<(https://[0-9a-zA-Z\./\?=&]+)>; '
77-
'rel="(\w+)"')
77+
'rel="(\w+)"')
7878

7979
def__repr__(self):
8080
return'<github3-core at 0x{0:x}>'.format(id(self))
@@ -234,7 +234,7 @@ def edit(self, body):
234234
"""
235235
ifbody:
236236
json=self._json(self._patch(self._api,
237-
data=dumps({'body':body})),200)
237+
data=dumps({'body':body})),200)
238238
ifjson:
239239
self._update_(json)
240240
returnTrue

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp