/ github / GitReleaseAsset.py
GitReleaseAsset.py
  1  ############################ Copyrights and license ############################
  2  #                                                                              #
  3  # Copyright 2017 Chris McBride <thehighlander@users.noreply.github.com>        #
  4  # Copyright 2017 Simon <spam@esemi.ru>                                         #
  5  # Copyright 2018 Wan Liuyang <tsfdye@gmail.com>                                #
  6  # Copyright 2018 sfdye <tsfdye@gmail.com>                                      #
  7  #                                                                              #
  8  # This file is part of PyGithub.                                               #
  9  # http://pygithub.readthedocs.io/                                              #
 10  #                                                                              #
 11  # PyGithub is free software: you can redistribute it and/or modify it under    #
 12  # the terms of the GNU Lesser General Public License as published by the Free  #
 13  # Software Foundation, either version 3 of the License, or (at your option)    #
 14  # any later version.                                                           #
 15  #                                                                              #
 16  # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY  #
 17  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    #
 18  # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
 19  # details.                                                                     #
 20  #                                                                              #
 21  # You should have received a copy of the GNU Lesser General Public License     #
 22  # along with PyGithub. If not, see <http://www.gnu.org/licenses/>.             #
 23  #                                                                              #
 24  ################################################################################
 25  from __future__ import annotations
 26  
 27  from datetime import datetime
 28  from typing import Any
 29  
 30  import github.NamedUser
 31  from github.GithubObject import Attribute, CompletableGithubObject, NotSet
 32  
 33  
 34  class GitReleaseAsset(CompletableGithubObject):
 35      """
 36      This class represents GitReleaseAssets. The reference can be found here https://docs.github.com/en/rest/reference/repos#releases
 37      """
 38  
 39      def _initAttributes(self) -> None:
 40          self._url: Attribute[str] = NotSet
 41          self._id: Attribute[int] = NotSet
 42          self._name: Attribute[str] = NotSet
 43          self._label: Attribute[str] = NotSet
 44          self._content_type: Attribute[str] = NotSet
 45          self._state: Attribute[str] = NotSet
 46          self._size: Attribute[int] = NotSet
 47          self._download_count: Attribute[int] = NotSet
 48          self._created_at: Attribute[datetime] = NotSet
 49          self._updated_at: Attribute[datetime] = NotSet
 50          self._browser_download_url: Attribute[str] = NotSet
 51          self._uploader: Attribute[github.NamedUser.NamedUser] = NotSet
 52  
 53      def __repr__(self) -> str:
 54          return self.get__repr__({"url": self.url})
 55  
 56      @property
 57      def url(self) -> str:
 58          self._completeIfNotSet(self._url)
 59          return self._url.value
 60  
 61      @property
 62      def id(self) -> int:
 63          self._completeIfNotSet(self._id)
 64          return self._id.value
 65  
 66      @property
 67      def name(self) -> str:
 68          self._completeIfNotSet(self._name)
 69          return self._name.value
 70  
 71      @property
 72      def label(self) -> str:
 73          self._completeIfNotSet(self._label)
 74          return self._label.value
 75  
 76      @property
 77      def content_type(self) -> str:
 78          self._completeIfNotSet(self._content_type)
 79          return self._content_type.value
 80  
 81      @property
 82      def state(self) -> str:
 83          self._completeIfNotSet(self._state)
 84          return self._state.value
 85  
 86      @property
 87      def size(self) -> int:
 88          self._completeIfNotSet(self._size)
 89          return self._size.value
 90  
 91      @property
 92      def download_count(self) -> int:
 93          self._completeIfNotSet(self._download_count)
 94          return self._download_count.value
 95  
 96      @property
 97      def created_at(self) -> datetime:
 98          self._completeIfNotSet(self._created_at)
 99          return self._created_at.value
100  
101      @property
102      def updated_at(self) -> datetime:
103          self._completeIfNotSet(self._updated_at)
104          return self._updated_at.value
105  
106      @property
107      def browser_download_url(self) -> str:
108          self._completeIfNotSet(self._browser_download_url)
109          return self._browser_download_url.value
110  
111      @property
112      def uploader(self) -> github.NamedUser.NamedUser:
113          self._completeIfNotSet(self._uploader)
114          return self._uploader.value
115  
116      def delete_asset(self) -> bool:
117          """
118          Delete asset from the release.
119          """
120          headers, data = self._requester.requestJsonAndCheck("DELETE", self.url)
121          return True
122  
123      def update_asset(self, name: str, label: str = "") -> GitReleaseAsset:
124          """
125          Update asset metadata.
126          """
127          assert isinstance(name, str), name
128          assert isinstance(label, str), label
129          post_parameters = {"name": name, "label": label}
130          headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters)
131          return GitReleaseAsset(self._requester, headers, data, completed=True)
132  
133      def _useAttributes(self, attributes: dict[str, Any]) -> None:
134          if "url" in attributes:  # pragma no branch
135              self._url = self._makeStringAttribute(attributes["url"])
136          if "id" in attributes:  # pragma no branch
137              self._id = self._makeIntAttribute(attributes["id"])
138          if "name" in attributes:  # pragma no branch
139              self._name = self._makeStringAttribute(attributes["name"])
140          if "label" in attributes:  # pragma no branch
141              self._label = self._makeStringAttribute(attributes["label"])
142          if "uploader" in attributes:  # pragma no branch
143              self._uploader = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["uploader"])
144          if "content_type" in attributes:  # pragma no branch
145              self._content_type = self._makeStringAttribute(attributes["content_type"])
146          if "state" in attributes:  # pragma no branch
147              self._state = self._makeStringAttribute(attributes["state"])
148          if "size" in attributes:  # pragma no branch
149              self._size = self._makeIntAttribute(attributes["size"])
150          if "download_count" in attributes:  # pragma no branch
151              self._download_count = self._makeIntAttribute(attributes["download_count"])
152          if "created_at" in attributes:  # pragma no branch
153              self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
154          if "updated_at" in attributes:  # pragma no branch
155              self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"])
156          if "browser_download_url" in attributes:  # pragma no branch
157              self._browser_download_url = self._makeStringAttribute(attributes["browser_download_url"])