Repository: PyGithub/PyGithub

Issue:
Expose `get_issue_events()` from `PullRequest`
I'm attempting to script automatically closing old Pull Requests, but letting users re-open them if they are still working on them. I don't want to *keep* closing PRs, so I want to check that a PR hasn't been re-opened before closing it. One way of doing that is to look through the list of "issue events", but first I need to use `PullRequest.as_issue()`, which makes a needless API request. 

Only the issue number is needed for `GET /repos/:owner/:repo/issues/:issue_number/events`, so it should be possible to do directly from the `PullRequest` object. Any chance you could add that method? Similar to `PullRequest.get_issue_comments()` etc.


Discussion:

Resolving patch:
diff --git a/github/PullRequest.py b/github/PullRequest.py
--- a/github/PullRequest.py
+++ b/github/PullRequest.py
@@ -56,6 +56,8 @@
 import github.Commit
 import github.PullRequestReview
 
+import Consts
+
 
 class PullRequest(github.GithubObject.CompletableGithubObject):
     """
@@ -627,6 +629,19 @@ def get_issue_comments(self):
             None
         )
 
+    def get_issue_events(self):
+        """
+        :calls: `GET /repos/:owner/:repo/issues/:issue_number/events <http://developer.github.com/v3/issues/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 <https://developer.github.com/v3/pulls/reviews>`_


Test patch:
diff --git a/tests/PullRequest.py b/tests/PullRequest.py
--- a/tests/PullRequest.py
+++ b/tests/PullRequest.py
@@ -131,6 +131,9 @@ def testGetIssueComment(self):
         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
--- /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"}}]
+