/ github / Membership.py
Membership.py
  1  ############################ Copyrights and license ############################
  2  #                                                                              #
  3  # Copyright 2012 Steve English <steve.english@navetas.com>                     #
  4  # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net>                 #
  5  # Copyright 2012 Zearin <zearin@gonk.net>                                      #
  6  # Copyright 2013 AKFish <akfish@gmail.com>                                     #
  7  # Copyright 2013 Cameron White <cawhite@pdx.edu>                               #
  8  # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net>                 #
  9  # Copyright 2013 poulp <mathieu.nerv@gmail.com>                                #
 10  # Copyright 2014 Tomas Radej <tradej@redhat.com>                               #
 11  # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net>                 #
 12  # Copyright 2016 E. Dunham <github@edunham.net>                                #
 13  # Copyright 2016 Jannis Gebauer <ja.geb@me.com>                                #
 14  # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com>          #
 15  # Copyright 2017 Balázs Rostás <rostas.balazs@gmail.com>                       #
 16  # Copyright 2017 Jannis Gebauer <ja.geb@me.com>                                #
 17  # Copyright 2017 Simon <spam@esemi.ru>                                         #
 18  # Copyright 2018 Wan Liuyang <tsfdye@gmail.com>                                #
 19  # Copyright 2018 bryanhuntesl <31992054+bryanhuntesl@users.noreply.github.com> #
 20  # Copyright 2018 sfdye <tsfdye@gmail.com>                                      #
 21  # Copyright 2018 itsbruce <it.is.bruce@gmail.com>                              #
 22  #                                                                              #
 23  # This file is part of PyGithub.                                               #
 24  # http://pygithub.readthedocs.io/                                              #
 25  #                                                                              #
 26  # PyGithub is free software: you can redistribute it and/or modify it under    #
 27  # the terms of the GNU Lesser General Public License as published by the Free  #
 28  # Software Foundation, either version 3 of the License, or (at your option)    #
 29  # any later version.                                                           #
 30  #                                                                              #
 31  # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY  #
 32  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    #
 33  # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
 34  # details.                                                                     #
 35  #                                                                              #
 36  # You should have received a copy of the GNU Lesser General Public License     #
 37  # along with PyGithub. If not, see <http://www.gnu.org/licenses/>.             #
 38  #                                                                              #
 39  ################################################################################
 40  from __future__ import annotations
 41  
 42  from typing import TYPE_CHECKING, Any
 43  
 44  import github.NamedUser
 45  import github.Organization
 46  from github.GithubObject import Attribute, CompletableGithubObject, NotSet
 47  
 48  if TYPE_CHECKING:
 49      from github.NamedUser import NamedUser
 50      from github.Organization import Organization
 51  
 52  
 53  class Membership(CompletableGithubObject):
 54      """
 55      This class represents Membership of an organization. The reference can be found here https://docs.github.com/en/rest/reference/orgs
 56      """
 57  
 58      def _initAttributes(self) -> None:
 59          self._url: Attribute[str] = NotSet
 60          self._state: Attribute[str] = NotSet
 61          self._role: Attribute[str] = NotSet
 62          self._organization_url: Attribute[str] = NotSet
 63          self._organization: Attribute[Organization] = NotSet
 64          self._user: Attribute[NamedUser] = NotSet
 65  
 66      def __repr__(self) -> str:
 67          return self.get__repr__({"url": self._url.value})
 68  
 69      @property
 70      def url(self) -> str:
 71          self._completeIfNotSet(self._url)
 72          return self._url.value
 73  
 74      @property
 75      def state(self) -> str:
 76          self._completeIfNotSet(self._state)
 77          return self._state.value
 78  
 79      @property
 80      def role(self) -> str:
 81          self._completeIfNotSet(self._role)
 82          return self._role.value
 83  
 84      @property
 85      def organization_url(self) -> str:
 86          self._completeIfNotSet(self._organization_url)
 87          return self._organization_url.value
 88  
 89      @property
 90      def organization(self) -> Organization:
 91          self._completeIfNotSet(self._organization)
 92          return self._organization.value
 93  
 94      @property
 95      def user(self) -> NamedUser:
 96          self._completeIfNotSet(self._user)
 97          return self._user.value
 98  
 99      def _useAttributes(self, attributes: dict[str, Any]) -> None:
100          if "url" in attributes:  # pragma no branch
101              self._url = self._makeStringAttribute(attributes["url"])
102          if "state" in attributes:  # pragma no branch
103              self._state = self._makeStringAttribute(attributes["state"])
104          if "role" in attributes:  # pragma no branch
105              self._role = self._makeStringAttribute(attributes["role"])
106          if "organization_url" in attributes:  # pragma no branch
107              self._organization_url = self._makeStringAttribute(attributes["organization_url"])
108          if "organization" in attributes:  # pragma no branch
109              self._organization = self._makeClassAttribute(github.Organization.Organization, attributes["organization"])
110          if "user" in attributes:  # pragma no branch
111              self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"])