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

Commitc55b4b9

Browse files
committed
Update to avoid /teams deprecation
GitHub deprecated the top-level /teams API in 2020 and is starting torun brown-outs with the goal of removing on March 15.Closessigmavirus24#1080
1 parent38b6f88 commitc55b4b9

17 files changed

+130
-81
lines changed

‎docs/source/release-notes/3.2.0.rst

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
3.2.0: 2022-xx-xx
1+
3.2.0: 2022-03-02
22
-----------------
33

4-
Dependency Change
5-
`````````````````
6-
4+
Bug Fixes
5+
`````````
76

8-
Features Added
9-
``````````````
7+
- Migrate to GitHub's supported Teams endpoints for select methods that were
8+
relying on the deprecated endpoints. See alsogh-1080_
109

1110

12-
Bug Fixes
13-
`````````
11+
.. _gh-1080:
12+
https://github.com/sigmavirus24/github3.py/issues/1080

‎src/github3/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
__author_email__="graffatcolmingov@gmail.com"
66
__license__="Modified BSD"
77
__copyright__="Copyright 2012-2022 Ian Stapleton Cordasco"
8-
__version__="3.1.2"
8+
__version__="3.2.0"
99
__version_info__=tuple(
1010
int(i)foriin__version__.split(".")ifi.isdigit()
1111
)

‎src/github3/models.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
"""This module provides the basic models used in github3.py."""
22
importjsonasjsonlib
33
importlogging
4+
importtypingast
45

56
importdateutil.parser
67
importrequests.compat
78

89
from .importexceptions
910
from .importsession
1011

12+
13+
ift.TYPE_CHECKING:
14+
from .importstructs
15+
1116
LOG=logging.getLogger(__package__)
1217

1318

19+
T=t.TypeVar("T")
20+
21+
1422
classGitHubCore:
1523
"""The base object for all objects that require a session.
1624
@@ -20,9 +28,9 @@ class GitHubCore:
2028
"""
2129

2230
_ratelimit_resource="core"
23-
_refresh_to=None
31+
_refresh_to:t.Optional["GitHubCore"]=None
2432

25-
def__init__(self,json,session):
33+
def__init__(self,json,session:session.GitHubSession):
2634
"""Initialize our basic object.
2735
2836
Pretty much every object will pass in decoded JSON and a Session.
@@ -244,14 +252,14 @@ def _api(self, uri):
244252

245253
def_iter(
246254
self,
247-
count,
248-
url,
249-
cls,
250-
params=None,
251-
etag=None,
252-
headers=None,
253-
list_key=None,
254-
):
255+
count:int,
256+
url:str,
257+
cls:t.Type[T],
258+
params:t.Optional[t.Mapping[str,t.Optional[str]]]=None,
259+
etag:t.Optional[str]=None,
260+
headers:t.Optional[t.Mapping[str,str]]=None,
261+
list_key:t.Optional[str]=None,
262+
)->"structs.GitHubIterator[T]":
255263
"""Generic iterator for this project.
256264
257265
:param int count: How many items to return.

‎src/github3/orgs.py

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def edit(
144144
bool
145145
"""
146146
ifname:
147-
data= {"name":name}
147+
data:t.Dict[str,t.Union[str,int]]= {"name":name}
148148
ifpermission:
149149
data["permission"]=permission
150150
ifparent_team_idisnotNone:
@@ -478,7 +478,14 @@ def add_repository(self, repository, team_id): # FIXME(jlk): add perms
478478
ifint(team_id)<0:
479479
returnFalse
480480

481-
url=self._build_url("teams",str(team_id),"repos",str(repository))
481+
url=self._build_url(
482+
"organizations",
483+
str(self.id),
484+
"team",
485+
str(team_id),
486+
"repos",
487+
str(repository),
488+
)
482489
returnself._boolean(self._put(url),204,404)
483490

484491
@requires_auth
@@ -736,10 +743,14 @@ def create_team(
736743
:rtype:
737744
:class:`~github3.orgs.Team`
738745
"""
739-
data= {
746+
data:t.Dict[str,t.Union[t.List[str],str,int]]= {
740747
"name":name,
741-
"repo_names": [getattr(r,"full_name",r)forrinrepo_names],
742-
"maintainers": [getattr(m,"login",m)forminmaintainers],
748+
"repo_names": [
749+
getattr(r,"full_name",r)forrin (repo_namesor [])
750+
],
751+
"maintainers": [
752+
getattr(m,"login",m)formin (maintainersor [])
753+
],
743754
"permission":permission,
744755
"privacy":privacy,
745756
}
@@ -1149,7 +1160,7 @@ def teams(self, number=-1, etag=None):
11491160
returnself._iter(int(number),url,ShortTeam,etag=etag)
11501161

11511162
@requires_auth
1152-
defpublicize_member(self,username):
1163+
defpublicize_member(self,username:str)->bool:
11531164
"""Make ``username``'s membership in this organization public.
11541165
11551166
:param str username:
@@ -1163,7 +1174,7 @@ def publicize_member(self, username):
11631174
returnself._boolean(self._put(url),204,404)
11641175

11651176
@requires_auth
1166-
defremove_member(self,username):
1177+
defremove_member(self,username:str)->bool:
11671178
"""Remove the user named ``username`` from this organization.
11681179
11691180
.. note::
@@ -1182,7 +1193,11 @@ def remove_member(self, username):
11821193
returnself._boolean(self._delete(url),204,404)
11831194

11841195
@requires_auth
1185-
defremove_repository(self,repository,team_id):
1196+
defremove_repository(
1197+
self,
1198+
repository:t.Union[Repository,ShortRepository,str],
1199+
team_id:int,
1200+
):
11861201
"""Remove ``repository`` from the team with ``team_id``.
11871202
11881203
:param str repository:
@@ -1196,13 +1211,18 @@ def remove_repository(self, repository, team_id):
11961211
"""
11971212
ifint(team_id)>0:
11981213
url=self._build_url(
1199-
"teams",str(team_id),"repos",str(repository)
1214+
"organizations",
1215+
str(self.id),
1216+
"team",
1217+
str(team_id),
1218+
"repos",
1219+
str(repository),
12001220
)
12011221
returnself._boolean(self._delete(url),204,404)
12021222
returnFalse
12031223

12041224
@requires_auth
1205-
defteam(self,team_id):
1225+
defteam(self,team_id:int)->t.Optional[Team]:
12061226
"""Return the team specified by ``team_id``.
12071227
12081228
:param int team_id:
@@ -1214,12 +1234,14 @@ def team(self, team_id):
12141234
"""
12151235
json=None
12161236
ifint(team_id)>0:
1217-
url=self._build_url("teams",str(team_id))
1237+
url=self._build_url(
1238+
"organizations",str(self.id),"team",str(team_id)
1239+
)
12181240
json=self._json(self._get(url),200)
12191241
returnself._instance_or_null(Team,json)
12201242

12211243
@requires_auth
1222-
defteam_by_name(self,team_slug):
1244+
defteam_by_name(self,team_slug:str)->t.Optional[Team]:
12231245
"""Return the team specified by ``team_slug``.
12241246
12251247
:param str team_slug:

‎src/github3/structs.py

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,75 @@
1-
importcollections.abcasabc_collections
1+
importcollections.abc
22
importfunctools
3+
importtypingast
34

45
fromrequests.compatimporturlencode
56
fromrequests.compatimporturlparse
67

78
from .importexceptions
89
from .importmodels
910

11+
ift.TYPE_CHECKING:
12+
importrequests.models
1013

11-
classGitHubIterator(models.GitHubCore,abc_collections.Iterator):
14+
from .importsession
15+
16+
17+
T=t.TypeVar("T")
18+
19+
20+
classGitHubIterator(models.GitHubCore,collections.abc.Iterator):
1221
"""The :class:`GitHubIterator` class powers all of the iter_* methods."""
1322

1423
def__init__(
1524
self,
16-
count,
17-
url,
18-
cls,
19-
session,
20-
params=None,
21-
etag=None,
22-
headers=None,
23-
list_key=None,
24-
):
25+
count:int,
26+
url:str,
27+
cls:t.Type[T],
28+
session:"session.GitHubSession",
29+
params:t.Optional[t.Mapping[str,t.Optional[str]]]=None,
30+
etag:t.Optional[str]=None,
31+
headers:t.Optional[t.Mapping[str,str]]=None,
32+
list_key:t.Optional[str]=None,
33+
)->None:
2534
models.GitHubCore.__init__(self, {},session)
2635
#: Original number of items requested
27-
self.original=count
36+
self.original:t.Final[int]=count
2837
#: Number of items left in the iterator
29-
self.count=count
38+
self.count:int=count
3039
#: URL the class used to make it's first GET
31-
self.url=url
40+
self.url:str=url
3241
#: Last URL that was requested
33-
self.last_url=None
34-
self._api=self.url
42+
self.last_url:t.Optional[str]=None
43+
self._api:str=self.url
3544
#: Class for constructing an item to return
36-
self.cls=cls
45+
self.cls:t.Type[T]=cls
3746
#: Parameters of the query string
38-
self.params=paramsor {}
47+
self.params:t.Mapping[str,t.Optional[str]]=paramsor {}
3948
self._remove_none(self.params)
4049
# We do not set this from the parameter sent. We want this to
4150
# represent the ETag header returned by GitHub no matter what.
4251
# If this is not None, then it won't be set from the response and
4352
# that's not what we want.
4453
#: The ETag Header value returned by GitHub
45-
self.etag=None
54+
self.etag:t.Optional[str]=None
4655
#: Headers generated for the GET request
47-
self.headers=headersor {}
56+
self.headers:t.Dict[str,str]=dict(headersor {})
4857
#: The last response seen
49-
self.last_response=None
58+
self.last_response:"requests.models.Response"=None
5059
#: Last status code received
51-
self.last_status=0
60+
self.last_status:int=0
5261
#: Key to get the list of items in case a dict is returned
53-
self.list_key=list_key
62+
self.list_key:t.Final[t.Optional[str]]=list_key
5463

5564
ifetag:
5665
self.headers.update({"If-None-Match":etag})
5766

58-
self.path=urlparse(self.url).path
67+
self.path:str=urlparse(self.url).path
5968

60-
def_repr(self):
69+
def_repr(self)->str:
6170
returnf"<GitHubIterator [{self.count},{self.path}]>"
6271

63-
def__iter__(self):
72+
def__iter__(self)->t.Generator[T,None,None]:
6473
self.last_url,params=self.url,self.params
6574
headers=self.headers
6675

@@ -127,23 +136,23 @@ def __iter__(self):
127136
rel_next=response.links.get("next", {})
128137
self.last_url=rel_next.get("url","")
129138

130-
def__next__(self):
139+
def__next__(self)->T:
131140
ifnothasattr(self,"__i__"):
132141
self.__i__=self.__iter__()
133142
returnnext(self.__i__)
134143

135-
def_get_json(self,response):
144+
def_get_json(self,response:"requests.models.Response"):
136145
returnself._json(response,200)
137146

138-
defrefresh(self,conditional=False):
147+
defrefresh(self,conditional:bool=False)->"GitHubIterator":
139148
self.count=self.original
140-
ifconditional:
149+
ifconditionalandself.etag:
141150
self.headers["If-None-Match"]=self.etag
142151
self.etag=None
143152
self.__i__=self.__iter__()
144153
returnself
145154

146-
defnext(self):
155+
defnext(self)->T:
147156
returnself.__next__()
148157

149158

@@ -160,13 +169,20 @@ class SearchIterator(GitHubIterator):
160169
_ratelimit_resource="search"
161170

162171
def__init__(
163-
self,count,url,cls,session,params=None,etag=None,headers=None
172+
self,
173+
count:int,
174+
url:str,
175+
cls:t.Type[T],
176+
session:"session.GitHubSession",
177+
params:t.Optional[t.Mapping[str,t.Optional[str]]]=None,
178+
etag:t.Optional[str]=None,
179+
headers:t.Optional[t.Mapping[str,str]]=None,
164180
):
165181
super().__init__(count,url,cls,session,params,etag,headers)
166182
#: Total count returned by GitHub
167-
self.total_count=0
183+
self.total_count:int=0
168184
#: Items array returned in the last request
169-
self.items= []
185+
self.items:t.List[t.Mapping[str,t.Any]]= []
170186

171187
def_repr(self):
172188
return"<SearchIterator [{}, {}?{}]>".format(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp