|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +############################ Copyrights and license ############################ |
| 4 | +# # |
| 5 | +# Copyright 2020 Raju Subramanian <[email protected]> # |
| 6 | +# # |
| 7 | +# This file is part of PyGithub. # |
| 8 | +# http://pygithub.readthedocs.io/ # |
| 9 | +# # |
| 10 | +# PyGithub is free software: you can redistribute it and/or modify it under # |
| 11 | +# the terms of the GNU Lesser General Public License as published by the Free # |
| 12 | +# Software Foundation, either version 3 of the License, or (at your option) # |
| 13 | +# any later version. # |
| 14 | +# # |
| 15 | +# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # |
| 16 | +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # |
| 17 | +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # |
| 18 | +# details. # |
| 19 | +# # |
| 20 | +# You should have received a copy of the GNU Lesser General Public License # |
| 21 | +# along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # |
| 22 | +# # |
| 23 | +################################################################################ |
| 24 | + |
| 25 | +import github |
| 26 | + |
| 27 | + |
| 28 | +class CheckSuite(github.GithubObject.CompletableGithubObject): |
| 29 | + """ |
| 30 | + This class represents check suites. The reference can be found here https://docs.github.com/en/rest/reference/checks#check-suites |
| 31 | + """ |
| 32 | + |
| 33 | + def __repr__(self): |
| 34 | + return self.get__repr__({"id": self._id.value, "url": self._url.value}) |
| 35 | + |
| 36 | + @property |
| 37 | + def after(self): |
| 38 | + """ |
| 39 | + :type: string |
| 40 | + """ |
| 41 | + self._completeIfNotSet(self._after) |
| 42 | + return self._after.value |
| 43 | + |
| 44 | + @property |
| 45 | + def app(self): |
| 46 | + """ |
| 47 | + :type: :class:`github.GithubApp.GithubApp` |
| 48 | + """ |
| 49 | + self._completeIfNotSet(self._app) |
| 50 | + return self._app.value |
| 51 | + |
| 52 | + @property |
| 53 | + def before(self): |
| 54 | + """ |
| 55 | + :type: string |
| 56 | + """ |
| 57 | + self._completeIfNotSet(self._before) |
| 58 | + return self._before.value |
| 59 | + |
| 60 | + @property |
| 61 | + def check_runs_url(self): |
| 62 | + """ |
| 63 | + :type: string |
| 64 | + """ |
| 65 | + self._completeIfNotSet(self._check_runs_url) |
| 66 | + return self._check_runs_url.value |
| 67 | + |
| 68 | + @property |
| 69 | + def conclusion(self): |
| 70 | + """ |
| 71 | + :type: string |
| 72 | + """ |
| 73 | + self._completeIfNotSet(self._conclusion) |
| 74 | + return self._conclusion.value |
| 75 | + |
| 76 | + @property |
| 77 | + def created_at(self): |
| 78 | + """ |
| 79 | + :type: datetime.datetime |
| 80 | + """ |
| 81 | + self._completeIfNotSet(self._created_at) |
| 82 | + return self._created_at.value |
| 83 | + |
| 84 | + @property |
| 85 | + def head_branch(self): |
| 86 | + """ |
| 87 | + :type: string |
| 88 | + """ |
| 89 | + self._completeIfNotSet(self._head_branch) |
| 90 | + return self._head_branch.value |
| 91 | + |
| 92 | + @property |
| 93 | + def head_commit(self): |
| 94 | + """ |
| 95 | + :type: :class:`github.GitCommit.GitCommit` |
| 96 | + """ |
| 97 | + self._completeIfNotSet(self._head_commit) |
| 98 | + return self._head_commit.value |
| 99 | + |
| 100 | + @property |
| 101 | + def head_sha(self): |
| 102 | + """ |
| 103 | + :type: string |
| 104 | + """ |
| 105 | + self._completeIfNotSet(self._head_sha) |
| 106 | + return self._head_sha.value |
| 107 | + |
| 108 | + @property |
| 109 | + def id(self): |
| 110 | + """ |
| 111 | + :type: int |
| 112 | + """ |
| 113 | + self._completeIfNotSet(self._id) |
| 114 | + return self._id.value |
| 115 | + |
| 116 | + @property |
| 117 | + def latest_check_runs_count(self): |
| 118 | + """ |
| 119 | + :type: int |
| 120 | + """ |
| 121 | + self._completeIfNotSet(self._latest_check_runs_count) |
| 122 | + return self._latest_check_runs_count.value |
| 123 | + |
| 124 | + @property |
| 125 | + def pull_requests(self): |
| 126 | + """ |
| 127 | + :type: list of :class:`github.PullRequest.PullRequest` |
| 128 | + """ |
| 129 | + self._completeIfNotSet(self._pull_requests) |
| 130 | + return self._pull_requests.value |
| 131 | + |
| 132 | + @property |
| 133 | + def repository(self): |
| 134 | + """ |
| 135 | + :type: :class:`github.Repository.Repository` |
| 136 | + """ |
| 137 | + self._completeIfNotSet(self._repository) |
| 138 | + return self._repository.value |
| 139 | + |
| 140 | + @property |
| 141 | + def status(self): |
| 142 | + """ |
| 143 | + :type: string |
| 144 | + """ |
| 145 | + self._completeIfNotSet(self._status) |
| 146 | + return self._status.value |
| 147 | + |
| 148 | + @property |
| 149 | + def updated_at(self): |
| 150 | + """ |
| 151 | + :type: datetime.datetime |
| 152 | + """ |
| 153 | + self._completeIfNotSet(self._updated_at) |
| 154 | + return self._updated_at.value |
| 155 | + |
| 156 | + @property |
| 157 | + def url(self): |
| 158 | + """ |
| 159 | + :type: string |
| 160 | + """ |
| 161 | + self._completeIfNotSet(self._url) |
| 162 | + return self._url.value |
| 163 | + |
| 164 | + def rerequest(self): |
| 165 | + """ |
| 166 | + :calls: `POST /repos/:owner/:repo/check-suites/:check_suite_id/rerequest <https://docs.github.com/en/rest/reference/checks#rerequest-a-check-suite>`_ |
| 167 | + :rtype: bool |
| 168 | + """ |
| 169 | + request_headers = {"Accept": "application/vnd.github.v3+json"} |
| 170 | + status, _, _ = self._requester.requestJson( |
| 171 | + "POST", self.url + "/rerequest", headers=request_headers |
| 172 | + ) |
| 173 | + return status == 201 |
| 174 | + |
| 175 | + def get_check_runs( |
| 176 | + self, |
| 177 | + check_name=github.GithubObject.NotSet, |
| 178 | + status=github.GithubObject.NotSet, |
| 179 | + filter=github.GithubObject.NotSet, |
| 180 | + ): |
| 181 | + """ |
| 182 | + :calls: `GET /repos/:owner/:repo/check-suites/:check_suite_id/check-runs <https://docs.github.com/en/rest/reference/checks#list-check-runs-in-a-check-suite>`_ |
| 183 | + :param check_name: string |
| 184 | + :param status: string |
| 185 | + :param filter: string |
| 186 | + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.CheckRun.CheckRun` |
| 187 | + """ |
| 188 | + assert check_name is github.GithubObject.NotSet or isinstance( |
| 189 | + check_name, str |
| 190 | + ), check_name |
| 191 | + assert status is github.GithubObject.NotSet or isinstance(status, str), status |
| 192 | + assert filter is github.GithubObject.NotSet or isinstance(filter, str), filter |
| 193 | + url_parameters = dict() |
| 194 | + if check_name is not github.GithubObject.NotSet: |
| 195 | + url_parameters["check_name"] = check_name |
| 196 | + if status is not github.GithubObject.NotSet: |
| 197 | + url_parameters["status"] = status |
| 198 | + if status is not github.GithubObject.NotSet: |
| 199 | + url_parameters["filter"] = filter |
| 200 | + return github.PaginatedList.PaginatedList( |
| 201 | + github.CheckRun.CheckRun, |
| 202 | + self._requester, |
| 203 | + self.url + "/check-runs", |
| 204 | + url_parameters, |
| 205 | + headers={"Accept": "application/vnd.github.v3+json"}, |
| 206 | + list_item="check_runs", |
| 207 | + ) |
| 208 | + |
| 209 | + def _initAttributes(self): |
| 210 | + self._after = github.GithubObject.NotSet |
| 211 | + self._app = github.GithubObject.NotSet |
| 212 | + self._before = github.GithubObject.NotSet |
| 213 | + self._check_runs_url = github.GithubObject.NotSet |
| 214 | + self._conclusion = github.GithubObject.NotSet |
| 215 | + self._created_at = github.GithubObject.NotSet |
| 216 | + self._head_branch = github.GithubObject.NotSet |
| 217 | + self._head_commit = github.GithubObject.NotSet |
| 218 | + self._head_sha = github.GithubObject.NotSet |
| 219 | + self._id = github.GithubObject.NotSet |
| 220 | + self._latest_check_runs_count = github.GithubObject.NotSet |
| 221 | + self._pull_requests = github.GithubObject.NotSet |
| 222 | + self._repository = github.GithubObject.NotSet |
| 223 | + self._status = github.GithubObject.NotSet |
| 224 | + self._updated_at = github.GithubObject.NotSet |
| 225 | + self._url = github.GithubObject.NotSet |
| 226 | + |
| 227 | + def _useAttributes(self, attributes): |
| 228 | + if "after" in attributes: # pragma no branch |
| 229 | + self._after = self._makeStringAttribute(attributes["after"]) |
| 230 | + if "app" in attributes: # pragma no branch |
| 231 | + self._app = self._makeClassAttribute( |
| 232 | + github.GithubApp.GithubApp, attributes["app"] |
| 233 | + ) |
| 234 | + if "before" in attributes: # pragma no branch |
| 235 | + self._before = self._makeStringAttribute(attributes["before"]) |
| 236 | + if "check_runs_url" in attributes: # pragma no branch |
| 237 | + self._check_runs_url = self._makeStringAttribute( |
| 238 | + attributes["check_runs_url"] |
| 239 | + ) |
| 240 | + if "conclusion" in attributes: # pragma no branch |
| 241 | + self._conclusion = self._makeStringAttribute(attributes["conclusion"]) |
| 242 | + if "created_at" in attributes: # pragma no branch |
| 243 | + self._created_at = self._makeDatetimeAttribute(attributes["created_at"]) |
| 244 | + if "head_branch" in attributes: # pragma no branch |
| 245 | + self._head_branch = self._makeStringAttribute(attributes["head_branch"]) |
| 246 | + if "head_commit" in attributes: # pragma no branch |
| 247 | + # This JSON swaps the 'sha' attribute for an 'id' attribute. |
| 248 | + # The GitCommit object only looks for 'sha' |
| 249 | + if "id" in attributes["head_commit"]: |
| 250 | + attributes["head_commit"]["sha"] = attributes["head_commit"]["id"] |
| 251 | + self._head_commit = self._makeClassAttribute( |
| 252 | + github.GitCommit.GitCommit, attributes["head_commit"] |
| 253 | + ) |
| 254 | + if "head_sha" in attributes: # pragma no branch |
| 255 | + self._head_sha = self._makeStringAttribute(attributes["head_sha"]) |
| 256 | + if "id" in attributes: # pragma no branch |
| 257 | + self._id = self._makeIntAttribute(attributes["id"]) |
| 258 | + if "latest_check_runs_count" in attributes: # pragma no branch |
| 259 | + self._latest_check_runs_count = self._makeIntAttribute( |
| 260 | + attributes["latest_check_runs_count"] |
| 261 | + ) |
| 262 | + if "pull_requests" in attributes: # pragma no branch |
| 263 | + self._pull_requests = self._makeListOfClassesAttribute( |
| 264 | + github.PullRequest.PullRequest, attributes["pull_requests"] |
| 265 | + ) |
| 266 | + if "repository" in attributes: # pragma no branch |
| 267 | + self._repository = self._makeClassAttribute( |
| 268 | + github.Repository.Repository, attributes["repository"] |
| 269 | + ) |
| 270 | + if "status" in attributes: # pragma no branch |
| 271 | + self._status = self._makeStringAttribute(attributes["status"]) |
| 272 | + if "updated_at" in attributes: # pragma no branch |
| 273 | + self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"]) |
| 274 | + if "url" in attributes: # pragma no branch |
| 275 | + self._url = self._makeStringAttribute(attributes["url"]) |
0 commit comments