Skip to content

Commit c2d3b5e

Browse files
authored
Sync Deployment class with API spec (#3121)
Adds the following attributes: - message - node_id - performed_via_github_app
1 parent 79b4fc7 commit c2d3b5e

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

github/Deployment.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,19 @@
4545
from __future__ import annotations
4646

4747
from datetime import datetime
48-
from typing import Any
48+
from typing import TYPE_CHECKING, Any
4949

5050
import github.Consts
5151
import github.DeploymentStatus
52+
import github.GithubApp
5253
import github.NamedUser
5354
from github.GithubObject import Attribute, CompletableGithubObject, NotSet, Opt
5455
from github.PaginatedList import PaginatedList
5556

57+
if TYPE_CHECKING:
58+
from github.GithubApp import GithubApp
59+
from github.NamedUser import NamedUser
60+
5661

5762
class Deployment(CompletableGithubObject):
5863
"""
@@ -70,12 +75,15 @@ class Deployment(CompletableGithubObject):
7075

7176
def _initAttributes(self) -> None:
7277
self._created_at: Attribute[datetime] = NotSet
73-
self._creator: Attribute[github.NamedUser.NamedUser] = NotSet
78+
self._creator: Attribute[NamedUser] = NotSet
7479
self._description: Attribute[str] = NotSet
7580
self._environment: Attribute[str] = NotSet
7681
self._id: Attribute[int] = NotSet
82+
self._message: Attribute[str] = NotSet
83+
self._node_id: Attribute[str] = NotSet
7784
self._original_environment: Attribute[str] = NotSet
7885
self._payload: Attribute[dict[str, Any]] = NotSet
86+
self._performed_via_github_app: Attribute[GithubApp] = NotSet
7987
self._production_environment: Attribute[bool] = NotSet
8088
self._ref: Attribute[str] = NotSet
8189
self._repository_url: Attribute[str] = NotSet
@@ -95,7 +103,7 @@ def created_at(self) -> datetime:
95103
return self._created_at.value
96104

97105
@property
98-
def creator(self) -> github.NamedUser.NamedUser:
106+
def creator(self) -> NamedUser:
99107
self._completeIfNotSet(self._creator)
100108
return self._creator.value
101109

@@ -114,6 +122,16 @@ def id(self) -> int:
114122
self._completeIfNotSet(self._id)
115123
return self._id.value
116124

125+
@property
126+
def message(self) -> str:
127+
self._completeIfNotSet(self._message)
128+
return self._message.value
129+
130+
@property
131+
def node_id(self) -> str:
132+
self._completeIfNotSet(self._node_id)
133+
return self._node_id.value
134+
117135
@property
118136
def original_environment(self) -> str:
119137
self._completeIfNotSet(self._original_environment)
@@ -124,6 +142,11 @@ def payload(self) -> dict[str, Any]:
124142
self._completeIfNotSet(self._payload)
125143
return self._payload.value
126144

145+
@property
146+
def performed_via_github_app(self) -> GithubApp:
147+
self._completeIfNotSet(self._performed_via_github_app)
148+
return self._performed_via_github_app.value
149+
127150
@property
128151
def production_environment(self) -> bool:
129152
self._completeIfNotSet(self._production_environment)
@@ -251,10 +274,18 @@ def _useAttributes(self, attributes: dict[str, Any]) -> None:
251274
self._environment = self._makeStringAttribute(attributes["environment"])
252275
if "id" in attributes: # pragma no branch
253276
self._id = self._makeIntAttribute(attributes["id"])
277+
if "message" in attributes: # pragma no branch
278+
self._message = self._makeStringAttribute(attributes["message"])
279+
if "node_id" in attributes: # pragma no branch
280+
self._node_id = self._makeStringAttribute(attributes["node_id"])
254281
if "original_environment" in attributes: # pragma no branch
255282
self._original_environment = self._makeStringAttribute(attributes["original_environment"])
256283
if "payload" in attributes: # pragma no branch
257284
self._payload = self._makeDictAttribute(attributes["payload"])
285+
if "performed_via_github_app" in attributes: # pragma no branch
286+
self._performed_via_github_app = self._makeClassAttribute(
287+
github.GithubApp.GithubApp, attributes["performed_via_github_app"]
288+
)
258289
if "production_environment" in attributes: # pragma no branch
259290
self._production_environment = self._makeBoolAttribute(attributes["production_environment"])
260291
if "ref" in attributes: # pragma no branch

tests/Deployment.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
# #
3535
################################################################################
3636

37+
from __future__ import annotations
38+
3739
from datetime import datetime, timezone
3840

3941
from . import Framework
@@ -45,7 +47,27 @@ def setUp(self):
4547
self.deployment = self.g.get_user().get_repo("PyGithub").get_deployment(263877258)
4648

4749
def testAttributes(self):
50+
self.assertEqual(self.deployment.created_at, datetime(2020, 8, 26, 11, 44, 53, tzinfo=timezone.utc))
51+
self.assertEqual(self.deployment.creator.login, "jacquev6")
52+
self.assertEqual(self.deployment.description, "Test deployment")
53+
self.assertEqual(self.deployment.environment, "test")
4854
self.assertEqual(self.deployment.id, 263877258)
55+
self.assertIsNone(self.deployment.message)
56+
self.assertEqual(self.deployment.node_id, "MDEwOkRlcGxveW1lbnQyNjIzNTE3NzY=")
57+
self.assertEqual(self.deployment.original_environment, "test")
58+
self.assertEqual(self.deployment.payload, {"test": True})
59+
self.assertIsNone(self.deployment.performed_via_github_app)
60+
self.assertEqual(self.deployment.production_environment, False)
61+
self.assertEqual(self.deployment.ref, "743f5a58b0bce91c4eab744ff7e39dfca9e6e8a5")
62+
self.assertEqual(self.deployment.repository_url, "https://api.github.com/repos/jacquev6/PyGithub")
63+
self.assertEqual(self.deployment.sha, "743f5a58b0bce91c4eab744ff7e39dfca9e6e8a5")
64+
self.assertEqual(
65+
self.deployment.statuses_url,
66+
"https://api.github.com/repos/jacquev6/PyGithub/deployments/263877258/statuses",
67+
)
68+
self.assertEqual(self.deployment.task, "deploy")
69+
self.assertEqual(self.deployment.transient_environment, True)
70+
self.assertEqual(self.deployment.updated_at, datetime(2020, 8, 26, 11, 44, 53, tzinfo=timezone.utc))
4971
self.assertEqual(
5072
self.deployment.url,
5173
"https://api.github.com/repos/jacquev6/PyGithub/deployments/263877258",

0 commit comments

Comments
 (0)