/ github / GithubApp.py
GithubApp.py
  1  ############################ Copyrights and license ############################
  2  #                                                                              #
  3  # Copyright 2020 Raju Subramanian <coder@mahesh.net>                           #
  4  #                                                                              #
  5  # This file is part of PyGithub.                                               #
  6  # http://pygithub.readthedocs.io/                                              #
  7  #                                                                              #
  8  # PyGithub is free software: you can redistribute it and/or modify it under    #
  9  # the terms of the GNU Lesser General Public License as published by the Free  #
 10  # Software Foundation, either version 3 of the License, or (at your option)    #
 11  # any later version.                                                           #
 12  #                                                                              #
 13  # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY  #
 14  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    #
 15  # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
 16  # details.                                                                     #
 17  #                                                                              #
 18  # You should have received a copy of the GNU Lesser General Public License     #
 19  # along with PyGithub. If not, see <http://www.gnu.org/licenses/>.             #
 20  #                                                                              #
 21  ################################################################################
 22  from __future__ import annotations
 23  
 24  from datetime import datetime
 25  from typing import Any
 26  
 27  import github.GithubObject
 28  import github.NamedUser
 29  from github.GithubObject import Attribute, CompletableGithubObject, NotSet
 30  
 31  
 32  class GithubApp(CompletableGithubObject):
 33      """
 34      This class represents github apps. The reference can be found here https://docs.github.com/en/rest/reference/apps
 35      """
 36  
 37      def _initAttributes(self) -> None:
 38          self._created_at: Attribute[datetime] = NotSet
 39          self._description: Attribute[str] = NotSet
 40          self._events: Attribute[list[str]] = NotSet
 41          self._external_url: Attribute[str] = NotSet
 42          self._html_url: Attribute[str] = NotSet
 43          self._id: Attribute[int] = NotSet
 44          self._name: Attribute[str] = NotSet
 45          self._owner: Attribute[github.NamedUser.NamedUser] = NotSet
 46          self._permissions: Attribute[dict[str, str]] = NotSet
 47          self._slug: Attribute[str] = NotSet
 48          self._updated_at: Attribute[datetime] = NotSet
 49          self._url: Attribute[str] = NotSet
 50  
 51      def __repr__(self) -> str:
 52          return self.get__repr__({"id": self._id.value, "url": self._url.value})
 53  
 54      @property
 55      def created_at(self) -> datetime:
 56          self._completeIfNotSet(self._created_at)
 57          return self._created_at.value
 58  
 59      @property
 60      def description(self) -> str:
 61          self._completeIfNotSet(self._description)
 62          return self._description.value
 63  
 64      @property
 65      def events(self) -> list[str]:
 66          self._completeIfNotSet(self._events)
 67          return self._events.value
 68  
 69      @property
 70      def external_url(self) -> str:
 71          self._completeIfNotSet(self._external_url)
 72          return self._external_url.value
 73  
 74      @property
 75      def html_url(self) -> str:
 76          self._completeIfNotSet(self._html_url)
 77          return self._html_url.value
 78  
 79      @property
 80      def id(self) -> int:
 81          self._completeIfNotSet(self._id)
 82          return self._id.value
 83  
 84      @property
 85      def name(self) -> str:
 86          self._completeIfNotSet(self._name)
 87          return self._name.value
 88  
 89      @property
 90      def owner(self) -> github.NamedUser.NamedUser:
 91          self._completeIfNotSet(self._owner)
 92          return self._owner.value
 93  
 94      @property
 95      def permissions(self) -> dict[str, str]:
 96          self._completeIfNotSet(self._permissions)
 97          return self._permissions.value
 98  
 99      @property
100      def slug(self) -> str:
101          self._completeIfNotSet(self._slug)
102          return self._slug.value
103  
104      @property
105      def updated_at(self) -> datetime:
106          self._completeIfNotSet(self._updated_at)
107          return self._updated_at.value
108  
109      @property
110      def url(self) -> str:
111          return self._url.value
112  
113      def _useAttributes(self, attributes: dict[str, Any]) -> None:
114          if "created_at" in attributes:  # pragma no branch
115              self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
116          if "description" in attributes:  # pragma no branch
117              self._description = self._makeStringAttribute(attributes["description"])
118          if "events" in attributes:  # pragma no branch
119              self._events = self._makeListOfStringsAttribute(attributes["events"])
120          if "external_url" in attributes:  # pragma no branch
121              self._external_url = self._makeStringAttribute(attributes["external_url"])
122          if "html_url" in attributes:  # pragma no branch
123              self._html_url = self._makeStringAttribute(attributes["html_url"])
124          if "id" in attributes:  # pragma no branch
125              self._id = self._makeIntAttribute(attributes["id"])
126          if "name" in attributes:  # pragma no branch
127              self._name = self._makeStringAttribute(attributes["name"])
128          if "owner" in attributes:  # pragma no branch
129              self._owner = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["owner"])
130          if "permissions" in attributes:  # pragma no branch
131              self._permissions = self._makeDictAttribute(attributes["permissions"])
132          if "slug" in attributes:  # pragma no branch
133              self._slug = self._makeStringAttribute(attributes["slug"])
134              self._url = self._makeStringAttribute(f"/apps/{attributes['slug']}")
135          if "updated_at" in attributes:  # pragma no branch
136              self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"])
137          if "url" in attributes:
138              self._url = self._makeStringAttribute(attributes["url"])