Skip to content

Commit

Permalink
Sync GistComment class with API spec (#3124)
Browse files Browse the repository at this point in the history
Adds the following attributes:
- author_association
- node_id
  • Loading branch information
EnricoMi authored Jan 8, 2025
1 parent 876ff10 commit eb6019a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions github/GistComment.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,23 @@ class GistComment(CompletableGithubObject):
"""

def _initAttributes(self) -> None:
self._author_association: Attribute[str] = NotSet
self._body: Attribute[str] = NotSet
self._created_at: Attribute[datetime] = NotSet
self._id: Attribute[int] = NotSet
self._node_id: Attribute[str] = NotSet
self._updated_at: Attribute[datetime] = NotSet
self._url: Attribute[str] = NotSet
self._user: Attribute[github.NamedUser.NamedUser] = NotSet

def __repr__(self) -> str:
return self.get__repr__({"id": self._id.value, "user": self._user.value})

@property
def author_association(self) -> str:
self._completeIfNotSet(self._author_association)
return self._author_association.value

@property
def body(self) -> str:
self._completeIfNotSet(self._body)
Expand All @@ -86,6 +93,11 @@ def id(self) -> int:
self._completeIfNotSet(self._id)
return self._id.value

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

@property
def updated_at(self) -> datetime:
self._completeIfNotSet(self._updated_at)
Expand Down Expand Up @@ -119,12 +131,16 @@ def edit(self, body: str) -> None:
self._useAttributes(data)

def _useAttributes(self, attributes: dict[str, Any]) -> None:
if "author_association" in attributes: # pragma no branch
self._author_association = self._makeStringAttribute(attributes["author_association"])
if "body" in attributes: # pragma no branch
self._body = self._makeStringAttribute(attributes["body"])
if "created_at" in attributes: # pragma no branch
self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
if "id" in attributes: # pragma no branch
self._id = self._makeIntAttribute(attributes["id"])
if "node_id" in attributes: # pragma no branch
self._node_id = self._makeStringAttribute(attributes["node_id"])
if "updated_at" in attributes: # pragma no branch
self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"])
if "url" in attributes: # pragma no branch
Expand Down
4 changes: 4 additions & 0 deletions tests/GistComment.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
# #
################################################################################

from __future__ import annotations

from datetime import datetime, timezone

from . import Framework
Expand All @@ -43,12 +45,14 @@ def setUp(self):
self.comment = self.g.get_gist("2729810").get_comment(323629)

def testAttributes(self):
self.assertIsNone(self.comment.author_association)
self.assertEqual(self.comment.body, "Comment created by PyGithub")
self.assertEqual(
self.comment.created_at,
datetime(2012, 5, 19, 7, 7, 57, tzinfo=timezone.utc),
)
self.assertEqual(self.comment.id, 323629)
self.assertIsNone(self.comment.node_id)
self.assertEqual(
self.comment.updated_at,
datetime(2012, 5, 19, 7, 7, 57, tzinfo=timezone.utc),
Expand Down

0 comments on commit eb6019a

Please sign in to comment.