/ github / TimelineEvent.py
TimelineEvent.py
  1  ############################ Copyrights and license ############################
  2  #                                                                              #
  3  # Copyright 2019 Nick Campbell <nicholas.j.campbell@gmail.com>                 #
  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  import github.TimelineEventSource
 30  from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet
 31  
 32  
 33  class TimelineEvent(NonCompletableGithubObject):
 34      """
 35      This class represents IssueTimelineEvents. The reference can be found here https://docs.github.com/en/rest/reference/issues#timeline
 36      """
 37  
 38      def _initAttributes(self) -> None:
 39          self._actor: Attribute[github.NamedUser.NamedUser] = NotSet
 40          self._commit_id: Attribute[str] = NotSet
 41          self._created_at: Attribute[datetime] = NotSet
 42          self._event: Attribute[str] = NotSet
 43          self._id: Attribute[int] = NotSet
 44          self._node_id: Attribute[str] = NotSet
 45          self._commit_url: Attribute[str] = NotSet
 46          self._source: Attribute[github.TimelineEventSource.TimelineEventSource] = NotSet
 47          self._url: Attribute[str] = NotSet
 48  
 49      def __repr__(self) -> str:
 50          return self.get__repr__({"id": self._id.value})
 51  
 52      @property
 53      def actor(self) -> github.NamedUser.NamedUser:
 54          return self._actor.value
 55  
 56      @property
 57      def commit_id(self) -> str:
 58          return self._commit_id.value
 59  
 60      @property
 61      def created_at(self) -> datetime:
 62          return self._created_at.value
 63  
 64      @property
 65      def event(self) -> str:
 66          return self._event.value
 67  
 68      @property
 69      def id(self) -> int:
 70          return self._id.value
 71  
 72      @property
 73      def node_id(self) -> str:
 74          return self._node_id.value
 75  
 76      @property
 77      def commit_url(self) -> str:
 78          return self._commit_url.value
 79  
 80      @property
 81      def source(self) -> github.TimelineEventSource.TimelineEventSource | None:
 82          # only available on `cross-referenced` events.
 83          if self.event == "cross-referenced" and self._source is not NotSet:
 84              return self._source.value
 85          return None
 86  
 87      @property
 88      def body(self) -> str | None:
 89          if self.event == "commented" and self._body is not NotSet:
 90              return self._body.value
 91          return None
 92  
 93      @property
 94      def author_association(self) -> str | None:
 95          if self.event == "commented" and self._author_association is not NotSet:
 96              return self._author_association.value
 97          return None
 98  
 99      @property
100      def url(self) -> str:
101          return self._url.value
102  
103      def _useAttributes(self, attributes: dict[str, Any]) -> None:
104          if "actor" in attributes:  # pragma no branch
105              self._actor = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["actor"])
106          if "commit_id" in attributes:  # pragma no branch
107              self._commit_id = self._makeStringAttribute(attributes["commit_id"])
108          if "created_at" in attributes:  # pragma no branch
109              self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
110          if "event" in attributes:  # pragma no branch
111              self._event = self._makeStringAttribute(attributes["event"])
112          if "id" in attributes:  # pragma no branch
113              self._id = self._makeIntAttribute(attributes["id"])
114          if "node_id" in attributes:  # pragma no branch
115              self._node_id = self._makeStringAttribute(attributes["node_id"])
116          if "commit_url" in attributes:  # pragma no branch
117              self._commit_url = self._makeStringAttribute(attributes["commit_url"])
118          if "source" in attributes:  # pragma no branch
119              self._source = self._makeClassAttribute(
120                  github.TimelineEventSource.TimelineEventSource, attributes["source"]
121              )
122          if "body" in attributes:  # pragma no branch
123              self._body = self._makeStringAttribute(attributes["body"])
124          if "author_association" in attributes:  # pragma no branch
125              self._author_association = self._makeStringAttribute(attributes["author_association"])
126          if "url" in attributes:  # pragma no branch
127              self._url = self._makeStringAttribute(attributes["url"])