Skip to content

Commit 5327617

Browse files
authored
Sync GithubApp class with API spec (#3127)
Adds the following attributes: - client_id - client_secret - installations_count - node_id - pem - webhook_secret
1 parent 6276e20 commit 5327617

File tree

4 files changed

+80
-13
lines changed

4 files changed

+80
-13
lines changed

github/GithubApp.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,38 @@ class GithubApp(CompletableGithubObject):
6565
"""
6666

6767
def _initAttributes(self) -> None:
68+
self._client_id: Attribute[str] = NotSet
69+
self._client_secret: Attribute[str] = NotSet
6870
self._created_at: Attribute[datetime] = NotSet
6971
self._description: Attribute[str] = NotSet
7072
self._events: Attribute[list[str]] = NotSet
7173
self._external_url: Attribute[str] = NotSet
7274
self._html_url: Attribute[str] = NotSet
7375
self._id: Attribute[int] = NotSet
76+
self._installations_count: Attribute[int] = NotSet
7477
self._name: Attribute[str] = NotSet
78+
self._node_id: Attribute[str] = NotSet
7579
self._owner: Attribute[github.NamedUser.NamedUser] = NotSet
80+
self._pem: Attribute[str] = NotSet
7681
self._permissions: Attribute[dict[str, str]] = NotSet
7782
self._slug: Attribute[str] = NotSet
7883
self._updated_at: Attribute[datetime] = NotSet
7984
self._url: Attribute[str] = NotSet
85+
self._webhook_secret: Attribute[str] = NotSet
8086

8187
def __repr__(self) -> str:
8288
return self.get__repr__({"id": self._id.value, "url": self._url.value})
8389

90+
@property
91+
def client_id(self) -> str:
92+
self._completeIfNotSet(self._client_id)
93+
return self._client_id.value
94+
95+
@property
96+
def client_secret(self) -> str:
97+
self._completeIfNotSet(self._client_secret)
98+
return self._client_secret.value
99+
84100
@property
85101
def created_at(self) -> datetime:
86102
self._completeIfNotSet(self._created_at)
@@ -111,16 +127,31 @@ def id(self) -> int:
111127
self._completeIfNotSet(self._id)
112128
return self._id.value
113129

130+
@property
131+
def installations_count(self) -> int:
132+
self._completeIfNotSet(self._installations_count)
133+
return self._installations_count.value
134+
114135
@property
115136
def name(self) -> str:
116137
self._completeIfNotSet(self._name)
117138
return self._name.value
118139

140+
@property
141+
def node_id(self) -> str:
142+
self._completeIfNotSet(self._node_id)
143+
return self._node_id.value
144+
119145
@property
120146
def owner(self) -> github.NamedUser.NamedUser:
121147
self._completeIfNotSet(self._owner)
122148
return self._owner.value
123149

150+
@property
151+
def pem(self) -> str:
152+
self._completeIfNotSet(self._pem)
153+
return self._pem.value
154+
124155
@property
125156
def permissions(self) -> dict[str, str]:
126157
self._completeIfNotSet(self._permissions)
@@ -140,7 +171,16 @@ def updated_at(self) -> datetime:
140171
def url(self) -> str:
141172
return self._url.value
142173

174+
@property
175+
def webhook_secret(self) -> str:
176+
self._completeIfNotSet(self._webhook_secret)
177+
return self._webhook_secret.value
178+
143179
def _useAttributes(self, attributes: dict[str, Any]) -> None:
180+
if "client_id" in attributes: # pragma no branch
181+
self._client_id = self._makeStringAttribute(attributes["client_id"])
182+
if "client_secret" in attributes: # pragma no branch
183+
self._client_secret = self._makeStringAttribute(attributes["client_secret"])
144184
if "created_at" in attributes: # pragma no branch
145185
self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
146186
if "description" in attributes: # pragma no branch
@@ -153,10 +193,16 @@ def _useAttributes(self, attributes: dict[str, Any]) -> None:
153193
self._html_url = self._makeStringAttribute(attributes["html_url"])
154194
if "id" in attributes: # pragma no branch
155195
self._id = self._makeIntAttribute(attributes["id"])
196+
if "installations_count" in attributes: # pragma no branch
197+
self._installations_count = self._makeIntAttribute(attributes["installations_count"])
156198
if "name" in attributes: # pragma no branch
157199
self._name = self._makeStringAttribute(attributes["name"])
200+
if "node_id" in attributes: # pragma no branch
201+
self._node_id = self._makeStringAttribute(attributes["node_id"])
158202
if "owner" in attributes: # pragma no branch
159203
self._owner = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["owner"])
204+
if "pem" in attributes: # pragma no branch
205+
self._pem = self._makeStringAttribute(attributes["pem"])
160206
if "permissions" in attributes: # pragma no branch
161207
self._permissions = self._makeDictAttribute(attributes["permissions"])
162208
if "slug" in attributes: # pragma no branch
@@ -166,3 +212,5 @@ def _useAttributes(self, attributes: dict[str, Any]) -> None:
166212
self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"])
167213
if "url" in attributes:
168214
self._url = self._makeStringAttribute(attributes["url"])
215+
if "webhook_secret" in attributes: # pragma no branch
216+
self._webhook_secret = self._makeStringAttribute(attributes["webhook_secret"])

tests/GithubApp.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
# #
2525
################################################################################
2626

27+
from __future__ import annotations
28+
2729
from datetime import datetime, timezone
2830

2931
import github
@@ -36,25 +38,34 @@ class GithubApp(Framework.TestCase):
3638
def setUp(self):
3739
super().setUp()
3840
self.app_slug = "github-actions"
41+
self.app = self.g.get_app(slug=self.app_slug)
42+
# fetch lazy object
43+
self.app.id
3944

40-
def testGetPublicApp(self):
41-
app = self.g.get_app(slug=self.app_slug)
45+
def testAttributes(self):
46+
app = self.app
47+
self.assertEqual(app.client_id, "Iv1.05c79e9ad1f6bdfa")
48+
self.assertIsNone(app.client_secret)
4249
self.assertEqual(app.created_at, datetime(2018, 7, 30, 9, 30, 17, tzinfo=timezone.utc))
4350
self.assertEqual(app.description, "Automate your workflow from idea to production")
4451
self.assertListEqual(
4552
app.events,
4653
[
54+
"branch_protection_rule",
4755
"check_run",
4856
"check_suite",
4957
"create",
5058
"delete",
5159
"deployment",
5260
"deployment_status",
61+
"discussion",
62+
"discussion_comment",
5363
"fork",
5464
"gollum",
5565
"issues",
5666
"issue_comment",
5767
"label",
68+
"merge_group",
5869
"milestone",
5970
"page_build",
6071
"project",
@@ -78,16 +89,23 @@ def testGetPublicApp(self):
7889
self.assertEqual(app.external_url, "https://help.github.com/en/actions")
7990
self.assertEqual(app.html_url, "https://github.com/apps/github-actions")
8091
self.assertEqual(app.id, 15368)
92+
self.assertIsNone(app.installations_count)
8193
self.assertEqual(app.name, "GitHub Actions")
94+
self.assertEqual(app.node_id, "MDM6QXBwMTUzNjg=")
8295
self.assertEqual(app.owner.login, "github")
96+
self.assertIsNone(app.pem)
8397
self.assertDictEqual(
8498
app.permissions,
8599
{
86100
"actions": "write",
101+
"administration": "read",
102+
"attestations": "write",
87103
"checks": "write",
88104
"contents": "write",
89105
"deployments": "write",
106+
"discussions": "write",
90107
"issues": "write",
108+
"merge_queues": "write",
91109
"metadata": "read",
92110
"packages": "write",
93111
"pages": "write",
@@ -100,8 +118,9 @@ def testGetPublicApp(self):
100118
},
101119
)
102120
self.assertEqual(app.slug, "github-actions")
103-
self.assertEqual(app.updated_at, datetime(2019, 12, 10, 19, 4, 12, tzinfo=timezone.utc))
121+
self.assertEqual(app.updated_at, datetime(2024, 4, 10, 20, 33, 16, tzinfo=timezone.utc))
104122
self.assertEqual(app.url, "/apps/github-actions")
123+
self.assertIsNone(app.webhook_secret)
105124

106125
def testGetAuthenticatedApp(self):
107126
auth = github.Auth.AppAuth(APP_ID, PRIVATE_KEY)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
https
2+
GET
3+
api.github.com
4+
None
5+
/apps/github-actions
6+
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
7+
None
8+
200
9+
[('Date', 'Fri, 03 Jan 2025 17:55:22 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/"52ae4146434244818fdf617cccfb66ce69c39baedeaf470ea3b79d55e0ac2102"'), ('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', '4992'), ('X-RateLimit-Reset', '1735927338'), ('X-RateLimit-Used', '8'), ('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', 'DB02:654DF:22F89888:23DA71AC:6778248A')]
10+
{"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"]}

tests/ReplayData/GithubApp.testGetPublicApp.txt

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)