/ github / StatsCommitActivity.py
StatsCommitActivity.py
 1  ############################ Copyrights and license ############################
 2  #                                                                              #
 3  # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net>                 #
 4  # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net>                 #
 5  # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com>          #
 6  # Copyright 2018 Wan Liuyang <tsfdye@gmail.com>                                #
 7  # Copyright 2018 sfdye <tsfdye@gmail.com>                                      #
 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  import github.GithubObject
30  from github.GithubObject import Attribute
31  
32  
33  class StatsCommitActivity(github.GithubObject.NonCompletableGithubObject):
34      """
35      This class represents StatsCommitActivities. The reference can be found here https://docs.github.com/en/rest/reference/repos#get-the-last-year-of-commit-activity
36      """
37  
38      def _initAttributes(self) -> None:
39          self._week: Attribute[datetime] = github.GithubObject.NotSet
40          self._total: Attribute[int] = github.GithubObject.NotSet
41          self._days: Attribute[int] = github.GithubObject.NotSet
42  
43      @property
44      def week(self) -> datetime:
45          return self._week.value
46  
47      @property
48      def total(self) -> int:
49          return self._total.value
50  
51      @property
52      def days(self) -> int:
53          return self._days.value
54  
55      def _useAttributes(self, attributes: Dict[str, Any]) -> None:
56          if "week" in attributes:  # pragma no branch
57              self._week = self._makeTimestampAttribute(attributes["week"])
58          if "total" in attributes:  # pragma no branch
59              self._total = self._makeIntAttribute(attributes["total"])
60          if "days" in attributes:  # pragma no branch
61              self._days = self._makeListOfIntsAttribute(attributes["days"])