@@ -78,11 +78,16 @@ def add_member(self, username):
78
78
def add_repository (self , repository , permission = '' ):
79
79
"""Add ``repository`` to this team.
80
80
81
+ If a permission is not provided, the team's default permission
82
+ will be assigned, by GitHub.
83
+
81
84
:param str repository: (required), form: 'user/repo'
82
85
:param str permission: (optional), ('pull', 'push', 'admin')
83
86
:returns: bool
84
87
"""
85
- data = {'permission' : permission }
88
+ data = {}
89
+ if permission :
90
+ data = {'permission' : permission }
86
91
url = self ._build_url ('repos' , repository , base_url = self ._api )
87
92
return self ._boolean (self ._put (url , data = dumps (data )), 204 , 404 )
88
93
@@ -229,7 +234,7 @@ def remove_repository(self, repository):
229
234
return self ._boolean (self ._delete (url ), 204 , 404 )
230
235
231
236
232
- class Organization (models .GitHubCore ):
237
+ class _Organization (models .GitHubCore ):
233
238
234
239
"""The :class:`Organization <Organization>` object.
235
240
@@ -247,75 +252,27 @@ class Organization(models.GitHubCore):
247
252
members_roles = frozenset (['all' , 'admin' , 'member' ])
248
253
249
254
def _update_attributes (self , org ):
250
- # Set the type of object
251
- self .type = self ._get_attribute (org , 'type' )
252
- if not self .type :
253
- self .type = 'Organization'
254
-
255
- self ._api = self ._get_attribute (org , 'url' )
256
-
257
255
#: URL of the avatar at gravatar
258
- self .avatar_url = self ._get_attribute (org , 'avatar_url' )
259
-
260
- #: URL of the blog
261
- self .blog = self ._get_attribute (org , 'blog' )
256
+ self .avatar_url = org ['avatar_url' ]
262
257
263
- #: Name of the company
264
- self .company = self . _get_attribute ( org , 'company' )
258
+ # Set the type of object (this doens't come through API data)
259
+ self .type = 'Organization'
265
260
266
- #: datetime object representing the date the account was created
267
- self .created_at = self ._strptime_attribute (org , 'created_at' )
268
-
269
- #: E-mail address of the org
270
- self .email = self ._get_attribute (org , 'email' )
271
-
272
- # The number of people following this org
273
- #: Number of followers
274
- self .followers_count = self ._get_attribute (org , 'followers' )
275
-
276
- # The number of people this org follows
277
- #: Number of people the org is following
278
- self .following_count = self ._get_attribute (org , 'following' )
261
+ self .url = self ._api = org ['url' ]
279
262
280
263
#: Unique ID of the account
281
- self .id = self ._get_attribute (org , 'id' )
282
-
283
- #: Location of the org
284
- self .location = self ._get_attribute (org , 'location' )
264
+ self .id = org ['id' ]
285
265
286
266
#: Name of the organization
287
- self .login = self ._get_attribute (org , 'login' )
288
-
289
- # e.g. first_name last_name
290
- #: Real name of the org
291
- self .name = self ._get_attribute (org , 'name' )
292
-
293
- # The number of public_repos
294
- #: Number of public repos owned by the org
295
- self .public_repos_count = self ._get_attribute (org , 'public_repos' )
296
-
297
- # e.g. https://github.com/self._login
298
- #: URL of the org's profile
299
- self .html_url = self ._get_attribute (org , 'html_url' )
300
-
301
- #: Description of the org
302
- self .description = self ._get_attribute (org , 'description' )
303
-
304
- #: Events url (not a template)
305
- self .events_url = self ._get_attribute (org , 'events_url' )
306
-
307
- #: Number of private repositories.
308
- self .private_repos = self ._get_attribute (org , 'owned_private_repos' )
267
+ self .login = org ['login' ]
309
268
310
269
#: Public Members URL Template. Expands with ``member``
311
- self .public_members_urlt = self ._class_attribute (
312
- org ,
313
- 'public_members_url' ,
314
- URITemplate
315
- )
270
+ self .public_members_urlt = URITemplate (org ['public_members_url' ])
316
271
317
- #: Repositories url (not a template)
318
- self .repos_url = self ._get_attribute (org , 'repos_url' )
272
+ #: Various urls (not templates)
273
+ for urltype in ('avatar_url' , 'events_url' , 'issues_url' ,
274
+ 'repos_url' ):
275
+ setattr (self , urltype , org [urltype ])
319
276
320
277
def _repr (self ):
321
278
return '<Organization [{s.login}:{s.name}]>' .format (s = self )
@@ -360,7 +317,7 @@ def add_member(self, username, team_id):
360
317
return self ._boolean (self ._put (url ), 204 , 404 )
361
318
362
319
@requires_auth
363
- def add_repository (self , repository , team_id ):
320
+ def add_repository (self , repository , team_id ): # FIXME(jlk): add perms
364
321
"""Add ``repository`` to ``team``.
365
322
366
323
.. versionchanged:: 1.0
@@ -447,7 +404,7 @@ def conceal_member(self, username):
447
404
return self ._boolean (self ._delete (url ), 204 , 404 )
448
405
449
406
@requires_auth
450
- def create_team (self , name , repo_names = [], permission = '' ):
407
+ def create_team (self , name , repo_names = [], permission = 'pull ' ):
451
408
"""Create a new team and return it.
452
409
453
410
This only works if the authenticated user owns this organization.
@@ -706,6 +663,74 @@ def team(self, team_id):
706
663
return self ._instance_or_null (Team , json )
707
664
708
665
666
+ class ShortOrganization (_Organization ):
667
+ """Object for the shortened representation of an Organization.
668
+
669
+ GitHub's API returns different amounts of information about orgs based
670
+ upon how that information is retrieved. Often times, when iterating over
671
+ several orgs, GitHub will return less information. To provide a clear
672
+ distinction between the types of orgs, github3.py uses different classes
673
+ with different sets of attributes.
674
+
675
+ .. versionadded:: 1.0.0
676
+ """
677
+
678
+ pass
679
+
680
+
681
+ class Organization (_Organization ):
682
+ """Object for the full representation of a Organization.
683
+
684
+ GitHub's API returns different amounts of information about orgs based
685
+ upon how that information is retrieved. This object exists to represent
686
+ the full amount of information returned for a specific org. For example,
687
+ you would receive this class when calling
688
+ :meth:`~github3.github.GitHub.organization`. To provide a clear
689
+ distinction between the types of orgs, github3.py uses different classes
690
+ with different sets of attributes.
691
+
692
+ .. versionchanged:: 1.0.0
693
+ """
694
+
695
+ def _update_attributes (self , org ):
696
+ super (Organization , self )._update_attributes (org )
697
+
698
+ # this may be blank if the org hasn't set it
699
+ #: URL of the blog
700
+ self .blog = self ._get_attribute (org , 'blog' )
701
+
702
+ #: Name of the company
703
+ self .company = self ._get_attribute (org , 'company' )
704
+
705
+ #: datetime object representing the date the account was created
706
+ self .created_at = org ['created_at' ]
707
+
708
+ #: E-mail address of the org
709
+ self .email = self ._get_attribute (org , 'email' )
710
+
711
+ # The number of people following this org
712
+ #: Number of followers
713
+ self .followers_count = org ['followers' ]
714
+
715
+ # The number of people this org follows
716
+ #: Number of people the org is following
717
+ self .following_count = org ['following' ]
718
+
719
+ #: Location of the org
720
+ self .location = self ._get_attribute (org , 'location' )
721
+
722
+ #: Display name of the org
723
+ self .name = self ._get_attribute (org , 'name' )
724
+
725
+ # The number of public_repos
726
+ #: Number of public repos owned by the org
727
+ self .public_repos_count = org ['public_repos' ]
728
+
729
+ # e.g. https://github.com/self._login
730
+ #: URL of the org's profile
731
+ self .html_url = org ['html_url' ]
732
+
733
+
709
734
class Membership (models .GitHubCore ):
710
735
711
736
"""The wrapper for information about Team and Organization memberships."""
@@ -717,7 +742,7 @@ def _update_attributes(self, membership):
717
742
self ._api = self ._get_attribute (membership , 'url' )
718
743
719
744
self .organization = self ._class_attribute (
720
- membership , 'organization' , Organization , self
745
+ membership , 'organization' , ShortOrganization , self
721
746
)
722
747
723
748
self .organization_url = self ._get_attribute (
0 commit comments