/ github / RepositoryKey.py
RepositoryKey.py
  1  ############################ Copyrights and license ############################
  2  #                                                                              #
  3  # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net>                 #
  4  # Copyright 2012 Zearin <zearin@gonk.net>                                      #
  5  # Copyright 2013 AKFish <akfish@gmail.com>                                     #
  6  # Copyright 2013 Srijan Choudhary <srijan4@gmail.com>                          #
  7  # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net>                 #
  8  # Copyright 2013 martinqt <m.ki2@laposte.net>                                  #
  9  # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net>                 #
 10  # Copyright 2016 Jannis Gebauer <ja.geb@me.com>                                #
 11  # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com>          #
 12  # Copyright 2017 Jimmy Zelinskie <jimmy.zelinskie+git@gmail.com>               #
 13  # Copyright 2017 Simon <spam@esemi.ru>                                         #
 14  # Copyright 2018 Laurent Raufaste <analogue@glop.org>                          #
 15  # Copyright 2018 Wan Liuyang <tsfdye@gmail.com>                                #
 16  # Copyright 2018 sfdye <tsfdye@gmail.com>                                      #
 17  #                                                                              #
 18  # This file is part of PyGithub.                                               #
 19  # http://pygithub.readthedocs.io/                                              #
 20  #                                                                              #
 21  # PyGithub is free software: you can redistribute it and/or modify it under    #
 22  # the terms of the GNU Lesser General Public License as published by the Free  #
 23  # Software Foundation, either version 3 of the License, or (at your option)    #
 24  # any later version.                                                           #
 25  #                                                                              #
 26  # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY  #
 27  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    #
 28  # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
 29  # details.                                                                     #
 30  #                                                                              #
 31  # You should have received a copy of the GNU Lesser General Public License     #
 32  # along with PyGithub. If not, see <http://www.gnu.org/licenses/>.             #
 33  #                                                                              #
 34  ################################################################################
 35  from datetime import datetime
 36  from typing import Any, Dict
 37  
 38  from github.GithubObject import Attribute, CompletableGithubObject, NotSet
 39  
 40  
 41  class RepositoryKey(CompletableGithubObject):
 42      """
 43      This class represents RepositoryKeys. The reference can be found here https://docs.github.com/en/rest/reference/repos#deploy-keys
 44      """
 45  
 46      def _initAttributes(self) -> None:
 47          self._created_at: Attribute[datetime] = NotSet
 48          self._id: Attribute[int] = NotSet
 49          self._key: Attribute[str] = NotSet
 50          self._title: Attribute[str] = NotSet
 51          self._url: Attribute[str] = NotSet
 52          self._verified: Attribute[bool] = NotSet
 53          self._read_only: Attribute[bool] = NotSet
 54  
 55      def __repr__(self) -> str:
 56          return self.get__repr__({"id": self._id.value, "title": self._title.value})
 57  
 58      @property
 59      def created_at(self) -> datetime:
 60          self._completeIfNotSet(self._created_at)
 61          return self._created_at.value
 62  
 63      @property
 64      def id(self) -> int:
 65          self._completeIfNotSet(self._id)
 66          return self._id.value
 67  
 68      @property
 69      def key(self) -> str:
 70          self._completeIfNotSet(self._key)
 71          return self._key.value
 72  
 73      @property
 74      def title(self) -> str:
 75          self._completeIfNotSet(self._title)
 76          return self._title.value
 77  
 78      @property
 79      def url(self) -> str:
 80          self._completeIfNotSet(self._url)
 81          return self._url.value
 82  
 83      @property
 84      def verified(self) -> bool:
 85          self._completeIfNotSet(self._verified)
 86          return self._verified.value
 87  
 88      @property
 89      def read_only(self) -> bool:
 90          self._completeIfNotSet(self._read_only)
 91          return self._read_only.value
 92  
 93      def delete(self) -> None:
 94          """
 95          :calls: `DELETE /repos/{owner}/{repo}/keys/{id} <https://docs.github.com/en/rest/reference/repos#deploy-keys>`_
 96          """
 97          headers, data = self._requester.requestJsonAndCheck("DELETE", self.url)
 98  
 99      def _useAttributes(self, attributes: Dict[str, Any]) -> None:
100          if "created_at" in attributes:  # pragma no branch
101              self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
102          if "id" in attributes:  # pragma no branch
103              self._id = self._makeIntAttribute(attributes["id"])
104          if "key" in attributes:  # pragma no branch
105              self._key = self._makeStringAttribute(attributes["key"])
106          if "title" in attributes:  # pragma no branch
107              self._title = self._makeStringAttribute(attributes["title"])
108          if "url" in attributes:  # pragma no branch
109              self._url = self._makeStringAttribute(attributes["url"])
110          if "verified" in attributes:  # pragma no branch
111              self._verified = self._makeBoolAttribute(attributes["verified"])
112          if "read_only" in attributes:  # pragma no branch
113              self._read_only = self._makeBoolAttribute(attributes["read_only"])