From b1c35499f4a97e71faa142e376fbea9488362679 Mon Sep 17 00:00:00 2001 From: Steve Kowalik Date: Tue, 10 Mar 2020 12:39:23 +1100 Subject: [PATCH] Don't transform completely in PullRequest.*assignees (#1428) The two methods PullRequest.add_to_assignees() and PullRequest.remove_from_assignees() are special, in that they call POST/DELETE on the issue_url of the pull request, and then transform all their attributes based on what was returned. This has a number of effects, none of them any good for calling new methods on the same pull request object. Instead, only pull out the changed attribute and use that. Also change the returned URL for the POST call in the replay data to match what GitHub returns. Fixes #1406 --- github/PullRequest.py | 6 ++++-- tests/PullRequest.py | 3 +++ tests/ReplayData/PullRequest.testAddAndRemoveAssignees.txt | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/github/PullRequest.py b/github/PullRequest.py index dd1be134..e1e7168e 100644 --- a/github/PullRequest.py +++ b/github/PullRequest.py @@ -872,7 +872,8 @@ class PullRequest(github.GithubObject.CompletableGithubObject): headers, data = self._requester.requestJsonAndCheck( "POST", self.issue_url + "/assignees", input=post_parameters ) - self._useAttributes(data) + # Only use the assignees attribute, since we call this PR as an issue + self._useAttributes({"assignees": data["assignees"]}) def remove_from_assignees(self, *assignees): """ @@ -895,7 +896,8 @@ class PullRequest(github.GithubObject.CompletableGithubObject): headers, data = self._requester.requestJsonAndCheck( "DELETE", self.issue_url + "/assignees", input=post_parameters ) - self._useAttributes(data) + # Only use the assignees attribute, since we call this PR as an issue + self._useAttributes({"assignees": data["assignees"]}) def update_branch(self, expected_head_sha=github.GithubObject.NotSet): """ diff --git a/tests/PullRequest.py b/tests/PullRequest.py index 90ca46cd..a8e0cd02 100644 --- a/tests/PullRequest.py +++ b/tests/PullRequest.py @@ -365,16 +365,19 @@ class PullRequest(Framework.TestCase): self.assertListKeyEqual( self.pull.assignees, lambda a: a.login, ["stuglaser", "jacquev6"] ) + url = self.pull.url self.pull.add_to_assignees(user1, user2) self.assertListKeyEqual( self.pull.assignees, lambda a: a.login, ["jacquev6", "stuglaser", "jayfk", "jzelinskie"], ) + self.assertEqual(self.pull.url, url) self.pull.remove_from_assignees(user1, user2) self.assertListKeyEqual( self.pull.assignees, lambda a: a.login, ["jacquev6", "stuglaser"] ) + self.assertEqual(self.pull.url, url) def testUpdateBranch(self): self.assertTrue( diff --git a/tests/ReplayData/PullRequest.testAddAndRemoveAssignees.txt b/tests/ReplayData/PullRequest.testAddAndRemoveAssignees.txt index fc995787..e88579ce 100644 --- a/tests/ReplayData/PullRequest.testAddAndRemoveAssignees.txt +++ b/tests/ReplayData/PullRequest.testAddAndRemoveAssignees.txt @@ -18,7 +18,7 @@ None {"assignees":["jayfk","jzelinskie"]} 201 [('status', '200 OK'), ('x-ratelimit-remaining', '4985'), ('content-length', '335'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"d135d74d2ea2159d044676a220d41d3a"'), ('date', 'Sun, 27 May 2012 09:04:06 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/pulls/31","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":31,"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":[{"login":"jacquev6","id": 327146,"avatar_url":"https://avatars.githubusercontent.com/u/327146?v=3","gravatar_id":"","url":"https://api.github.com/users/jacquev6"},{"login":"stuglaser","id": 1527117,"avatar_url":"https://avatars.githubusercontent.com/u/1527117?v=3","gravatar_id":"","url":"https://api.github.com/users/stuglaser"},{"login":"jayfk","id": 2930472,"avatar_url":"https://avatars.githubusercontent.com/u/2930472?v=3","gravatar_id":"","url":"https://api.github.com/users/jayfk"},{"login":"jzelinskie","id": 343539,"avatar_url":"https://avatars.githubusercontent.com/u/343539?v=3","gravatar_id":"","url":"https://api.github.com/users/jzelinskie"}],"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/31"} +{"updated_at":"2012-05-26T14:59:33Z","body":"Body edited by PyGithub","url":"https://api.github.com/repos/jacquev6/PyGithub/issues/31","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":31,"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":[{"login":"jacquev6","id": 327146,"avatar_url":"https://avatars.githubusercontent.com/u/327146?v=3","gravatar_id":"","url":"https://api.github.com/users/jacquev6"},{"login":"stuglaser","id": 1527117,"avatar_url":"https://avatars.githubusercontent.com/u/1527117?v=3","gravatar_id":"","url":"https://api.github.com/users/stuglaser"},{"login":"jayfk","id": 2930472,"avatar_url":"https://avatars.githubusercontent.com/u/2930472?v=3","gravatar_id":"","url":"https://api.github.com/users/jayfk"},{"login":"jzelinskie","id": 343539,"avatar_url":"https://avatars.githubusercontent.com/u/343539?v=3","gravatar_id":"","url":"https://api.github.com/users/jzelinskie"}],"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/31"} https DELETE