Comparison.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 Peter Buckley <dx-pbuckley@users.noreply.github.com> # 9 # Copyright 2018 Wan Liuyang <tsfdye@gmail.com> # 10 # Copyright 2018 sfdye <tsfdye@gmail.com> # 11 # # 12 # This file is part of PyGithub. # 13 # http://pygithub.readthedocs.io/ # 14 # # 15 # PyGithub is free software: you can redistribute it and/or modify it under # 16 # the terms of the GNU Lesser General Public License as published by the Free # 17 # Software Foundation, either version 3 of the License, or (at your option) # 18 # any later version. # 19 # # 20 # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # 21 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # 22 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # 23 # details. # 24 # # 25 # You should have received a copy of the GNU Lesser General Public License # 26 # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # 27 # # 28 ################################################################################ 29 from __future__ import annotations 30 31 from typing import Any 32 33 import github.Commit 34 import github.File 35 from github.GithubObject import Attribute, CompletableGithubObject, NotSet 36 37 38 class Comparison(CompletableGithubObject): 39 """ 40 This class represents Comparisons 41 """ 42 43 def _initAttributes(self) -> None: 44 self._ahead_by: Attribute[int] = NotSet 45 self._base_commit: Attribute[github.Commit.Commit] = NotSet 46 self._behind_by: Attribute[int] = NotSet 47 self._commits: Attribute[list[github.Commit.Commit]] = NotSet 48 self._diff_url: Attribute[str] = NotSet 49 self._files: Attribute[list[github.File.File]] = NotSet 50 self._html_url: Attribute[str] = NotSet 51 self._merge_base_commit: Attribute[github.Commit.Commit] = NotSet 52 self._patch_url: Attribute[str] = NotSet 53 self._permalink_url: Attribute[str] = NotSet 54 self._status: Attribute[str] = NotSet 55 self._total_commits: Attribute[int] = NotSet 56 self._url: Attribute[str] = NotSet 57 58 def __repr__(self) -> str: 59 return self.get__repr__({"url": self._url.value}) 60 61 @property 62 def ahead_by(self) -> int: 63 self._completeIfNotSet(self._ahead_by) 64 return self._ahead_by.value 65 66 @property 67 def base_commit(self) -> github.Commit.Commit: 68 self._completeIfNotSet(self._base_commit) 69 return self._base_commit.value 70 71 @property 72 def behind_by(self) -> int: 73 self._completeIfNotSet(self._behind_by) 74 return self._behind_by.value 75 76 @property 77 def commits(self) -> list[github.Commit.Commit]: 78 self._completeIfNotSet(self._commits) 79 return self._commits.value 80 81 @property 82 def diff_url(self) -> str: 83 self._completeIfNotSet(self._diff_url) 84 return self._diff_url.value 85 86 @property 87 def files(self) -> list[github.File.File]: 88 self._completeIfNotSet(self._files) 89 return self._files.value 90 91 @property 92 def html_url(self) -> str: 93 self._completeIfNotSet(self._html_url) 94 return self._html_url.value 95 96 @property 97 def merge_base_commit(self) -> github.Commit.Commit: 98 self._completeIfNotSet(self._merge_base_commit) 99 return self._merge_base_commit.value 100 101 @property 102 def patch_url(self) -> str: 103 self._completeIfNotSet(self._patch_url) 104 return self._patch_url.value 105 106 @property 107 def permalink_url(self) -> str: 108 self._completeIfNotSet(self._permalink_url) 109 return self._permalink_url.value 110 111 @property 112 def status(self) -> str: 113 self._completeIfNotSet(self._status) 114 return self._status.value 115 116 @property 117 def total_commits(self) -> int: 118 self._completeIfNotSet(self._total_commits) 119 return self._total_commits.value 120 121 @property 122 def url(self) -> str: 123 self._completeIfNotSet(self._url) 124 return self._url.value 125 126 def _useAttributes(self, attributes: dict[str, Any]) -> None: 127 if "ahead_by" in attributes: # pragma no branch 128 self._ahead_by = self._makeIntAttribute(attributes["ahead_by"]) 129 if "base_commit" in attributes: # pragma no branch 130 self._base_commit = self._makeClassAttribute(github.Commit.Commit, attributes["base_commit"]) 131 if "behind_by" in attributes: # pragma no branch 132 self._behind_by = self._makeIntAttribute(attributes["behind_by"]) 133 if "commits" in attributes: # pragma no branch 134 self._commits = self._makeListOfClassesAttribute(github.Commit.Commit, attributes["commits"]) 135 if "diff_url" in attributes: # pragma no branch 136 self._diff_url = self._makeStringAttribute(attributes["diff_url"]) 137 if "files" in attributes: # pragma no branch 138 self._files = self._makeListOfClassesAttribute(github.File.File, attributes["files"]) 139 if "html_url" in attributes: # pragma no branch 140 self._html_url = self._makeStringAttribute(attributes["html_url"]) 141 if "merge_base_commit" in attributes: # pragma no branch 142 self._merge_base_commit = self._makeClassAttribute(github.Commit.Commit, attributes["merge_base_commit"]) 143 if "patch_url" in attributes: # pragma no branch 144 self._patch_url = self._makeStringAttribute(attributes["patch_url"]) 145 if "permalink_url" in attributes: # pragma no branch 146 self._permalink_url = self._makeStringAttribute(attributes["permalink_url"]) 147 if "status" in attributes: # pragma no branch 148 self._status = self._makeStringAttribute(attributes["status"]) 149 if "total_commits" in attributes: # pragma no branch 150 self._total_commits = self._makeIntAttribute(attributes["total_commits"]) 151 if "url" in attributes: # pragma no branch 152 self._url = self._makeStringAttribute(attributes["url"])