Skip to content

Commit cc4c526

Browse files
authored
Add support for issue reactions summary (PyGithub#2866)
1 parent 2d284d1 commit cc4c526

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

github/Issue.py

+8
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def _initAttributes(self) -> None:
128128
self._updated_at: Attribute[datetime] = NotSet
129129
self._url: Attribute[str] = NotSet
130130
self._user: Attribute[NamedUser] = NotSet
131+
self._reactions: Attribute[dict] = NotSet
131132

132133
def __repr__(self) -> str:
133134
return self.get__repr__({"number": self._number.value, "title": self._title.value})
@@ -263,6 +264,11 @@ def active_lock_reason(self) -> str | None:
263264
self._completeIfNotSet(self._active_lock_reason)
264265
return self._active_lock_reason.value
265266

267+
@property
268+
def reactions(self) -> dict:
269+
self._completeIfNotSet(self._reactions)
270+
return self._reactions.value
271+
266272
def as_pull_request(self) -> PullRequest:
267273
"""
268274
:calls: `GET /repos/{owner}/{repo}/pulls/{number} <https://docs.github.com/en/rest/reference/pulls>`_
@@ -566,3 +572,5 @@ def _useAttributes(self, attributes: dict[str, Any]) -> None:
566572
self._url = self._makeStringAttribute(attributes["url"])
567573
if "user" in attributes: # pragma no branch
568574
self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"])
575+
if "reactions" in attributes:
576+
self._reactions = self._makeDictAttribute(attributes["reactions"])

tests/Issue.py

+15
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,21 @@ def testAttributes(self):
102102
self.assertEqual(self.issue.user.login, "jacquev6")
103103
self.assertEqual(self.issue.repository.name, "PyGithub")
104104
self.assertEqual(repr(self.issue), 'Issue(title="Issue created by PyGithub", number=28)')
105+
self.assertEqual(
106+
self.issue.reactions,
107+
{
108+
"+1": 0,
109+
"-1": 0,
110+
"confused": 0,
111+
"eyes": 0,
112+
"heart": 0,
113+
"hooray": 2,
114+
"laugh": 0,
115+
"rocket": 0,
116+
"total_count": 2,
117+
"url": "https://api.github.com/repos/PyGithub/PyGithub/issues/28/reactions",
118+
},
119+
)
105120

106121
def testEditWithoutParameters(self):
107122
self.issue.edit()

tests/ReplayData/Issue.setUp.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ None
2929
None
3030
200
3131
[('status', '200 OK'), ('x-ratelimit-remaining', '4991'), ('content-length', '2258'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"071cb2b8bfef81f56b94d7d9397e6aa4"'), ('date', 'Sat, 26 May 2012 14:59:40 GMT'), ('content-type', 'application/json; charset=utf-8')]
32-
{"updated_at":"2012-05-26T14:59:33Z","body":"Body edited by PyGithub","url":"https://api.github.com/repos/jacquev6/PyGithub/issues/28","comments":0,"milestone":{"creator":{"url":"https://api.github.com/users/jacquev6","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"url":"https://api.github.com/repos/jacquev6/PyGithub/milestones/1","number":1,"title":"Version 0.4","due_on":"2012-03-13T07:00:00Z","open_issues":0,"created_at":"2012-03-08T12:22:10Z","state":"closed","description":"","id":93546,"closed_issues":3},"number":28,"closed_by":{"url":"https://api.github.com/users/jacquev6","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"assignee":{"url":"https://api.github.com/users/jacquev6","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"assignees":[{"url":"https://api.github.com/users/jacquev6","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":327146},{"url":"https://api.github.com/users/stuglaser","gravatar_id":"","login":"stuglaser","avatar_url":"https://avatars.githubusercontent.com/u/1527117?v=3","id":1527117}],"closed_at":"2012-05-26T14:59:33Z","title":"Issue created by PyGithub","labels":[{"url":"https://api.github.com/repos/jacquev6/PyGithub/labels/Bug","name":"Bug","color":"e10c02"},{"url":"https://api.github.com/repos/jacquev6/PyGithub/labels/Project+management","name":"Project management","color":"444444"},{"url":"https://api.github.com/repos/jacquev6/PyGithub/labels/Question","name":"Question","color":"02e10c"}],"created_at":"2012-05-19T10:38:23Z","state":"closed","user":{"url":"https://api.github.com/users/jacquev6","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"id":4653757,"pull_request":{"patch_url":null,"diff_url":null,"html_url":null},"html_url":"https://github.com/jacquev6/PyGithub/issues/28","state_reason":"completed","comments_url":"https://github.com/jacquev6/PyGithub/issues/28/comments","events_url":"https://github.com/jacquev6/PyGithub/issues/28/events","labels_url":"https://github.com/jacquev6/PyGithub/issues/28/labels{/name}"}
32+
{"updated_at":"2012-05-26T14:59:33Z","body":"Body edited by PyGithub","url":"https://api.github.com/repos/jacquev6/PyGithub/issues/28","comments":0,"milestone":{"creator":{"url":"https://api.github.com/users/jacquev6","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"url":"https://api.github.com/repos/jacquev6/PyGithub/milestones/1","number":1,"title":"Version 0.4","due_on":"2012-03-13T07:00:00Z","open_issues":0,"created_at":"2012-03-08T12:22:10Z","state":"closed","description":"","id":93546,"closed_issues":3},"number":28,"closed_by":{"url":"https://api.github.com/users/jacquev6","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"assignee":{"url":"https://api.github.com/users/jacquev6","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"assignees":[{"url":"https://api.github.com/users/jacquev6","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","id":327146},{"url":"https://api.github.com/users/stuglaser","gravatar_id":"","login":"stuglaser","avatar_url":"https://avatars.githubusercontent.com/u/1527117?v=3","id":1527117}],"closed_at":"2012-05-26T14:59:33Z","title":"Issue created by PyGithub","labels":[{"url":"https://api.github.com/repos/jacquev6/PyGithub/labels/Bug","name":"Bug","color":"e10c02"},{"url":"https://api.github.com/repos/jacquev6/PyGithub/labels/Project+management","name":"Project management","color":"444444"},{"url":"https://api.github.com/repos/jacquev6/PyGithub/labels/Question","name":"Question","color":"02e10c"}],"created_at":"2012-05-19T10:38:23Z","state":"closed","user":{"url":"https://api.github.com/users/jacquev6","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"id":4653757,"pull_request":{"patch_url":null,"diff_url":null,"html_url":null},"html_url":"https://github.com/jacquev6/PyGithub/issues/28","state_reason":"completed","comments_url":"https://github.com/jacquev6/PyGithub/issues/28/comments","events_url":"https://github.com/jacquev6/PyGithub/issues/28/events","labels_url":"https://github.com/jacquev6/PyGithub/issues/28/labels{/name}","reactions":{"url":"https://api.github.com/repos/PyGithub/PyGithub/issues/28/reactions","total_count":2,"+1":0,"-1":0,"laugh":0,"hooray":2,"confused":0,"heart":0,"rocket":0,"eyes":0}}

0 commit comments

Comments
 (0)