/ github / GistComment.py
GistComment.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 Vincent Jacques <vincent@vincent-jacques.net>                 #
  7  # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net>                 #
  8  # Copyright 2016 Jannis Gebauer <ja.geb@me.com>                                #
  9  # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com>          #
 10  # Copyright 2018 Wan Liuyang <tsfdye@gmail.com>                                #
 11  # Copyright 2018 sfdye <tsfdye@gmail.com>                                      #
 12  #                                                                              #
 13  # This file is part of PyGithub.                                               #
 14  # http://pygithub.readthedocs.io/                                              #
 15  #                                                                              #
 16  # PyGithub is free software: you can redistribute it and/or modify it under    #
 17  # the terms of the GNU Lesser General Public License as published by the Free  #
 18  # Software Foundation, either version 3 of the License, or (at your option)    #
 19  # any later version.                                                           #
 20  #                                                                              #
 21  # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY  #
 22  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    #
 23  # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
 24  # details.                                                                     #
 25  #                                                                              #
 26  # You should have received a copy of the GNU Lesser General Public License     #
 27  # along with PyGithub. If not, see <http://www.gnu.org/licenses/>.             #
 28  #                                                                              #
 29  ################################################################################
 30  from __future__ import annotations
 31  
 32  from datetime import datetime
 33  from typing import Any
 34  
 35  import github.GithubObject
 36  import github.NamedUser
 37  from github.GithubObject import Attribute, CompletableGithubObject, NotSet
 38  
 39  
 40  class GistComment(CompletableGithubObject):
 41      """
 42      This class represents GistComments. The reference can be found here https://docs.github.com/en/rest/reference/gists#comments
 43      """
 44  
 45      def _initAttributes(self) -> None:
 46          self._body: Attribute[str] = NotSet
 47          self._created_at: Attribute[datetime] = NotSet
 48          self._id: Attribute[int] = NotSet
 49          self._updated_at: Attribute[datetime] = NotSet
 50          self._url: Attribute[str] = NotSet
 51          self._user: Attribute[github.NamedUser.NamedUser] = NotSet
 52  
 53      def __repr__(self) -> str:
 54          return self.get__repr__({"id": self._id.value, "user": self._user.value})
 55  
 56      @property
 57      def body(self) -> str:
 58          self._completeIfNotSet(self._body)
 59          return self._body.value
 60  
 61      @property
 62      def created_at(self) -> datetime:
 63          self._completeIfNotSet(self._created_at)
 64          return self._created_at.value
 65  
 66      @property
 67      def id(self) -> int:
 68          self._completeIfNotSet(self._id)
 69          return self._id.value
 70  
 71      @property
 72      def updated_at(self) -> datetime:
 73          self._completeIfNotSet(self._updated_at)
 74          return self._updated_at.value
 75  
 76      @property
 77      def url(self) -> str:
 78          self._completeIfNotSet(self._url)
 79          return self._url.value
 80  
 81      @property
 82      def user(self) -> github.NamedUser.NamedUser:
 83          self._completeIfNotSet(self._user)
 84          return self._user.value
 85  
 86      def delete(self) -> None:
 87          """
 88          :calls: `DELETE /gists/{gist_id}/comments/{id} <https://docs.github.com/en/rest/reference/gists#comments>`_
 89          """
 90          headers, data = self._requester.requestJsonAndCheck("DELETE", self.url)
 91  
 92      def edit(self, body: str) -> None:
 93          """
 94          :calls: `PATCH /gists/{gist_id}/comments/{id} <https://docs.github.com/en/rest/reference/gists#comments>`_
 95          """
 96          assert isinstance(body, str), body
 97          post_parameters = {
 98              "body": body,
 99          }
100          headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters)
101          self._useAttributes(data)
102  
103      def _useAttributes(self, attributes: dict[str, Any]) -> None:
104          if "body" in attributes:  # pragma no branch
105              self._body = self._makeStringAttribute(attributes["body"])
106          if "created_at" in attributes:  # pragma no branch
107              self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
108          if "id" in attributes:  # pragma no branch
109              self._id = self._makeIntAttribute(attributes["id"])
110          if "updated_at" in attributes:  # pragma no branch
111              self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"])
112          if "url" in attributes:  # pragma no branch
113              self._url = self._makeStringAttribute(attributes["url"])
114          if "user" in attributes:  # pragma no branch
115              self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"])