From acd515aaec2e3810d5c4e6a2142c259765eff2bc Mon Sep 17 00:00:00 2001 From: Mark Browning Date: Tue, 2 Jul 2019 19:52:11 -0500 Subject: [PATCH] Adds `get_issue_events` to `PullRequest` object (#1154) * Adds `get_issue_events` to `PullRequest` object * Add unit test for * Fix PullRequest.get_issue_events unit test Use actual event ids... * Fix missing import on PullRequest. I wish the unit tests would run in Python3... * Add PulReqeust.testGetIssueEvents ReplayData * Updating replay data to use developer's personal credentials. --- github/PullRequest.py | 15 +++++++++++++++ tests/PullRequest.py | 3 +++ .../ReplayData/PullRequest.testGetIssueEvents.txt | 11 +++++++++++ 3 files changed, 29 insertions(+) create mode 100644 tests/ReplayData/PullRequest.testGetIssueEvents.txt diff --git a/github/PullRequest.py b/github/PullRequest.py index af2100fe..82073b31 100644 --- a/github/PullRequest.py +++ b/github/PullRequest.py @@ -56,6 +56,8 @@ import github.IssueComment import github.Commit import github.PullRequestReview +import Consts + class PullRequest(github.GithubObject.CompletableGithubObject): """ @@ -627,6 +629,19 @@ class PullRequest(github.GithubObject.CompletableGithubObject): None ) + def get_issue_events(self): + """ + :calls: `GET /repos/:owner/:repo/issues/:issue_number/events `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.IssueEvent.IssueEvent` + """ + return github.PaginatedList.PaginatedList( + github.IssueEvent.IssueEvent, + self._requester, + self.issue_url + "/events", + None, + headers={'Accept': Consts.mediaTypeLockReasonPreview} + ) + def get_review(self, id): """ :calls: `GET /repos/:owner/:repo/pulls/:number/reviews/:id `_ diff --git a/tests/PullRequest.py b/tests/PullRequest.py index 4d8ed039..b691079b 100644 --- a/tests/PullRequest.py +++ b/tests/PullRequest.py @@ -131,6 +131,9 @@ class PullRequest(Framework.TestCase): comment = self.pull.get_issue_comment(8387331) self.assertEqual(comment.body, "Issue comment created by PyGithub") + def testGetIssueEvents(self): + self.assertListKeyEqual(self.pull.get_issue_events(), lambda e: e.id, [16349963, 16350729, 16350730, 16350731, 28469043, 98136335]) + def testGetReviewComments(self): epoch = datetime.datetime(1970, 1, 1, 0, 0) comments = self.pull.get_review_comments(since=epoch) diff --git a/tests/ReplayData/PullRequest.testGetIssueEvents.txt b/tests/ReplayData/PullRequest.testGetIssueEvents.txt new file mode 100644 index 00000000..a55f7862 --- /dev/null +++ b/tests/ReplayData/PullRequest.testGetIssueEvents.txt @@ -0,0 +1,11 @@ +https +GET +api.github.com +None +/repos/jacquev6/PyGithub/issues/31/events +{'Accept': 'application/vnd.github.sailor-v-preview+json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('Date', 'Sat, 29 Jun 2019 00:12:14 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Server', 'GitHub.com'), ('Status', '200 OK'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4964'), ('X-RateLimit-Reset', '1561767884'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding'), ('ETag', 'W/"e8868b673676b7b3ed46856d038bf5d1"'), ('X-OAuth-Scopes', 'repo'), ('X-Accepted-OAuth-Scopes', 'repo'), ('X-GitHub-Media-Type', 'github.sailor-v-preview; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type'), ('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'"), ('Content-Encoding', 'gzip'), ('X-GitHub-Request-Id', '1F21:3EEE:1B22EE9:20CFD3C:5D16ACDE')] +[{"id":16349963,"node_id":"MDE1OlN1YnNjcmliZWRFdmVudDE2MzQ5OTYz","url":"https://api.github.com/repos/jacquev6/PyGithub/issues/events/16349963","actor":{"login":"jacquev6","id":327146,"node_id":"MDQ6VXNlcjMyNzE0Ng==","avatar_url":"https://avatars1.githubusercontent.com/u/327146?v=4","gravatar_id":"","url":"https://api.github.com/users/jacquev6","html_url":"https://github.com/jacquev6","followers_url":"https://api.github.com/users/jacquev6/followers","following_url":"https://api.github.com/users/jacquev6/following{/other_user}","gists_url":"https://api.github.com/users/jacquev6/gists{/gist_id}","starred_url":"https://api.github.com/users/jacquev6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacquev6/subscriptions","organizations_url":"https://api.github.com/users/jacquev6/orgs","repos_url":"https://api.github.com/users/jacquev6/repos","events_url":"https://api.github.com/users/jacquev6/events{/privacy}","received_events_url":"https://api.github.com/users/jacquev6/received_events","type":"User","site_admin":false},"event":"subscribed","commit_id":null,"commit_url":null,"created_at":"2012-05-27T09:25:36Z"},{"id":16350729,"node_id":"MDE1OlJlZmVyZW5jZWRFdmVudDE2MzUwNzI5","url":"https://api.github.com/repos/jacquev6/PyGithub/issues/events/16350729","actor":{"login":"jacquev6","id":327146,"node_id":"MDQ6VXNlcjMyNzE0Ng==","avatar_url":"https://avatars1.githubusercontent.com/u/327146?v=4","gravatar_id":"","url":"https://api.github.com/users/jacquev6","html_url":"https://github.com/jacquev6","followers_url":"https://api.github.com/users/jacquev6/followers","following_url":"https://api.github.com/users/jacquev6/following{/other_user}","gists_url":"https://api.github.com/users/jacquev6/gists{/gist_id}","starred_url":"https://api.github.com/users/jacquev6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacquev6/subscriptions","organizations_url":"https://api.github.com/users/jacquev6/orgs","repos_url":"https://api.github.com/users/jacquev6/repos","events_url":"https://api.github.com/users/jacquev6/events{/privacy}","received_events_url":"https://api.github.com/users/jacquev6/received_events","type":"User","site_admin":false},"event":"referenced","commit_id":"688208b1a5a074871d0e9376119556897439697d","commit_url":"https://api.github.com/repos/jacquev6/PyGithub/commits/688208b1a5a074871d0e9376119556897439697d","created_at":"2012-05-27T10:29:07Z"},{"id":16350730,"node_id":"MDExOk1lcmdlZEV2ZW50MTYzNTA3MzA=","url":"https://api.github.com/repos/jacquev6/PyGithub/issues/events/16350730","actor":{"login":"jacquev6","id":327146,"node_id":"MDQ6VXNlcjMyNzE0Ng==","avatar_url":"https://avatars1.githubusercontent.com/u/327146?v=4","gravatar_id":"","url":"https://api.github.com/users/jacquev6","html_url":"https://github.com/jacquev6","followers_url":"https://api.github.com/users/jacquev6/followers","following_url":"https://api.github.com/users/jacquev6/following{/other_user}","gists_url":"https://api.github.com/users/jacquev6/gists{/gist_id}","starred_url":"https://api.github.com/users/jacquev6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacquev6/subscriptions","organizations_url":"https://api.github.com/users/jacquev6/orgs","repos_url":"https://api.github.com/users/jacquev6/repos","events_url":"https://api.github.com/users/jacquev6/events{/privacy}","received_events_url":"https://api.github.com/users/jacquev6/received_events","type":"User","site_admin":false},"event":"merged","commit_id":"688208b1a5a074871d0e9376119556897439697d","commit_url":"https://api.github.com/repos/jacquev6/PyGithub/commits/688208b1a5a074871d0e9376119556897439697d","created_at":"2012-05-27T10:29:07Z"},{"id":16350731,"node_id":"MDExOkNsb3NlZEV2ZW50MTYzNTA3MzE=","url":"https://api.github.com/repos/jacquev6/PyGithub/issues/events/16350731","actor":{"login":"jacquev6","id":327146,"node_id":"MDQ6VXNlcjMyNzE0Ng==","avatar_url":"https://avatars1.githubusercontent.com/u/327146?v=4","gravatar_id":"","url":"https://api.github.com/users/jacquev6","html_url":"https://github.com/jacquev6","followers_url":"https://api.github.com/users/jacquev6/followers","following_url":"https://api.github.com/users/jacquev6/following{/other_user}","gists_url":"https://api.github.com/users/jacquev6/gists{/gist_id}","starred_url":"https://api.github.com/users/jacquev6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacquev6/subscriptions","organizations_url":"https://api.github.com/users/jacquev6/orgs","repos_url":"https://api.github.com/users/jacquev6/repos","events_url":"https://api.github.com/users/jacquev6/events{/privacy}","received_events_url":"https://api.github.com/users/jacquev6/received_events","type":"User","site_admin":false},"event":"closed","commit_id":null,"commit_url":null,"created_at":"2012-05-27T10:29:07Z"},{"id":28469043,"node_id":"MDEzOkFzc2lnbmVkRXZlbnQyODQ2OTA0Mw==","url":"https://api.github.com/repos/jacquev6/PyGithub/issues/events/28469043","actor":{"login":"jacquev6","id":327146,"node_id":"MDQ6VXNlcjMyNzE0Ng==","avatar_url":"https://avatars1.githubusercontent.com/u/327146?v=4","gravatar_id":"","url":"https://api.github.com/users/jacquev6","html_url":"https://github.com/jacquev6","followers_url":"https://api.github.com/users/jacquev6/followers","following_url":"https://api.github.com/users/jacquev6/following{/other_user}","gists_url":"https://api.github.com/users/jacquev6/gists{/gist_id}","starred_url":"https://api.github.com/users/jacquev6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacquev6/subscriptions","organizations_url":"https://api.github.com/users/jacquev6/orgs","repos_url":"https://api.github.com/users/jacquev6/repos","events_url":"https://api.github.com/users/jacquev6/events{/privacy}","received_events_url":"https://api.github.com/users/jacquev6/received_events","type":"User","site_admin":false},"event":"assigned","commit_id":null,"commit_url":null,"created_at":"2012-11-03T08:19:40Z","assignee":{"login":"jacquev6","id":327146,"node_id":"MDQ6VXNlcjMyNzE0Ng==","avatar_url":"https://avatars1.githubusercontent.com/u/327146?v=4","gravatar_id":"","url":"https://api.github.com/users/jacquev6","html_url":"https://github.com/jacquev6","followers_url":"https://api.github.com/users/jacquev6/followers","following_url":"https://api.github.com/users/jacquev6/following{/other_user}","gists_url":"https://api.github.com/users/jacquev6/gists{/gist_id}","starred_url":"https://api.github.com/users/jacquev6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacquev6/subscriptions","organizations_url":"https://api.github.com/users/jacquev6/orgs","repos_url":"https://api.github.com/users/jacquev6/repos","events_url":"https://api.github.com/users/jacquev6/events{/privacy}","received_events_url":"https://api.github.com/users/jacquev6/received_events","type":"User","site_admin":false},"assigner":{"login":"ghost","id":10137,"node_id":"MDQ6VXNlcjEwMTM3","avatar_url":"https://avatars3.githubusercontent.com/u/10137?v=4","gravatar_id":"","url":"https://api.github.com/users/ghost","html_url":"https://github.com/ghost","followers_url":"https://api.github.com/users/ghost/followers","following_url":"https://api.github.com/users/ghost/following{/other_user}","gists_url":"https://api.github.com/users/ghost/gists{/gist_id}","starred_url":"https://api.github.com/users/ghost/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ghost/subscriptions","organizations_url":"https://api.github.com/users/ghost/orgs","repos_url":"https://api.github.com/users/ghost/repos","events_url":"https://api.github.com/users/ghost/events{/privacy}","received_events_url":"https://api.github.com/users/ghost/received_events","type":"User","site_admin":false}},{"id":98136335,"node_id":"MDEyOkxhYmVsZWRFdmVudDk4MTM2MzM1","url":"https://api.github.com/repos/jacquev6/PyGithub/issues/events/98136335","actor":{"login":"jacquev6","id":327146,"node_id":"MDQ6VXNlcjMyNzE0Ng==","avatar_url":"https://avatars1.githubusercontent.com/u/327146?v=4","gravatar_id":"","url":"https://api.github.com/users/jacquev6","html_url":"https://github.com/jacquev6","followers_url":"https://api.github.com/users/jacquev6/followers","following_url":"https://api.github.com/users/jacquev6/following{/other_user}","gists_url":"https://api.github.com/users/jacquev6/gists{/gist_id}","starred_url":"https://api.github.com/users/jacquev6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacquev6/subscriptions","organizations_url":"https://api.github.com/users/jacquev6/orgs","repos_url":"https://api.github.com/users/jacquev6/repos","events_url":"https://api.github.com/users/jacquev6/events{/privacy}","received_events_url":"https://api.github.com/users/jacquev6/received_events","type":"User","site_admin":false},"event":"labeled","commit_id":null,"commit_url":null,"created_at":"2014-03-02T18:55:09Z","label":{"name":"v1","color":"5319e7"}}] +