/ github / Clones.py
Clones.py
 1  ############################ Copyrights and license ############################
 2  #                                                                              #
 3  # Copyright 2018 Justin Kufro <jkufro@andrew.cmu.edu>                          #
 4  # Copyright 2018 Ivan Minno <iminno@andrew.cmu.edu>                            #
 5  # Copyright 2018 Zilei Gu <zileig@andrew.cmu.edu>                              #
 6  # Copyright 2018 Yves Zumbach <yzumbach@andrew.cmu.edu>                        #
 7  # Copyright 2018 Leying Chen <leyingc@andrew.cmu.edu>                          #
 8  #                                                                              #
 9  # This file is part of PyGithub.                                               #
10  # http://pygithub.readthedocs.io/                                              #
11  #                                                                              #
12  # PyGithub is free software: you can redistribute it and/or modify it under    #
13  # the terms of the GNU Lesser General Public License as published by the Free  #
14  # Software Foundation, either version 3 of the License, or (at your option)    #
15  # any later version.                                                           #
16  #                                                                              #
17  # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY  #
18  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    #
19  # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
20  # details.                                                                     #
21  #                                                                              #
22  # You should have received a copy of the GNU Lesser General Public License     #
23  # along with PyGithub. If not, see <http://www.gnu.org/licenses/>.             #
24  #                                                                              #
25  ################################################################################
26  from datetime import datetime
27  from typing import Any, Dict
28  
29  from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet
30  
31  
32  class Clones(NonCompletableGithubObject):
33      """
34      This class represents a popular Path for a GitHub repository.
35      The reference can be found here https://docs.github.com/en/rest/reference/repos#get-repository-clones
36      """
37  
38      def _initAttributes(self) -> None:
39          self._timestamp: Attribute[datetime] = NotSet
40          self._count: Attribute[int] = NotSet
41          self._uniques: Attribute[int] = NotSet
42  
43      def __repr__(self) -> str:
44          return self.get__repr__(
45              {
46                  "timestamp": self._timestamp.value,
47                  "count": self._count.value,
48                  "uniques": self._uniques.value,
49              }
50          )
51  
52      @property
53      def timestamp(self) -> datetime:
54          return self._timestamp.value
55  
56      @property
57      def count(self) -> int:
58          return self._count.value
59  
60      @property
61      def uniques(self) -> int:
62          return self._uniques.value
63  
64      def _useAttributes(self, attributes: Dict[str, Any]) -> None:
65          if "timestamp" in attributes:  # pragma no branch
66              self._timestamp = self._makeDatetimeAttribute(attributes["timestamp"])
67          if "count" in attributes:  # pragma no branch
68              self._count = self._makeIntAttribute(attributes["count"])
69          if "uniques" in attributes:  # pragma no branch
70              self._uniques = self._makeIntAttribute(attributes["uniques"])