12
12
from .repos import Repository
13
13
from .repos import ShortRepository
14
14
15
+ if t .TYPE_CHECKING :
16
+ from . import users as _users
17
+
18
+
19
+ class ShortRepositoryWithPermissions (ShortRepository ):
20
+ class_name = "ShortRepositoryWithPermissions"
21
+
22
+ def _update_attributes (self , repo ) -> None :
23
+ super ()._update_attributes (repo )
24
+ self .permissions = repo ["permissions" ]
25
+
15
26
16
27
class _Team (models .GitHubCore ):
17
28
"""Base class for Team representations."""
@@ -32,6 +43,10 @@ def _update_attributes(self, team):
32
43
) # TODO: Re-record cassettes to ensure this exists
33
44
self .repositories_url = team ["repositories_url" ]
34
45
self .slug = team ["slug" ]
46
+ self .parent = None
47
+ parent = team .get ("parent" )
48
+ if parent :
49
+ self .parent = ShortTeam (parent , self )
35
50
36
51
def _repr (self ):
37
52
return "<{s.class_name} [{s.name}]>" .format (s = self )
@@ -170,6 +185,15 @@ def members(self, role=None, number=-1, etag=None):
170
185
headers = headers ,
171
186
)
172
187
188
+ @requires_auth
189
+ def permissions_for (
190
+ self , repository : str
191
+ ) -> ShortRepositoryWithPermissions :
192
+ headers = {"Accept" : "application/vnd.github.v3.repository+json" }
193
+ url = self ._build_url ("repos" , repository , base_url = self ._api )
194
+ json = self ._json (self ._get (url , headers = headers ), 200 )
195
+ return ShortRepositoryWithPermissions (json , self )
196
+
173
197
@requires_auth
174
198
def repositories (self , number = - 1 , etag = None ):
175
199
"""Iterate over the repositories this team has access to.
@@ -182,12 +206,14 @@ def repositories(self, number=-1, etag=None):
182
206
:returns:
183
207
generator of repositories this team has access to
184
208
:rtype:
185
- :class:`~github3.repos.ShortRepository `
209
+ :class:`~github3.orgs.ShortRepositoryWithPermissions `
186
210
"""
187
- headers = {"Accept" : "application/vnd.github.ironman-preview+json" }
188
211
url = self ._build_url ("repos" , base_url = self ._api )
189
212
return self ._iter (
190
- int (number ), url , ShortRepository , etag = etag , headers = headers
213
+ int (number ),
214
+ url ,
215
+ ShortRepositoryWithPermissions ,
216
+ etag = etag ,
191
217
)
192
218
193
219
@requires_auth
@@ -343,10 +369,6 @@ class _Organization(models.GitHubCore):
343
369
http://developer.github.com/v3/orgs/
344
370
"""
345
371
346
- PREVIEW_HEADERS = {
347
- "Accept" : "application/vnd.github.hellcat-preview+json"
348
- }
349
-
350
372
class_name = "_Organization"
351
373
352
374
# Filters available when listing members. Note: ``"2fa_disabled"``
@@ -654,11 +676,14 @@ def conceal_member(self, username):
654
676
@requires_auth
655
677
def create_team (
656
678
self ,
657
- name ,
658
- repo_names = [],
659
- permission = "pull" ,
660
- parent_team_id = None ,
661
- privacy = "secret" ,
679
+ name : str ,
680
+ repo_names : t .Optional [t .Sequence [str ]] = [],
681
+ maintainers : t .Optional [
682
+ t .Union [t .Sequence [str ], t .Sequence ["_users._User" ]]
683
+ ] = [],
684
+ permission : str = "pull" ,
685
+ parent_team_id : t .Optional [int ] = None ,
686
+ privacy : str = "secret" ,
662
687
):
663
688
"""Create a new team and return it.
664
689
@@ -668,6 +693,8 @@ def create_team(
668
693
(required), name to be given to the team
669
694
:param list repo_names:
670
695
(optional) repositories, e.g. ['github/dotfiles']
696
+ :param list maintainers:
697
+ (optional) list of usernames who will be maintainers
671
698
:param str permission:
672
699
(optional), options:
673
700
@@ -692,20 +719,16 @@ def create_team(
692
719
"""
693
720
data = {
694
721
"name" : name ,
695
- "repo_names" : repo_names ,
722
+ "repo_names" : [getattr (r , "full_name" , r ) for r in repo_names ],
723
+ "maintainers" : [getattr (m , "login" , m ) for m in maintainers ],
696
724
"permission" : permission ,
697
725
"privacy" : privacy ,
698
726
}
699
- headers = (
700
- self .PREVIEW_HEADERS
701
- if parent_team_id or privacy == "closed"
702
- else None
703
- )
704
727
if parent_team_id :
705
728
data .update ({"parent_team_id" : parent_team_id })
706
729
707
730
url = self ._build_url ("teams" , base_url = self ._api )
708
- json = self ._json (self ._post (url , data , headers = headers ), 201 )
731
+ json = self ._json (self ._post (url , data ), 201 )
709
732
return self ._instance_or_null (Team , json )
710
733
711
734
@requires_auth
0 commit comments