StatsContributor.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 __future__ import annotations 27 28 from datetime import datetime 29 from typing import Any 30 31 import github.GithubObject 32 import github.NamedUser 33 from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet 34 35 36 class StatsContributor(NonCompletableGithubObject): 37 """ 38 This class represents StatsContributors. The reference can be found here https://docs.github.com/en/rest/reference/repos#get-all-contributor-commit-activity 39 """ 40 41 class Week(NonCompletableGithubObject): 42 """ 43 This class represents weekly statistics of a contributor. 44 """ 45 46 @property 47 def w(self) -> datetime: 48 return self._w.value 49 50 @property 51 def a(self) -> int: 52 return self._a.value 53 54 @property 55 def d(self) -> int: 56 return self._d.value 57 58 @property 59 def c(self) -> int: 60 return self._c.value 61 62 def _initAttributes(self) -> None: 63 self._w: Attribute[datetime] = NotSet 64 self._a: Attribute[int] = NotSet 65 self._d: Attribute[int] = NotSet 66 self._c: Attribute[int] = NotSet 67 68 def _useAttributes(self, attributes: dict[str, Any]) -> None: 69 if "w" in attributes: # pragma no branch 70 self._w = self._makeTimestampAttribute(attributes["w"]) 71 if "a" in attributes: # pragma no branch 72 self._a = self._makeIntAttribute(attributes["a"]) 73 if "d" in attributes: # pragma no branch 74 self._d = self._makeIntAttribute(attributes["d"]) 75 if "c" in attributes: # pragma no branch 76 self._c = self._makeIntAttribute(attributes["c"]) 77 78 @property 79 def author(self) -> github.NamedUser.NamedUser: 80 return self._author.value 81 82 @property 83 def total(self) -> int: 84 return self._total.value 85 86 @property 87 def weeks(self) -> list[Week]: 88 return self._weeks.value 89 90 def _initAttributes(self) -> None: 91 self._author: Attribute[github.NamedUser.NamedUser] = NotSet 92 self._total: Attribute[int] = NotSet 93 self._weeks: Attribute[list[StatsContributor.Week]] = NotSet 94 95 def _useAttributes(self, attributes: dict[str, Any]) -> None: 96 if "author" in attributes: # pragma no branch 97 self._author = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["author"]) 98 if "total" in attributes: # pragma no branch 99 self._total = self._makeIntAttribute(attributes["total"]) 100 if "weeks" in attributes: # pragma no branch 101 self._weeks = self._makeListOfClassesAttribute(self.Week, attributes["weeks"])