Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for issue reactions summary #2866

Merged
merged 2 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions github/Issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def _initAttributes(self) -> None:
self._updated_at: Attribute[datetime] = NotSet
self._url: Attribute[str] = NotSet
self._user: Attribute[NamedUser] = NotSet
self._reactions: Attribute[dict] = NotSet

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

@property
def reactions(self) -> dict:
self._completeIfNotSet(self._reactions)
return self._reactions.value

def as_pull_request(self) -> PullRequest:
"""
:calls: `GET /repos/{owner}/{repo}/pulls/{number} <https://docs.github.com/en/rest/reference/pulls>`_
Expand Down Expand Up @@ -566,3 +572,5 @@ def _useAttributes(self, attributes: dict[str, Any]) -> None:
self._url = self._makeStringAttribute(attributes["url"])
if "user" in attributes: # pragma no branch
self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["user"])
if "reactions" in attributes:
self._reactions = self._makeDictAttribute(attributes["reactions"])
15 changes: 15 additions & 0 deletions tests/Issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,21 @@ def testAttributes(self):
self.assertEqual(self.issue.user.login, "jacquev6")
self.assertEqual(self.issue.repository.name, "PyGithub")
self.assertEqual(repr(self.issue), 'Issue(title="Issue created by PyGithub", number=28)')
self.assertEqual(
self.issue.reactions,
{
"+1": 0,
"-1": 0,
"confused": 0,
"eyes": 0,
"heart": 0,
"hooray": 2,
"laugh": 0,
"rocket": 0,
"total_count": 2,
"url": "https://api.github.com/repos/PyGithub/PyGithub/issues/28/reactions",
},
)

def testEditWithoutParameters(self):
self.issue.edit()
Expand Down
2 changes: 1 addition & 1 deletion tests/ReplayData/Issue.setUp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ None
None
200
[('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')]
{"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}"}
{"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}}