Skip to content

Commit 6d501b2

Browse files
dhruvmanilawrecker
andauthored
Add support for Check Suites (PyGithub#1764)
* Add initial support for Check Suites * Add API call detail in CheckSuite.rerequest * Update Accept header with general instead of preview * Add 'get check runs' endpoint for CheckSuite with stubs * Add create check suite endpoint with stub * Update CheckSuite tests with creat check suite endpoint * Add update check suites preferences endpoint * Add repository preferences object and stub file * Add update check suite preferences tests Needed for PyGithub#1621 Co-authored-by: Raju Subramanian <[email protected]>
1 parent 197e065 commit 6d501b2

20 files changed

+956
-5
lines changed

github/CheckSuite.py

+275
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
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"])

github/CheckSuite.pyi

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from datetime import datetime
2+
from typing import Any, Dict, List
3+
4+
from github.CheckRun import CheckRun
5+
from github.GitCommit import GitCommit
6+
from github.GithubApp import GithubApp
7+
from github.GithubObject import CompletableGithubObject
8+
from github.PaginatedList import PaginatedList
9+
from github.PullRequest import PullRequest
10+
from github.Repository import Repository
11+
12+
class CheckSuite(CompletableGithubObject):
13+
def __repr__(self) -> str: ...
14+
def _initAttributes(self) -> None: ...
15+
def _useAttributes(self, attributes: Dict[str, Any]) -> None: ...
16+
@property
17+
def after(self) -> str: ...
18+
@property
19+
def app(self) -> GithubApp: ...
20+
@property
21+
def before(self) -> str: ...
22+
@property
23+
def check_runs_url(self) -> str: ...
24+
@property
25+
def conclusion(self) -> str: ...
26+
@property
27+
def created_at(self) -> datetime: ...
28+
@property
29+
def head_branch(self) -> str: ...
30+
@property
31+
def head_commit(self) -> GitCommit: ...
32+
@property
33+
def head_sha(self) -> str: ...
34+
@property
35+
def id(self) -> int: ...
36+
@property
37+
def latest_check_runs_count(self) -> int: ...
38+
@property
39+
def pull_requests(self) -> List[PullRequest]: ...
40+
@property
41+
def repository(self) -> Repository: ...
42+
@property
43+
def status(self) -> str: ...
44+
@property
45+
def updated_at(self) -> datetime: ...
46+
@property
47+
def url(self) -> str: ...
48+
def rerequest(self) -> bool: ...
49+
def get_check_runs(
50+
self, check_name: str, status: str, filter: str
51+
) -> PaginatedList[CheckRun]: ...

github/Commit.py

+29
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
################################################################################
3434

3535
import github.CheckRun
36+
import github.CheckSuite
3637
import github.CommitCombinedStatus
3738
import github.CommitComment
3839
import github.CommitStats
@@ -293,6 +294,34 @@ def get_check_runs(
293294
list_item="check_runs",
294295
)
295296

297+
def get_check_suites(
298+
self, app_id=github.GithubObject.NotSet, check_name=github.GithubObject.NotSet
299+
):
300+
"""
301+
:class: `GET /repos/:owner/:repo/commits/:ref/check-suites <https://docs.github.com/en/rest/reference/checks#list-check-suites-for-a-git-reference>`_
302+
:param app_id: int
303+
:param check_name: string
304+
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.CheckSuite.CheckSuite`
305+
"""
306+
assert app_id is github.GithubObject.NotSet or isinstance(app_id, int), app_id
307+
assert check_name is github.GithubObject.NotSet or isinstance(
308+
check_name, str
309+
), check_name
310+
parameters = dict()
311+
if app_id is not github.GithubObject.NotSet:
312+
parameters["app_id"] = app_id
313+
if check_name is not github.GithubObject.NotSet:
314+
parameters["check_name"] = check_name
315+
request_headers = {"Accept": "application/vnd.github.v3+json"}
316+
return github.PaginatedList.PaginatedList(
317+
github.CheckSuite.CheckSuite,
318+
self._requester,
319+
self.url + "/check-suites",
320+
parameters,
321+
headers=request_headers,
322+
list_item="check_suites",
323+
)
324+
296325
@property
297326
def _identity(self):
298327
return self.sha

github/Commit.pyi

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Any, Dict, List, Union
22

33
from github.CheckRun import CheckRun
4+
from github.CheckSuite import CheckSuite
45
from github.CommitCombinedStatus import CommitCombinedStatus
56
from github.CommitComment import CommitComment
67
from github.CommitStats import CommitStats
@@ -41,6 +42,11 @@ class Commit(CompletableGithubObject):
4142
) -> CommitStatus: ...
4243
@property
4344
def files(self) -> List[File]: ...
45+
def get_check_suites(
46+
self,
47+
app_id: Union[_NotSetType, int],
48+
check_name: Union[_NotSetType, str],
49+
) -> PaginatedList[CheckSuite]: ...
4450
def get_combined_status(self) -> CommitCombinedStatus: ...
4551
def get_comments(self) -> PaginatedList[CommitComment]: ...
4652
def get_statuses(self) -> PaginatedList[CommitStatus]: ...

0 commit comments

Comments
 (0)