Skip to content

Commit

Permalink
Added option to create review for Pull request (#662)
Browse files Browse the repository at this point in the history
* Added option to create review for Pull request

* Fix tests
  • Loading branch information
gshefer authored and sfdye committed Mar 20, 2018
1 parent 3cd176e commit 162f039
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 5 deletions.
25 changes: 25 additions & 0 deletions github/PullRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,31 @@ def create_issue_comment(self, body):
)
return github.IssueComment.IssueComment(self._requester, headers, data, completed=True)

def create_review(self, commit, body, event=github.GithubObject.NotSet, comments=github.GithubObject.NotSet):
"""
:calls: `POST /repos/:owner/:repo/pulls/:number/reviews <https://developer.github.com/v3/pulls/reviews/>`_
:param commit: github.Commit.Commit
:param body: string
:param event: string
:param comments: list
:rtype: :class:`github.PullRequestReview.PullRequestReview`
"""
assert isinstance(commit, github.Commit.Commit), commit
assert isinstance(body, str), body
assert event is github.GithubObject.NotSet or isinstance(event, str), event
assert comments is github.GithubObject.NotSet or isinstance(comments, list), comments
post_parameters = {'commit_id': commit.sha, 'body': body}
post_parameters['event'] = 'COMMENT' if event == github.GithubObject.NotSet else event
if comments is github.GithubObject.NotSet:
post_parameters['comments'] = []
headers, data = self._requester.requestJsonAndCheck(
"POST",
self.url + "/reviews",
input=post_parameters
)
self._useAttributes(data)
return github.PullRequestReview.PullRequestReview(self._requester, headers, data, completed=True)

def edit(self, title=github.GithubObject.NotSet, body=github.GithubObject.NotSet, state=github.GithubObject.NotSet, base=github.GithubObject.NotSet):
"""
:calls: `PATCH /repos/:owner/:repo/pulls/:number <http://developer.github.com/v3/pulls>`_
Expand Down
7 changes: 7 additions & 0 deletions github/tests/PullRequestReview.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ def setUp(self):
self.repo = self.g.get_repo("PyGithub/PyGithub")
self.pull = self.repo.get_pull(538)

# Test ability to create a review
self.created_pullreview = self.pull.create_review(
self.repo.get_commit('2f0e4e55fe87e38d26efc9aa1346f56abfbd6c52'),
'Some review created by PyGithub'
)

# Test ability to get all reviews
self.pullreviews = self.pull.get_reviews()

Expand All @@ -51,6 +57,7 @@ def testAttributes(self):
self.assertEqual(self.pullreview.html_url, "https://github.com/PyGithub/PyGithub/pull/538#pullrequestreview-28482091")
self.assertEqual(self.pullreview.pull_request_url, "https://api.github.com/repos/PyGithub/PyGithub/pulls/538")
self.assertEqual(self.pullreview.submitted_at, datetime.datetime(2017, 3, 22, 19, 6, 59))
self.assertIn(self.created_pullreview, self.pullreviews)

# test __repr__() based on this attributes
self.assertEqual(self.pullreview.__repr__(), 'PullRequestReview(user=NamedUser(login="jzelinskie"), id=28482091)')
1 change: 0 additions & 1 deletion github/tests/ReplayData/PullRequest.testGetCommits.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ None
200
[('status', '200 OK'), ('x-ratelimit-remaining', '4975'), ('content-length', '4531'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"b4ea459213c1dd415628476619cbbc25"'), ('date', 'Sun, 27 May 2012 10:20:23 GMT'), ('content-type', 'application/json; charset=utf-8')]
[{"author":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"url":"https://api.github.com/repos/jacquev6/PyGithub/commits/4aadfff21cdd2d2566b0e4bd7309c233b5f4ae23","committer":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"sha":"4aadfff21cdd2d2566b0e4bd7309c233b5f4ae23","parents":[{"url":"https://api.github.com/repos/jacquev6/PyGithub/commits/ed866fc43833802ab553e5ff8581c81bb00dd433","sha":"ed866fc43833802ab553e5ff8581c81bb00dd433"}],"commit":{"author":{"email":"vincent@vincent-jacques.net","name":"Vincent Jacques","date":"2012-05-27T00:33:23-07:00"},"url":"https://api.github.com/repos/jacquev6/PyGithub/git/commits/4aadfff21cdd2d2566b0e4bd7309c233b5f4ae23","message":"Improve test coverage","committer":{"email":"vincent@vincent-jacques.net","name":"Vincent Jacques","date":"2012-05-27T00:33:23-07:00"},"tree":{"url":"https://api.github.com/repos/jacquev6/PyGithub/git/trees/3447efc7d0f2e0197a722c55c13cde7417d1f2d3","sha":"3447efc7d0f2e0197a722c55c13cde7417d1f2d3"}}},{"author":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"url":"https://api.github.com/repos/jacquev6/PyGithub/commits/93dcae5cf207de376c91d0599226e7c7563e1d16","committer":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"sha":"93dcae5cf207de376c91d0599226e7c7563e1d16","parents":[{"url":"https://api.github.com/repos/jacquev6/PyGithub/commits/4aadfff21cdd2d2566b0e4bd7309c233b5f4ae23","sha":"4aadfff21cdd2d2566b0e4bd7309c233b5f4ae23"}],"commit":{"author":{"email":"vincent@vincent-jacques.net","name":"Vincent Jacques","date":"2012-05-27T00:37:17-07:00"},"url":"https://api.github.com/repos/jacquev6/PyGithub/git/commits/93dcae5cf207de376c91d0599226e7c7563e1d16","message":"Remove branch coverage for optional attributes (temporary?)","committer":{"email":"vincent@vincent-jacques.net","name":"Vincent Jacques","date":"2012-05-27T00:37:17-07:00"},"tree":{"url":"https://api.github.com/repos/jacquev6/PyGithub/git/trees/d925a951cd6a5442e91dcfded3171520e9cca5de","sha":"d925a951cd6a5442e91dcfded3171520e9cca5de"}}},{"author":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"url":"https://api.github.com/repos/jacquev6/PyGithub/commits/8a4f306d4b223682dd19410d4a9150636ebe4206","committer":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"sha":"8a4f306d4b223682dd19410d4a9150636ebe4206","parents":[{"url":"https://api.github.com/repos/jacquev6/PyGithub/commits/93dcae5cf207de376c91d0599226e7c7563e1d16","sha":"93dcae5cf207de376c91d0599226e7c7563e1d16"}],"commit":{"author":{"email":"vincent@vincent-jacques.net","name":"Vincent Jacques","date":"2012-05-27T02:07:47-07:00"},"url":"https://api.github.com/repos/jacquev6/PyGithub/git/commits/8a4f306d4b223682dd19410d4a9150636ebe4206","message":"Test (and implement) Issue.*_label*\n\nAnd this commit will be used to test PullRequests","committer":{"email":"vincent@vincent-jacques.net","name":"Vincent Jacques","date":"2012-05-27T02:07:47-07:00"},"tree":{"url":"https://api.github.com/repos/jacquev6/PyGithub/git/trees/fa0251344d6b0b9f69f33c1faf6e3323001b309d","sha":"fa0251344d6b0b9f69f33c1faf6e3323001b309d"}}}]

0 comments on commit 162f039

Please sign in to comment.