/ github / GitTree.py
GitTree.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  
31  from __future__ import annotations
32  
33  from typing import TYPE_CHECKING, Any
34  
35  import github.GitTreeElement
36  from github.GithubObject import Attribute, CompletableGithubObject, NotSet
37  
38  if TYPE_CHECKING:
39      from github.GitTreeElement import GitTreeElement
40  
41  
42  class GitTree(CompletableGithubObject):
43      """
44      This class represents GitTrees. The reference can be found here https://docs.github.com/en/rest/reference/git#trees
45      """
46  
47      def _initAttributes(self) -> None:
48          self._sha: Attribute[str] = NotSet
49          self._tree: Attribute[list[GitTreeElement]] = NotSet
50          self._url: Attribute[str] = NotSet
51  
52      def __repr__(self) -> str:
53          return self.get__repr__({"sha": self._sha.value})
54  
55      @property
56      def sha(self) -> str:
57          self._completeIfNotSet(self._sha)
58          return self._sha.value
59  
60      @property
61      def tree(self) -> list[GitTreeElement]:
62          self._completeIfNotSet(self._tree)
63          return self._tree.value
64  
65      @property
66      def url(self) -> str:
67          self._completeIfNotSet(self._url)
68          return self._url.value
69  
70      @property
71      def _identity(self) -> str:
72          return self.sha
73  
74      def _useAttributes(self, attributes: dict[str, Any]) -> None:
75          if "sha" in attributes:  # pragma no branch
76              self._sha = self._makeStringAttribute(attributes["sha"])
77          if "tree" in attributes:  # pragma no branch
78              self._tree = self._makeListOfClassesAttribute(github.GitTreeElement.GitTreeElement, attributes["tree"])
79          if "url" in attributes:  # pragma no branch
80              self._url = self._makeStringAttribute(attributes["url"])