@@ -77,11 +77,16 @@ def add_member(self, username):
77
77
def add_repository (self , repository , permission = '' ):
78
78
"""Add ``repository`` to this team.
79
79
80
+ If a permission is not provided, the team's default permission
81
+ will be assigned, by GitHub.
82
+
80
83
:param str repository: (required), form: 'user/repo'
81
84
:param str permission: (optional), ('pull', 'push', 'admin')
82
85
:returns: bool
83
86
"""
84
- data = {'permission' : permission }
87
+ data = {}
88
+ if permission :
89
+ data = {'permission' : permission }
85
90
url = self ._build_url ('repos' , repository , base_url = self ._api )
86
91
return self ._boolean (self ._put (url , data = dumps (data )), 204 , 404 )
87
92
@@ -228,7 +233,7 @@ def remove_repository(self, repository):
228
233
return self ._boolean (self ._delete (url ), 204 , 404 )
229
234
230
235
231
- class Organization (models .GitHubCore ):
236
+ class _Organization (models .GitHubCore ):
232
237
233
238
"""The :class:`Organization <Organization>` object.
234
239
@@ -246,75 +251,27 @@ class Organization(models.GitHubCore):
246
251
members_roles = frozenset (['all' , 'admin' , 'member' ])
247
252
248
253
def _update_attributes (self , org ):
249
- # Set the type of object
250
- self .type = self ._get_attribute (org , 'type' )
251
- if not self .type :
252
- self .type = 'Organization'
253
-
254
- self ._api = self ._get_attribute (org , 'url' )
255
-
256
254
#: URL of the avatar at gravatar
257
- self .avatar_url = self ._get_attribute (org , 'avatar_url' )
258
-
259
- #: URL of the blog
260
- self .blog = self ._get_
F438
attribute (org , 'blog' )
255
+ self .avatar_url = org ['avatar_url' ]
261
256
262
- #: Name of the company
263
- self .company = self . _get_attribute ( org , 'company' )
257
+ # Set the type of object (this doens't come through API data)
258
+ self .type = 'Organization'
264
259
265
- #: datetime object representing the date the account was created
266
- self .created_at = self ._strptime_attribute (org , 'created_at' )
267
-
268
- #: E-mail address of the org
269
- self .email = self ._get_attribute (org , 'email' )
270
-
271
- # The number of people following this org
272
- #: Number of followers
273
- self .followers_count = self ._get_attribute (org , 'followers' )
274
-
275
- # The number of people this org follows
276
- #: Number of people the org is following
277
- self .following_count = self ._get_attribute (org , 'following' )
260
+ self .url = self ._api = org ['url' ]
278
261
279
262
#: Unique ID of the account
280
- self .id = self ._get_attribute (org , 'id' )
281
-
282
- #: Location of the org
283
- self .location = self ._get_attribute (org , 'location' )
263
+ self .id = org ['id' ]
284
264
285
265
#: Name of the organization
286
- self .login = self ._get_attribute (org , 'login' )
287
-
288
- # e.g. first_name last_name
289
- #: Real name of the org
290
- self .name = self ._get_attribute (org , 'name' )
291
-
292
- # The number of public_repos
293
- #: Number of public repos owned by the org
294
- self .public_repos_count = self ._get_attribute (org , 'public_repos' )
295
-
296
- # e.g. https://github.com/self._login
297
- #: URL of the org's profile
298
- self .html_url = self ._get_attribute (org , 'html_url' )
299
-
300
- #: Description of the org
301
- self .description = self ._get_attribute (org , 'description' )
302
-
303
- #: Events url (not a template)
304
- self .events_url = self ._get_attribute (org , 'events_url' )
305
-
306
- #: Number of private repositories.
307
- self .private_repos = self ._get_attribute (org , 'owned_private_repos' )
266
+ self .login = org ['login' ]
308
267
309
268
#: Public Members URL Template. Expands with ``member``
310
- self .public_members_urlt = self ._class_attribute (
311
- org ,
312
- 'public_members_url' ,
313
- URITemplate
314
- )
269
+ self .public_members_urlt = URITemplate (org ['public_members_url' ])
315
270
316
- #: Repositories url (not a template)
317
- self .repos_url = self ._get_attribute (org , 'repos_url' )
271
+ #: Various urls (not templates)
272
+ for urltype in ('avatar_url' , 'events_url' , 'issues_url' ,
273
+ 'repos_url' ):
274
+ self .__setattr__ (urltype , org [urltype ])
318
275
319
276
def _repr (self ):
320
277
return '<Organization [{s.login}:{s.name}]>' .format (s = self )
@@ -359,7 +316,7 @@ def add_member(self, username, team_id):
359
316
return self ._boolean (self ._put (url ), 204 , 404 )
360
317
361
318
@requires_auth
362
- def add_repository (self , repository , team_id ):
319
+ def add_repository (self , repository , team_id ): # FIXME(jlk): add perms
363
320
"""Add ``repository`` to ``team``.
364
321
365
322
.. versionchanged:: 1.0
@@ -430,7 +387,7 @@ def conceal_member(self, username):
430
387
return self ._boolean (self ._delete (url ), 204 , 404 )
431
388
432
389
@requires_auth
433
- def create_team (self , name , repo_names = [], permission = '' ):
390
+ def create_team (self , name , repo_names = [], permission = 'pull ' ):
434
391
"""Create a new team and return it.
435
392
436
393
This only works if the authenticated user owns this organization.
@@ -660,6 +617,74 @@ def team(self, team_id):
660
617
return self ._instance_or_null (Team , json )
661
618
662
619
620
+ class ShortOrganization (_Organization ):
621
+ """Object for the shortened representation of an Organization.
622
+
623
+ GitHub's API returns different amounts of information about orgs based
624
+ upon how that information is retrieved. Often times, when iterating over
625
+ several orgs, GitHub will return less information. To provide a clear
626
+ distinction between the types of orgs, github3.py uses different classes
627
+ with different sets of attributes.
628
+
629
+ .. versionadded:: 1.0.0
630
+ """
631
+
632
+ pass
633
+
634
+
635
+ class Organization (_Organization ):
636
+ """Object for the full representation of a Organization.
637
+
638
+ GitHub's API returns different amounts of information about orgs based
639
+ upon how that information is retrieved. This object exists to represent
640
+ the full amount of information returned for a specific org. For example,
641
+ you would receive this class when calling
642
+ :meth:`~github3.github.GitHub.organization`. To provide a clear
643
+ distinction between the types of orgs, github3.py uses different classes
644
+ with different sets of attributes.
645
+
646
+ .. versionchanged:: 1.0.0
647
+ """
648
+
649
+ def _update_attributes (self , org ):
650
+ super (Organization , self )._update_attributes (org )
651
+
652
+ # this may be blank if the org hasn't set it
653
+ #: URL of the blog
654
+ self .blog = self ._get_attribute (org , 'blog' )
655
+
656
+ #: Name of the company
657
+ self .company = self ._get_attribute (org , 'company' )
658
+
659
+ #: datetime object representing the date the account was created
660
+ self .created_at = org ['created_at' ]
661
+
662
+ #: E-mail address of the org
663
+ self .email = self ._get_attribute (org , 'email' )
664
+
665
+ # The number of people following this org
666
+ #: Number of followers
667
+ self .followers_count = org ['followers' ]
668
+
669
+ # The number of people this org follows
670
+ #: Number of people the org is following
671
+ self .following_count = org ['following' ]
672
+
673
+ #: Location of the org
674
+ self .location = self ._get_attribute (org , 'location' )
675
+
676
+ #: Display name of the org
677
+ self .name = self ._get_attribute (org , 'name' )
678
+
679
+ # The number of public_repos
680
+ #: Number of public repos owned by the org
681
+ self .public_repos_count = org ['public_repos' ]
682
+
683
+ # e.g. https://github.com/self._login
684
+ #: URL of the org's profile
685
+ self .html_url = org ['html_url' ]
686
+
687
+
663
688
class Membership (models .GitHubCore ):
664
689
665
690
"""The wrapper for information about Team and Organization memberships."""
@@ -671,7 +696,7 @@ def _update_attributes(self, membership):
671
696
self ._api = self ._get_attribute (membership , 'url' )
672
697
673
698
self .organization = self ._class_attribute (
674
- membership , 'organization' , Organization , self
699
+ membership , 'organization' , ShortOrganization , self
675
700
)
676
701
677
702
self .organization_url = self ._get_attribute (
0 commit comments