From f7d203c083358dcf0689bc63fccc55c02ad46c6e Mon Sep 17 00:00:00 2001 From: Huan-Cheng Chang Date: Mon, 26 Oct 2020 06:40:46 +0100 Subject: [PATCH] Add support for deleting reactions (#1708) * Delete comment reactions * Add test case * update ignore-word-list * Delete issue reactions * Delete issue comment reactions * Delete pull request comment reactions * check status --- .pre-commit-config.yaml | 2 +- github/CommitComment.py | 18 +++++++++++++++++- github/CommitComment.pyi | 1 + github/Issue.py | 15 +++++++++++++++ github/Issue.pyi | 1 + github/IssueComment.py | 18 +++++++++++++++++- github/IssueComment.pyi | 1 + github/PullRequestComment.py | 18 +++++++++++++++++- github/PullRequestComment.pyi | 1 + tests/CommitComment.py | 6 +++++- tests/Issue.py | 4 ++++ tests/IssueComment.py | 6 +++++- tests/PullRequestComment.py | 6 +++++- .../CommitComment.testDeleteReaction.txt | 11 +++++++++++ tests/ReplayData/Issue.testDeleteReaction.txt | 11 +++++++++++ .../IssueComment.testDeleteReaction.txt | 11 +++++++++++ .../PullRequestComment.testDeleteReaction.txt | 11 +++++++++++ 17 files changed, 134 insertions(+), 7 deletions(-) create mode 100644 tests/ReplayData/CommitComment.testDeleteReaction.txt create mode 100644 tests/ReplayData/Issue.testDeleteReaction.txt create mode 100644 tests/ReplayData/IssueComment.testDeleteReaction.txt create mode 100644 tests/ReplayData/PullRequestComment.testDeleteReaction.txt diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8f51c619..c1b18c58 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,5 +22,5 @@ repos: - id: codespell exclude: tests/ args: - - --ignore-words-list="bloaded,nto,pullrequest,pullrequests,thi,tim,wan,Wan" + - --ignore-words-list="bloaded,nto,pullrequest,pullrequests,thi,tim,wan,Wan,chang,Chang" - --quiet-level=2 diff --git a/github/CommitComment.py b/github/CommitComment.py index 9f8422fb..c2d1fba7 100644 --- a/github/CommitComment.py +++ b/github/CommitComment.py @@ -9,10 +9,11 @@ # Copyright 2014 Vincent Jacques # # Copyright 2016 Jannis Gebauer # # Copyright 2016 Peter Buckley # -# Copyright 2017 Nicolas Agustín Torres # +# Copyright 2017 Nicolas Agustín Torres # # Copyright 2018 Wan Liuyang # # Copyright 2018 per1234 # # Copyright 2018 sfdye # +# Copyright 2020 Huan-Cheng Chang # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # @@ -189,6 +190,21 @@ class CommitComment(github.GithubObject.CompletableGithubObject): ) return github.Reaction.Reaction(self._requester, headers, data, completed=True) + def delete_reaction(self, reaction_id): + """ + :calls: `DELETE /repos/:owner/:repo/comments/:comment_id/reactions/:reaction_id + `_ + :param reaction_id: integer + :rtype: bool + """ + assert isinstance(reaction_id, int), reaction_id + status, _, _ = self._requester.requestJson( + "DELETE", + self.url + "/reactions/" + str(reaction_id), + headers={"Accept": Consts.mediaTypeReactionsPreview}, + ) + return status == 204 + def _initAttributes(self): self._body = github.GithubObject.NotSet self._commit_id = github.GithubObject.NotSet diff --git a/github/CommitComment.pyi b/github/CommitComment.pyi index 4078950a..3aeedcbc 100644 --- a/github/CommitComment.pyi +++ b/github/CommitComment.pyi @@ -18,6 +18,7 @@ class CommitComment(CompletableGithubObject): @property def created_at(self) -> datetime: ... def delete(self) -> None: ... + def delete_reaction(self, reaction_id: int) -> bool: ... def edit(self, body: str) -> None: ... def get_reactions(self) -> PaginatedList[Reaction]: ... @property diff --git a/github/Issue.py b/github/Issue.py index cac67f81..641a3332 100644 --- a/github/Issue.py +++ b/github/Issue.py @@ -24,6 +24,7 @@ # Copyright 2018 per1234 # # Copyright 2018 sfdye # # Copyright 2019 Nick Campbell # +# Copyright 2020 Huan-Cheng Chang # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # @@ -585,6 +586,20 @@ class Issue(github.GithubObject.CompletableGithubObject): ) return github.Reaction.Reaction(self._requester, headers, data, completed=True) + def delete_reaction(self, reaction_id): + """ + :calls: `DELETE /repos/:owner/:repo/issues/:issue_number/reactions/:reaction_id `_ + :param reaction_id: integer + :rtype: bool + """ + assert isinstance(reaction_id, int), reaction_id + status, _, _ = self._requester.requestJson( + "DELETE", + self.url + "/reactions/" + str(reaction_id), + headers={"Accept": Consts.mediaTypeReactionsPreview}, + ) + return status == 204 + def get_timeline(self): """ :calls: `GET /repos/:owner/:repo/issues/:number/timeline `_ diff --git a/github/Issue.pyi b/github/Issue.pyi index b1290df6..64327cef 100644 --- a/github/Issue.pyi +++ b/github/Issue.pyi @@ -45,6 +45,7 @@ class Issue(CompletableGithubObject): @property def created_at(self) -> datetime: ... def delete_labels(self) -> None: ... + def delete_reaction(self, reaction_id: int) -> bool: ... def edit( self, title: Union[str, _NotSetType] = ..., diff --git a/github/IssueComment.py b/github/IssueComment.py index 85ecfe31..093412fb 100644 --- a/github/IssueComment.py +++ b/github/IssueComment.py @@ -10,10 +10,11 @@ # Copyright 2014 Vincent Jacques # # Copyright 2016 Jannis Gebauer # # Copyright 2016 Peter Buckley # -# Copyright 2017 Nicolas Agustín Torres # +# Copyright 2017 Nicolas Agustín Torres # # Copyright 2018 Wan Liuyang # # Copyright 2018 per1234 # # Copyright 2018 sfdye # +# Copyright 2020 Huan-Cheng Chang # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # @@ -166,6 +167,21 @@ class IssueComment(github.GithubObject.CompletableGithubObject): ) return github.Reaction.Reaction(self._requester, headers, data, completed=True) + def delete_reaction(self, reaction_id): + """ + :calls: `DELETE /repos/:owner/:repo/issues/comments/:comment_id/reactions/:reaction_id + `_ + :param reaction_id: integer + :rtype: bool + """ + assert isinstance(reaction_id, int), reaction_id + status, _, _ = self._requester.requestJson( + "DELETE", + self.url + "/reactions/" + str(reaction_id), + headers={"Accept": Consts.mediaTypeReactionsPreview}, + ) + return status == 204 + def _initAttributes(self): self._body = github.GithubObject.NotSet self._created_at = github.GithubObject.NotSet diff --git a/github/IssueComment.pyi b/github/IssueComment.pyi index 96db4ad8..b01dc155 100644 --- a/github/IssueComment.pyi +++ b/github/IssueComment.pyi @@ -16,6 +16,7 @@ class IssueComment(CompletableGithubObject): @property def created_at(self) -> datetime: ... def delete(self) -> None: ... + def delete_reaction(self, reaction_id: int) -> bool: ... def edit(self, body: str) -> None: ... def get_reactions(self) -> PaginatedList[Reaction]: ... @property diff --git a/github/PullRequestComment.py b/github/PullRequestComment.py index 6c40392b..8953c739 100644 --- a/github/PullRequestComment.py +++ b/github/PullRequestComment.py @@ -11,10 +11,11 @@ # Copyright 2014 Vincent Jacques # # Copyright 2016 Jannis Gebauer # # Copyright 2016 Peter Buckley # -# Copyright 2017 Nicolas Agustín Torres # +# Copyright 2017 Nicolas Agustín Torres # # Copyright 2018 Jess Morgan <979404+JessMorgan@users.noreply.github.com> # # Copyright 2018 per1234 # # Copyright 2018 sfdye # +# Copyright 2020 Huan-Cheng Chang # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # @@ -223,6 +224,21 @@ class PullRequestComment(github.GithubObject.CompletableGithubObject): ) return github.Reaction.Reaction(self._requester, headers, data, completed=True) + def delete_reaction(self, reaction_id): + """ + :calls: `DELETE /repos/:owner/:repo/pulls/comments/:comment_id/reactions/:reaction_id + `_ + :param reaction_id: integer + :rtype: bool + """ + assert isinstance(reaction_id, int), reaction_id + status, _, _ = self._requester.requestJson( + "DELETE", + self.url + "/reactions/" + str(reaction_id), + headers={"Accept": Consts.mediaTypeReactionsPreview}, + ) + return status == 204 + def _initAttributes(self): self._body = github.GithubObject.NotSet self._commit_id = github.GithubObject.NotSet diff --git a/github/PullRequestComment.pyi b/github/PullRequestComment.pyi index 8a83710a..4b390df3 100644 --- a/github/PullRequestComment.pyi +++ b/github/PullRequestComment.pyi @@ -18,6 +18,7 @@ class PullRequestComment(CompletableGithubObject): @property def created_at(self) -> datetime: ... def delete(self) -> None: ... + def delete_reaction(self, reaction_id: int) -> bool: ... @property def diff_hunk(self) -> str: ... def edit(self, body: str) -> None: ... diff --git a/tests/CommitComment.py b/tests/CommitComment.py index 29bfcdb8..1e38fe19 100644 --- a/tests/CommitComment.py +++ b/tests/CommitComment.py @@ -8,8 +8,9 @@ # Copyright 2014 Vincent Jacques # # Copyright 2016 Jannis Gebauer # # Copyright 2016 Peter Buckley # -# Copyright 2017 Nicolas Agustín Torres # +# Copyright 2017 Nicolas Agustín Torres # # Copyright 2018 sfdye # +# Copyright 2020 Huan-Cheng Chang # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # @@ -83,3 +84,6 @@ class CommitComment(Framework.TestCase): self.assertEqual(reaction.id, 17283092) self.assertEqual(reaction.content, "hooray") + + def testDeleteReaction(self): + self.assertTrue(self.comment.delete_reaction(85737646)) diff --git a/tests/Issue.py b/tests/Issue.py index c67164be..030b54e6 100644 --- a/tests/Issue.py +++ b/tests/Issue.py @@ -14,6 +14,7 @@ # Copyright 2017 Nicolas Agustín Torres # # Copyright 2018 sfdye # # Copyright 2019 Nick Campbell # +# Copyright 2020 Huan-Cheng Chang # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # @@ -263,6 +264,9 @@ class Issue(Framework.TestCase): self.assertEqual(reaction.id, 16917472) self.assertEqual(reaction.content, "hooray") + def testDeleteReaction(self): + self.assertTrue(self.issue.delete_reaction(85740167)) + def testGetTimeline(self): expected_events = { "referenced", diff --git a/tests/IssueComment.py b/tests/IssueComment.py index 67e61c69..5d052f08 100644 --- a/tests/IssueComment.py +++ b/tests/IssueComment.py @@ -8,8 +8,9 @@ # Copyright 2014 Vincent Jacques # # Copyright 2016 Jannis Gebauer # # Copyright 2016 Peter Buckley # -# Copyright 2017 Nicolas Agustín Torres # +# Copyright 2017 Nicolas Agustín Torres # # Copyright 2018 sfdye # +# Copyright 2020 Huan-Cheng Chang # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # @@ -83,3 +84,6 @@ class IssueComment(Framework.TestCase): self.assertEqual(reaction.id, 17282654) self.assertEqual(reaction.content, "hooray") + + def testDeleteReaction(self): + self.assertTrue(self.comment.delete_reaction(85743754)) diff --git a/tests/PullRequestComment.py b/tests/PullRequestComment.py index ae284d88..3dcb7ece 100644 --- a/tests/PullRequestComment.py +++ b/tests/PullRequestComment.py @@ -8,8 +8,9 @@ # Copyright 2014 Vincent Jacques # # Copyright 2016 Jannis Gebauer # # Copyright 2016 Peter Buckley # -# Copyright 2017 Nicolas Agustín Torres # +# Copyright 2017 Nicolas Agustín Torres # # Copyright 2018 sfdye # +# Copyright 2020 Huan-Cheng Chang # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # @@ -89,3 +90,6 @@ class PullRequestComment(Framework.TestCase): self.assertEqual(reaction.id, 17283822) self.assertEqual(reaction.content, "hooray") + + def testDeleteReaction(self): + self.assertTrue(self.comment.delete_reaction(85750463)) diff --git a/tests/ReplayData/CommitComment.testDeleteReaction.txt b/tests/ReplayData/CommitComment.testDeleteReaction.txt new file mode 100644 index 00000000..b82e23d2 --- /dev/null +++ b/tests/ReplayData/CommitComment.testDeleteReaction.txt @@ -0,0 +1,11 @@ +https +DELETE +api.github.com +None +/repos/jacquev6/PyGithub/comments/1361949/reactions/85737646 +{'Accept': 'application/vnd.github.squirrel-girl-preview', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +204 +[('Date', 'Mon, 28 Sep 2020 19:55:51 GMT'), ('Server', 'GitHub.com'), ('Status', '204 No Content'), ('X-OAuth-Scopes', 'public_repo, repo:status, write:discussion'), ('X-Accepted-OAuth-Scopes', ''), ('X-GitHub-Media-Type', 'github.squirrel-girl-preview'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4959'), ('X-RateLimit-Reset', '1601324668'), ('X-RateLimit-Used', '41'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Vary', 'Accept-Encoding, Accept, X-Requested-With, Accept-Encoding'), ('X-GitHub-Request-Id', 'C96E:F313:162969A9:1A634C51:5F723FC7')] + + diff --git a/tests/ReplayData/Issue.testDeleteReaction.txt b/tests/ReplayData/Issue.testDeleteReaction.txt new file mode 100644 index 00000000..aeab9bad --- /dev/null +++ b/tests/ReplayData/Issue.testDeleteReaction.txt @@ -0,0 +1,11 @@ +https +DELETE +api.github.com +None +/repos/jacquev6/PyGithub/issues/28/reactions/85740167 +{'Accept': 'application/vnd.github.squirrel-girl-preview', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +204 +[('Date', 'Mon, 28 Sep 2020 20:23:03 GMT'), ('Server', 'GitHub.com'), ('Status', '204 No Content'), ('X-OAuth-Scopes', 'public_repo, repo:status, write:discussion'), ('X-Accepted-OAuth-Scopes', ''), ('X-GitHub-Media-Type', 'github.squirrel-girl-preview'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4955'), ('X-RateLimit-Reset', '1601324668'), ('X-RateLimit-Used', '45'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Vary', 'Accept-Encoding, Accept, X-Requested-With, Accept-Encoding'), ('X-GitHub-Request-Id', 'AE16:FACE:CAD7D10:F1C172A:5F724627')] + + diff --git a/tests/ReplayData/IssueComment.testDeleteReaction.txt b/tests/ReplayData/IssueComment.testDeleteReaction.txt new file mode 100644 index 00000000..9b6aae16 --- /dev/null +++ b/tests/ReplayData/IssueComment.testDeleteReaction.txt @@ -0,0 +1,11 @@ +https +DELETE +api.github.com +None +/repos/jacquev6/PyGithub/issues/comments/5808311/reactions/85743754 +{'Accept': 'application/vnd.github.squirrel-girl-preview', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +204 +[('Date', 'Mon, 28 Sep 2020 20:58:11 GMT'), ('Server', 'GitHub.com'), ('Status', '204 No Content'), ('X-OAuth-Scopes', 'public_repo, repo:status, write:discussion'), ('X-Accepted-OAuth-Scopes', ''), ('X-GitHub-Media-Type', 'github.squirrel-girl-preview'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4983'), ('X-RateLimit-Reset', '1601330202'), ('X-RateLimit-Used', '17'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Vary', 'Accept-Encoding, Accept, X-Requested-With, Accept-Encoding'), ('X-GitHub-Request-Id', '8F46:7327:16616BD7:1AB22028:5F724E63')] + + diff --git a/tests/ReplayData/PullRequestComment.testDeleteReaction.txt b/tests/ReplayData/PullRequestComment.testDeleteReaction.txt new file mode 100644 index 00000000..1948cb5d --- /dev/null +++ b/tests/ReplayData/PullRequestComment.testDeleteReaction.txt @@ -0,0 +1,11 @@ +https +DELETE +api.github.com +None +/repos/jacquev6/PyGithub/pulls/comments/886298/reactions/85750463 +{'Accept': 'application/vnd.github.squirrel-girl-preview', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +204 +[('Date', 'Mon, 28 Sep 2020 22:15:48 GMT'), ('Server', 'GitHub.com'), ('Status', '204 No Content'), ('X-OAuth-Scopes', 'public_repo, repo:status, write:discussion'), ('X-Accepted-OAuth-Scopes', ''), ('X-GitHub-Media-Type', 'github.squirrel-girl-preview'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4991'), ('X-RateLimit-Reset', '1601334930'), ('X-RateLimit-Used', '9'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Vary', 'Accept-Encoding, Accept, X-Requested-With, Accept-Encoding'), ('X-GitHub-Request-Id', '9B34:FACF:17050546:1B72222B:5F726093')] + +