Skip to content

Commit

Permalink
Sync CheckRun class with API spec (#3111)
Browse files Browse the repository at this point in the history
Adds the following attributes:
- deployment

Deprecates
- check_suite_id
  • Loading branch information
EnricoMi authored Jan 7, 2025
1 parent 29eb0f5 commit 3837c7d
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 68 deletions.
30 changes: 28 additions & 2 deletions github/CheckRun.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@
from datetime import datetime
from typing import TYPE_CHECKING, Any

from typing_extensions import deprecated

import github.CheckRunAnnotation
import github.CheckRunOutput
import github.CheckSuite
import github.Deployment
import github.GithubApp
import github.GithubObject
import github.PullRequest
Expand All @@ -52,6 +56,8 @@
if TYPE_CHECKING:
from github.CheckRunAnnotation import CheckRunAnnotation
from github.CheckRunOutput import CheckRunOutput
from github.CheckSuite import CheckSuite
from github.Deployment import Deployment
from github.GithubApp import GithubApp
from github.PullRequest import PullRequest

Expand All @@ -70,9 +76,11 @@ class CheckRun(CompletableGithubObject):

def _initAttributes(self) -> None:
self._app: Attribute[GithubApp] = NotSet
self._check_suite: Attribute[CheckSuite] = NotSet
self._check_suite_id: Attribute[int] = NotSet
self._completed_at: Attribute[datetime | None] = NotSet
self._conclusion: Attribute[str] = NotSet
self._deployment: Attribute[Deployment] = NotSet
self._details_url: Attribute[str] = NotSet
self._external_id: Attribute[str] = NotSet
self._head_sha: Attribute[str] = NotSet
Expand All @@ -95,6 +103,12 @@ def app(self) -> GithubApp:
return self._app.value

@property
def check_suite(self) -> CheckSuite:
self._completeIfNotSet(self._check_suite)
return self._check_suite.value

@property
@deprecated("Use property check_suite.id instead")
def check_suite_id(self) -> int:
self._completeIfNotSet(self._check_suite_id)
return self._check_suite_id.value
Expand All @@ -109,6 +123,11 @@ def conclusion(self) -> str:
self._completeIfNotSet(self._conclusion)
return self._conclusion.value

@property
def deployment(self) -> Deployment:
self._completeIfNotSet(self._deployment)
return self._deployment.value

@property
def details_url(self) -> str:
self._completeIfNotSet(self._details_url)
Expand Down Expand Up @@ -166,7 +185,6 @@ def status(self) -> str:

@property
def url(self) -> str:
self._completeIfNotSet(self._url)
return self._url.value

def get_annotations(self) -> PaginatedList[CheckRunAnnotation]:
Expand Down Expand Up @@ -238,11 +256,19 @@ def _useAttributes(self, attributes: dict[str, Any]) -> None:
self._app = self._makeClassAttribute(github.GithubApp.GithubApp, attributes["app"])
# This only gives us a dictionary with `id` attribute of `check_suite`
if "check_suite" in attributes and "id" in attributes["check_suite"]: # pragma no branch
self._check_suite_id = self._makeIntAttribute(attributes["check_suite"]["id"])
id = attributes["check_suite"]["id"]
if "url" not in attributes["check_suite"] and "url" in attributes:
url = attributes["url"].split("/")[:-2] + ["check-suites", str(id)]
attributes["check_suite"]["url"] = "/".join(url)
self._check_suite = self._makeClassAttribute(github.CheckSuite.CheckSuite, attributes["check_suite"])
# deprecated check suite id property
self._check_suite_id = self._makeIntAttribute(id)
if "completed_at" in attributes: # pragma no branch
self._completed_at = self._makeDatetimeAttribute(attributes["completed_at"])
if "conclusion" in attributes: # pragma no branch
self._conclusion = self._makeStringAttribute(attributes["conclusion"])
if "deployment" in attributes: # pragma no branch
self._deployment = self._makeClassAttribute(github.Deployment.Deployment, attributes["deployment"])
if "details_url" in attributes: # pragma no branch
self._details_url = self._makeStringAttribute(attributes["details_url"])
if "external_id" in attributes: # pragma no branch
Expand Down
2 changes: 1 addition & 1 deletion github/CheckSuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class CheckSuite(CompletableGithubObject):
https://docs.github.com/en/rest/reference/checks#check-suites
The OpenAPI schema can be found at
- /components/schemas/check-run/properties/check_suite
- /components/schemas/check-suite
"""
Expand Down Expand Up @@ -207,7 +208,6 @@ def url(self) -> str:
"""
:type: string
"""
self._completeIfNotSet(self._url)
return self._url.value

def rerequest(self) -> bool:
Expand Down
1 change: 1 addition & 0 deletions github/Deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Deployment(CompletableGithubObject):
The OpenAPI schema can be found at
- /components/schemas/deployment
- /components/schemas/deployment-simple
- /paths/"/repos/{owner}/{repo}/deployments"/post/responses/202/content/"application/json"/schema
"""
Expand Down
54 changes: 26 additions & 28 deletions tests/CheckRun.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
# #
################################################################################

from __future__ import annotations

from datetime import datetime, timezone

from . import Framework
Expand All @@ -33,45 +35,41 @@ def setUp(self):
super().setUp()
self.repo = self.g.get_repo("PyGithub/PyGithub")
self.testrepo = self.g.get_repo("dhruvmanila/pygithub-testing")
self.check_run_id = 1039891953
self.check_run_ref = "6bc9ecc8c849df4e45e60c1e6a5df8876180a20a"
self.check_run_id = 34942661139
self.check_run_ref = "10a7135a04f71e6101f8b013aded8a662d08fd1f"
self.check_run = self.repo.get_check_run(self.check_run_id)
self.commit = self.repo.get_commit(self.check_run_ref)

def testAttributes(self):
self.assertEqual(self.check_run.app.id, 15368)
self.assertEqual(self.check_run.app.slug, "github-actions")
self.assertEqual(self.check_run.check_suite_id, 1110219217)
self.assertEqual(self.check_run.check_suite.id, 32504127411)
self.assertEqual(
self.check_run.completed_at,
datetime(2020, 8, 28, 4, 21, 21, tzinfo=timezone.utc),
self.check_run.check_suite.url, "https://api.github.com/repos/PyGithub/PyGithub/check-suites/32504127411"
)
# check_suite is lazy, so accessing a property other than id or url fetches the suite object
self.assertEqual(self.check_run.check_suite.head_sha, "10a7135a04f71e6101f8b013aded8a662d08fd1f")
self.assertEqual(self.check_run.check_suite_id, 32504127411)
self.assertEqual(self.check_run.completed_at, datetime(2024, 12, 28, 16, 53, 10, tzinfo=timezone.utc))
self.assertEqual(self.check_run.conclusion, "success")
self.assertIsNone(self.check_run.deployment)
self.assertEqual(
self.check_run.details_url,
"https://github.com/PyGithub/PyGithub/runs/1039891953",
self.check_run.details_url, "https://github.com/PyGithub/PyGithub/actions/runs/12528252236/job/34942661139"
)
self.assertEqual(self.check_run.external_id, "6b512fe7-587c-5ecc-c4a3-03b7358c152d")
self.assertEqual(self.check_run.head_sha, "6bc9ecc8c849df4e45e60c1e6a5df8876180a20a")
self.assertEqual(self.check_run.external_id, "8ece7711-e8e8-5d87-8f8a-6791d424ecd6")
self.assertEqual(self.check_run.head_sha, "10a7135a04f71e6101f8b013aded8a662d08fd1f")
self.assertEqual(
self.check_run.html_url,
"https://github.com/PyGithub/PyGithub/runs/1039891953",
self.check_run.html_url, "https://github.com/PyGithub/PyGithub/actions/runs/12528252236/job/34942661139"
)
self.assertEqual(self.check_run.id, 1039891953)
self.assertEqual(self.check_run.name, "test (Python 3.8)")
self.assertEqual(self.check_run.node_id, "MDg6Q2hlY2tSdW4xMDM5ODkxOTUz")
self.assertEqual(self.check_run.output.annotations_count, 0)
self.assertEqual(self.check_run.id, 34942661139)
self.assertEqual(self.check_run.name, "test (Python 3.8 on Ubuntu)")
self.assertEqual(self.check_run.node_id, "CR_kwDOADYVqs8AAAAIIr6yEw")
self.assertEqual(self.check_run.output.annotations_count, 1)
self.assertEqual(len(self.check_run.pull_requests), 0)
self.assertEqual(
self.check_run.started_at,
datetime(2020, 8, 28, 4, 20, 27, tzinfo=timezone.utc),
)
self.assertEqual(self.check_run.started_at, datetime(2024, 12, 28, 16, 51, 59, tzinfo=timezone.utc))
self.assertEqual(self.check_run.status, "completed")
self.assertEqual(
self.check_run.url,
"https://api.github.com/repos/PyGithub/PyGithub/check-runs/1039891953",
)
self.assertEqual(repr(self.check_run), 'CheckRun(id=1039891953, conclusion="success")')
self.assertEqual(self.check_run.url, "https://api.github.com/repos/PyGithub/PyGithub/check-runs/34942661139")
self.assertEqual(repr(self.check_run), 'CheckRun(id=34942661139, conclusion="success")')

def testCheckRunOutputAttributes(self):
check_run_output = self.repo.get_check_run(1039891917).output
Expand All @@ -93,7 +91,7 @@ def testGetCheckRunsForRef(self):
self.assertEqual(check_runs.totalCount, 4)
self.assertListEqual(
[check_run.id for check_run in check_runs],
[1039891953, 1039891931, 1039891917, 1039891902],
[34942661139, 1039891931, 1039891917, 1039891902],
)

def testGetCheckRunsForRefFilterByCheckName(self):
Expand All @@ -106,7 +104,7 @@ def testGetCheckRunsForRefFilterByStatus(self):
self.assertEqual(completed_check_runs.totalCount, 4)
self.assertListEqual(
[check_run.id for check_run in completed_check_runs],
[1039891953, 1039891931, 1039891917, 1039891902],
[34942661139, 1039891931, 1039891917, 1039891902],
)
queued_check_runs = self.commit.get_check_runs(status="queued")
self.assertEqual(queued_check_runs.totalCount, 0)
Expand All @@ -119,12 +117,12 @@ def testGetCheckRunsForRefFilterByFilter(self):
self.assertEqual(latest_check_runs.totalCount, 4)
self.assertListEqual(
[check_run.id for check_run in latest_check_runs],
[1039891953, 1039891931, 1039891917, 1039891902],
[34942661139, 1039891931, 1039891917, 1039891902],
)
self.assertEqual(all_check_runs.totalCount, 4)
self.assertListEqual(
[check_run.id for check_run in all_check_runs],
[1039891953, 1039891931, 1039891917, 1039891902],
[34942661139, 1039891931, 1039891917, 1039891902],
)

def testCreateCheckRunInProgress(self):
Expand Down
20 changes: 10 additions & 10 deletions tests/ReplayData/CheckRun.setUp.txt

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions tests/ReplayData/CheckRun.testAttributes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
https
GET
api.github.com
None
/repos/PyGithub/PyGithub/check-suites/32504127411
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
None
200
[('Date', 'Tue, 07 Jan 2025 18:39:51 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP,Accept-Encoding, Accept, X-Requested-With'), ('ETag', 'W/"cf37edb770e117d44287f2b73ea121cea53b58824434ae25c42768094feb7718"'), ('X-OAuth-Scopes', 'read:discussion, repo'), ('X-Accepted-OAuth-Scopes', ''), ('github-authentication-token-expiration', '2025-02-04 16:42:10 UTC'), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('x-github-api-version-selected', '2022-11-28'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4994'), ('X-RateLimit-Reset', '1736275846'), ('X-RateLimit-Used', '6'), ('X-RateLimit-Resource', 'core'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '0'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Content-Encoding', 'gzip'), ('Transfer-Encoding', 'chunked'), ('Server', 'github.com'), ('X-GitHub-Request-Id', 'E55A:3F163C:341D0EB:354A600:677D74F7')]
{"id":32504127411,"node_id":"CS_kwDOADYVqs8AAAAHkWWfsw","head_branch":"httpretty-urllib3-fix","head_sha":"10a7135a04f71e6101f8b013aded8a662d08fd1f","status":"completed","conclusion":"success","url":"https://api.github.com/repos/PyGithub/PyGithub/check-suites/32504127411","before":null,"after":null,"pull_requests":[],"app":{"id":15368,"client_id":"Iv1.05c79e9ad1f6bdfa","slug":"github-actions","node_id":"MDM6QXBwMTUzNjg=","owner":{"login":"github","id":9919,"node_id":"MDEyOk9yZ2FuaXphdGlvbjk5MTk=","avatar_url":"https://avatars.githubusercontent.com/u/9919?v=4","gravatar_id":"","url":"https://api.github.com/users/github","html_url":"https://github.com/github","followers_url":"https://api.github.com/users/github/followers","following_url":"https://api.github.com/users/github/following{/other_user}","gists_url":"https://api.github.com/users/github/gists{/gist_id}","starred_url":"https://api.github.com/users/github/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/github/subscriptions","organizations_url":"https://api.github.com/users/github/orgs","repos_url":"https://api.github.com/users/github/repos","events_url":"https://api.github.com/users/github/events{/privacy}","received_events_url":"https://api.github.com/users/github/received_events","type":"Organization","user_view_type":"public","site_admin":false},"name":"GitHub Actions","description":"Automate your workflow from idea to production","external_url":"https://help.github.com/en/actions","html_url":"https://github.com/apps/github-actions","created_at":"2018-07-30T09:30:17Z","updated_at":"2024-04-10T20:33:16Z","permissions":{"actions":"write","administration":"read","attestations":"write","checks":"write","contents":"write","deployments":"write","discussions":"write","issues":"write","merge_queues":"write","metadata":"read","packages":"write","pages":"write","pull_requests":"write","repository_hooks":"write","repository_projects":"write","security_events":"write","statuses":"write","vulnerability_alerts":"read"},"events":["branch_protection_rule","check_run","check_suite","create","delete","deployment","deployment_status","discussion","discussion_comment","fork","gollum","issues","issue_comment","label","merge_group","milestone","page_build","project","project_card","project_column","public","pull_request","pull_request_review","pull_request_review_comment","push","registry_package","release","repository","repository_dispatch","status","watch","workflow_dispatch","workflow_run"]},"created_at":"2024-12-28T16:51:51Z","updated_at":"2024-12-28T17:13:41Z","rerequestable":true,"runs_rerequestable":false,"latest_check_runs_count":10,"check_runs_url":"https://api.github.com/repos/PyGithub/PyGithub/check-suites/32504127411/check-runs","head_commit":{"id":"10a7135a04f71e6101f8b013aded8a662d08fd1f","tree_id":"deb3f7784c24794fe277714a37d9f874d24543eb","message":"Patch httpretty socket for latest urllib3 release","timestamp":"2024-12-28T16:51:40Z","author":{"name":"Enrico Minack","email":"[email protected]"},"committer":{"name":"Enrico Minack","email":"[email protected]"}},"repository":{"id":3544490,"node_id":"MDEwOlJlcG9zaXRvcnkzNTQ0NDkw","name":"PyGithub","full_name":"PyGithub/PyGithub","private":false,"owner":{"login":"PyGithub","id":11288996,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExMjg4OTk2","avatar_url":"https://avatars.githubusercontent.com/u/11288996?v=4","gravatar_id":"","url":"https://api.github.com/users/PyGithub","html_url":"https://github.com/PyGithub","followers_url":"https://api.github.com/users/PyGithub/followers","following_url":"https://api.github.com/users/PyGithub/following{/other_user}","gists_url":"https://api.github.com/users/PyGithub/gists{/gist_id}","starred_url":"https://api.github.com/users/PyGithub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PyGithub/subscriptions","organizations_url":"https://api.github.com/users/PyGithub/orgs","repos_url":"https://api.github.com/users/PyGithub/repos","events_url":"https://api.github.com/users/PyGithub/events{/privacy}","received_events_url":"https://api.github.com/users/PyGithub/received_events","type":"Organization","user_view_type":"public","site_admin":false},"html_url":"https://github.com/PyGithub/PyGithub","description":"Typed interactions with the GitHub API v3","fork":false,"url":"https://api.github.com/repos/PyGithub/PyGithub","forks_url":"https://api.github.com/repos/PyGithub/PyGithub/forks","keys_url":"https://api.github.com/repos/PyGithub/PyGithub/keys{/key_id}","collaborators_url":"https://api.github.com/repos/PyGithub/PyGithub/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/PyGithub/PyGithub/teams","hooks_url":"https://api.github.com/repos/PyGithub/PyGithub/hooks","issue_events_url":"https://api.github.com/repos/PyGithub/PyGithub/issues/events{/number}","events_url":"https://api.github.com/repos/PyGithub/PyGithub/events","assignees_url":"https://api.github.com/repos/PyGithub/PyGithub/assignees{/user}","branches_url":"https://api.github.com/repos/PyGithub/PyGithub/branches{/branch}","tags_url":"https://api.github.com/repos/PyGithub/PyGithub/tags","blobs_url":"https://api.github.com/repos/PyGithub/PyGithub/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/PyGithub/PyGithub/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/PyGithub/PyGithub/git/refs{/sha}","trees_url":"https://api.github.com/repos/PyGithub/PyGithub/git/trees{/sha}","statuses_url":"https://api.github.com/repos/PyGithub/PyGithub/statuses/{sha}","languages_url":"https://api.github.com/repos/PyGithub/PyGithub/languages","stargazers_url":"https://api.github.com/repos/PyGithub/PyGithub/stargazers","contributors_url":"https://api.github.com/repos/PyGithub/PyGithub/contributors","subscribers_url":"https://api.github.com/repos/PyGithub/PyGithub/subscribers","subscription_url":"https://api.github.com/repos/PyGithub/PyGithub/subscription","commits_url":"https://api.github.com/repos/PyGithub/PyGithub/commits{/sha}","git_commits_url":"https://api.github.com/repos/PyGithub/PyGithub/git/commits{/sha}","comments_url":"https://api.github.com/repos/PyGithub/PyGithub/comments{/number}","issue_comment_url":"https://api.github.com/repos/PyGithub/PyGithub/issues/comments{/number}","contents_url":"https://api.github.com/repos/PyGithub/PyGithub/contents/{+path}","compare_url":"https://api.github.com/repos/PyGithub/PyGithub/compare/{base}...{head}","merges_url":"https://api.github.com/repos/PyGithub/PyGithub/merges","archive_url":"https://api.github.com/repos/PyGithub/PyGithub/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/PyGithub/PyGithub/downloads","issues_url":"https://api.github.com/repos/PyGithub/PyGithub/issues{/number}","pulls_url":"https://api.github.com/repos/PyGithub/PyGithub/pulls{/number}","milestones_url":"https://api.github.com/repos/PyGithub/PyGithub/milestones{/number}","notifications_url":"https://api.github.com/repos/PyGithub/PyGithub/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/PyGithub/PyGithub/labels{/name}","releases_url":"https://api.github.com/repos/PyGithub/PyGithub/releases{/id}","deployments_url":"https://api.github.com/repos/PyGithub/PyGithub/deployments"}}
Loading

0 comments on commit 3837c7d

Please sign in to comment.