Skip to content

Commit

Permalink
Sync Deployment class with API spec (#3121)
Browse files Browse the repository at this point in the history
Adds the following attributes:
- message
- node_id
- performed_via_github_app
  • Loading branch information
EnricoMi authored Jan 8, 2025
1 parent 79b4fc7 commit c2d3b5e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
37 changes: 34 additions & 3 deletions github/Deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,19 @@
from __future__ import annotations

from datetime import datetime
from typing import Any
from typing import TYPE_CHECKING, Any

import github.Consts
import github.DeploymentStatus
import github.GithubApp
import github.NamedUser
from github.GithubObject import Attribute, CompletableGithubObject, NotSet, Opt
from github.PaginatedList import PaginatedList

if TYPE_CHECKING:
from github.GithubApp import GithubApp
from github.NamedUser import NamedUser


class Deployment(CompletableGithubObject):
"""
Expand All @@ -70,12 +75,15 @@ class Deployment(CompletableGithubObject):

def _initAttributes(self) -> None:
self._created_at: Attribute[datetime] = NotSet
self._creator: Attribute[github.NamedUser.NamedUser] = NotSet
self._creator: Attribute[NamedUser] = NotSet
self._description: Attribute[str] = NotSet
self._environment: Attribute[str] = NotSet
self._id: Attribute[int] = NotSet
self._message: Attribute[str] = NotSet
self._node_id: Attribute[str] = NotSet
self._original_environment: Attribute[str] = NotSet
self._payload: Attribute[dict[str, Any]] = NotSet
self._performed_via_github_app: Attribute[GithubApp] = NotSet
self._production_environment: Attribute[bool] = NotSet
self._ref: Attribute[str] = NotSet
self._repository_url: Attribute[str] = NotSet
Expand All @@ -95,7 +103,7 @@ def created_at(self) -> datetime:
return self._created_at.value

@property
def creator(self) -> github.NamedUser.NamedUser:
def creator(self) -> NamedUser:
self._completeIfNotSet(self._creator)
return self._creator.value

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

@property
def message(self) -> str:
self._completeIfNotSet(self._message)
return self._message.value

@property
def node_id(self) -> str:
self._completeIfNotSet(self._node_id)
return self._node_id.value

@property
def original_environment(self) -> str:
self._completeIfNotSet(self._original_environment)
Expand All @@ -124,6 +142,11 @@ def payload(self) -> dict[str, Any]:
self._completeIfNotSet(self._payload)
return self._payload.value

@property
def performed_via_github_app(self) -> GithubApp:
self._completeIfNotSet(self._performed_via_github_app)
return self._performed_via_github_app.value

@property
def production_environment(self) -> bool:
self._completeIfNotSet(self._production_environment)
Expand Down Expand Up @@ -251,10 +274,18 @@ def _useAttributes(self, attributes: dict[str, Any]) -> None:
self._environment = self._makeStringAttribute(attributes["environment"])
if "id" in attributes: # pragma no branch
self._id = self._makeIntAttribute(attributes["id"])
if "message" in attributes: # pragma no branch
self._message = self._makeStringAttribute(attributes["message"])
if "node_id" in attributes: # pragma no branch
self._node_id = self._makeStringAttribute(attributes["node_id"])
if "original_environment" in attributes: # pragma no branch
self._original_environment = self._makeStringAttribute(attributes["original_environment"])
if "payload" in attributes: # pragma no branch
self._payload = self._makeDictAttribute(attributes["payload"])
if "performed_via_github_app" in attributes: # pragma no branch
self._performed_via_github_app = self._makeClassAttribute(
github.GithubApp.GithubApp, attributes["performed_via_github_app"]
)
if "production_environment" in attributes: # pragma no branch
self._production_environment = self._makeBoolAttribute(attributes["production_environment"])
if "ref" in attributes: # pragma no branch
Expand Down
22 changes: 22 additions & 0 deletions tests/Deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
# #
################################################################################

from __future__ import annotations

from datetime import datetime, timezone

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

def testAttributes(self):
self.assertEqual(self.deployment.created_at, datetime(2020, 8, 26, 11, 44, 53, tzinfo=timezone.utc))
self.assertEqual(self.deployment.creator.login, "jacquev6")
self.assertEqual(self.deployment.description, "Test deployment")
self.assertEqual(self.deployment.environment, "test")
self.assertEqual(self.deployment.id, 263877258)
self.assertIsNone(self.deployment.message)
self.assertEqual(self.deployment.node_id, "MDEwOkRlcGxveW1lbnQyNjIzNTE3NzY=")
self.assertEqual(self.deployment.original_environment, "test")
self.assertEqual(self.deployment.payload, {"test": True})
self.assertIsNone(self.deployment.performed_via_github_app)
self.assertEqual(self.deployment.production_environment, False)
self.assertEqual(self.deployment.ref, "743f5a58b0bce91c4eab744ff7e39dfca9e6e8a5")
self.assertEqual(self.deployment.repository_url, "https://api.github.com/repos/jacquev6/PyGithub")
self.assertEqual(self.deployment.sha, "743f5a58b0bce91c4eab744ff7e39dfca9e6e8a5")
self.assertEqual(
self.deployment.statuses_url,
"https://api.github.com/repos/jacquev6/PyGithub/deployments/263877258/statuses",
)
self.assertEqual(self.deployment.task, "deploy")
self.assertEqual(self.deployment.transient_environment, True)
self.assertEqual(self.deployment.updated_at, datetime(2020, 8, 26, 11, 44, 53, tzinfo=timezone.utc))
self.assertEqual(
self.deployment.url,
"https://api.github.com/repos/jacquev6/PyGithub/deployments/263877258",
Expand Down

0 comments on commit c2d3b5e

Please sign in to comment.