1
1
# -*- coding: utf-8 -*-
2
- """
3
- github3.orgs
4
- ============
5
-
6
- This module contains all of the classes related to organizations.
7
-
8
- """
2
+ """This module contains all of the classes related to organizations."""
9
3
from __future__ import unicode_literals
10
4
11
5
import warnings
12
6
from json import dumps
13
7
14
8
from uritemplate import URITemplate
15
9
16
- from . import users
10
+ from . import users , models
17
11
18
12
from .decorators import requires_auth
19
13
from .events import Event
20
- from .models import BaseAccount , GitHubCore
21
14
from .projects import Project
22
15
from .repos import Repository
23
16
24
17
25
- class Team (GitHubCore ):
18
+ class Team (models . GitHubCore ):
26
19
27
20
"""The :class:`Team <Team>` object.
28
21
29
- Two team instances can be checked like so::
30
-
31
- t1 == t2
32
- t1 != t2
33
-
34
- And is equivalent to::
35
-
36
- t1.id == t2.id
37
- t1.id != t2.id
38
-
39
- See also: http://developer.github.com/v3/orgs/teams/
22
+ Please see GitHub's `Team Documentation`_ for more information.
40
23
24
+ .. _Team Documentation:
25
+ http://developer.github.com/v3/orgs/teams/
41
26
"""
42
27
43
28
# Roles available to members on a team.
@@ -93,11 +78,16 @@ def add_member(self, username):
93
78
def add_repository (self , repository , permission = '' ):
94
79
"""Add ``repository`` to this team.
95
80
81
+ If a permission is not provided, the team's default permission
82
+ will be assigned, by GitHub.
83
+
96
84
:param str repository: (required), form: 'user/repo'
97
85
:param str permission: (optional), ('pull', 'push', 'admin')
98
86
:returns: bool
99
87
"""
100
- data = {'permission' : permission }
88
+ data = {}
89
+ if permission :
90
+ data = {'permission' : permission }
101
91
url = self ._build_url ('repos' , repository , base_url = self ._api )
102
92
return self ._boolean (self ._put (url , data = dumps (data )), 204 , 404 )
103
93
@@ -244,22 +234,14 @@ def remove_repository(self, repository):
244
234
return self ._boolean (self ._delete (url ), 204 , 404 )
245
235
246
236
247
- class Organization ( BaseAccount ):
237
+ class _Organization ( models . GitHubCore ):
248
238
249
239
"""The :class:`Organization <Organization>` object.
250
240
251
- Two organization instances can be checked like so::
252
-
253
- o1 == o2
254
- o1 != o2
255
-
256
- And is equivalent to::
257
-
258
- o1.id == o2.id
259
- o1.id != o2.id
260
-
261
- See also: http://developer.github.com/v3/orgs/
241
+ Please see GitHub's `Organization Documentation`_ for more information.
262
242
243
+ .. _Organization Documentation:
244
+ http://developer.github.com/v3/orgs/
263
245
"""
264
246
265
247
# Filters available when listing members. Note: ``"2fa_disabled"``
@@ -270,23 +252,30 @@ class Organization(BaseAccount):
270
252
members_roles = frozenset (['all' , 'admin' , 'member' ])
271
253
272
254
def _update_attributes (self , org ):
273
- super (Organization , self )._update_attributes (org )
274
- self .type = self .type or 'Organization'
255
+ #: URL of the avatar at gravatar
256
+ self .avatar_url = org ['avatar_url' ]
257
+
258
+ # Set the type of object (this doens't come through API data)
259
+ self .type = 'Organization'
260
+
261
+ self .url = self ._api = org ['url' ]
275
262
276
- #: Events url (not a template)
277
- self .events_url = self ._get_attribute (org , 'events_url' )
278
- #: Number of private repositories.
279
- self .private_repos = self ._get_attribute (org , 'private_repos' )
263
+ #: Unique ID of the account
264
+ self .id = org ['id' ]
265
+
266
+ #: Name of the organization
267
+ self .login = org ['login' ]
280
268
281
269
#: Public Members URL Template. Expands with ``member``
282
- self .public_members_urlt = self ._class_attribute (
283
- org ,
284
- 'public_members_url' ,
285
- URITemplate
286
- )
270
+ self .public_members_urlt = URITemplate (org ['public_members_url' ])
287
271
288
- #: Repositories url (not a template)
289
- 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 ])
276
+
277
+ def _repr (self ):
278
+ return '<Organization [{s.login}:{s.name}]>' .format (s = self )
290
279
291
280
@requires_auth
292
281
def add_member (self , username , team_id ):
@@ -328,7 +317,7 @@ def add_member(self, username, team_id):
328
317
return self ._boolean (self ._put (url ), 204 , 404 )
329
318
330
319
@requires_auth
331
- def add_repository (self , repository , team_id ):
320
+ def add_repository (self , repository , team_id ): # FIXME(jlk): add perms
332
321
"""Add ``repository`` to ``team``.
333
322
334
323
.. versionchanged:: 1.0
@@ -415,7 +404,7 @@ def conceal_member(self, username):
415
404
return self ._boolean (self ._delete (url ), 204 , 404 )
416
405
417
406
@requires_auth
418
- def create_team (self , name , repo_names = [], permission = '' ):
407
+ def create_team (self , name , repo_names = [], permission = 'pull ' ):
419
408
"""Create a new team and return it.
420
409
421
410
This only works if the authenticated user owns this organization.
@@ -674,7 +663,75 @@ def team(self, team_id):
674
663
return self ._instance_or_null (Team , json )
675
664
676
665
677
- class Membership (GitHubCore ):
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
+
734
+ class Membership (models .GitHubCore ):
678
735
679
736
"""The wrapper for information about Team and Organization memberships."""
680
737
@@ -685,7 +742,7 @@ def _update_attributes(self, membership):
685
742
self ._api = self ._get_attribute (membership , 'url' )
686
743
687
744
self .organization = self ._class_attribute (
688
- membership , 'organization' , Organization , self
745
+ membership , 'organization' , ShortOrganization , self
689
746
)
690
747
691
748
self .organization_url = self ._get_attribute (
@@ -711,7 +768,7 @@ def edit(self, state):
711
768
"""
712
769
if state and state .lower () == 'active' :
713
770
data = dumps ({'state' : state .lower ()})
714
- json = self ._json (self ._patch (self ._api , data = data ))
771
+ json = self ._json (self ._patch (self ._api , data = data ), 200 )
715
772
self ._update_attributes (json )
716
773
return True
717
774
return False
0 commit comments