Skip to content

Commit

Permalink
Add maintainer can modify flag to create pull request (#703)
Browse files Browse the repository at this point in the history
* Add flag for maintainer can modify when creating pull requests

* Change default to be None to let github decide the behaviour

* Update docstring

* Follow conventions from other functions
  • Loading branch information
res0nance authored and sfdye committed Feb 15, 2018
1 parent 98d32af commit 0e5a1d1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions github/Repository.py
Expand Up @@ -1010,19 +1010,24 @@ def create_pull(self, *args, **kwds):
:param issue: :class:`github.Issue.Issue`
:param base: string
:param head: string
:param maintainer_can_modify: bool
:rtype: :class:`github.PullRequest.PullRequest`
"""
if len(args) + len(kwds) == 4:
if len(args) + len(kwds) >= 4:
return self.__create_pull_1(*args, **kwds)
else:
return self.__create_pull_2(*args, **kwds)

def __create_pull_1(self, title, body, base, head):
def __create_pull_1(self, title, body, base, head, maintainer_can_modify=github.GithubObject.NotSet):
assert isinstance(title, (str, unicode)), title
assert isinstance(body, (str, unicode)), body
assert isinstance(base, (str, unicode)), base
assert isinstance(head, (str, unicode)), head
return self.__create_pull(title=title, body=body, base=base, head=head)
assert maintainer_can_modify is github.GithubObject.NotSet or isinstance(maintainer_can_modify, bool), maintainer_can_modify
if maintainer_can_modify is not github.GithubObject.NotSet:
return self.__create_pull(title=title, body=body, base=base, head=head, maintainer_can_modify=maintainer_can_modify)
else:
return self.__create_pull(title=title, body=body, base=base, head=head)

def __create_pull_2(self, issue, base, head):
assert isinstance(issue, github.Issue.Issue), issue
Expand Down
2 changes: 1 addition & 1 deletion github/tests/ReplayData/Repository.testCreatePull.txt
Expand Up @@ -4,7 +4,7 @@ api.github.com
None
/repos/jacquev6/PyGithub/pulls
{'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
{"body": "Body of the pull request", "head": "BeaverSoftware:master", "base": "topic/RewriteWithGeneratedCode", "title": "Pull request created by PyGithub"}
{"body": "Body of the pull request", "head": "BeaverSoftware:master", "base": "topic/RewriteWithGeneratedCode", "maintainer_can_modify": true, "title": "Pull request created by PyGithub"}
201
[('status', '201 Created'), ('x-ratelimit-remaining', '4963'), ('content-length', '4486'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"1e069be7c3e3eb8b12afb1e1f5343dc9"'), ('date', 'Sun, 27 May 2012 09:25:37 GMT'), ('content-type', 'application/json; charset=utf-8'), ('location', 'https://api.github.com/repos/jacquev6/PyGithub/pulls/31')]
{"merged":false,"patch_url":"https://github.com/jacquev6/PyGithub/pull/31.patch","mergeable":null,"head":{"ref":"master","label":"BeaverSoftware:master","repo":{"clone_url":"https://github.com/BeaverSoftware/PyGithub.git","has_downloads":true,"watchers":1,"updated_at":"2012-05-27T09:09:17Z","homepage":"http://vincent-jacques.net/PyGithub","url":"https://api.github.com/repos/BeaverSoftware/PyGithub","mirror_url":null,"has_wiki":false,"has_issues":false,"fork":true,"forks":0,"size":176,"private":false,"open_issues":0,"svn_url":"https://github.com/BeaverSoftware/PyGithub","owner":{"url":"https://api.github.com/users/BeaverSoftware","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","login":"BeaverSoftware","id":1424031,"avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png"},"name":"PyGithub","language":"Python","description":"Python library implementing the full Github API v3","ssh_url":"git@github.com:BeaverSoftware/PyGithub.git","pushed_at":"2012-05-27T09:09:17Z","created_at":"2012-05-27T08:50:04Z","id":4460787,"git_url":"git://github.com/BeaverSoftware/PyGithub.git","html_url":"https://github.com/BeaverSoftware/PyGithub","full_name":"BeaverSoftware/PyGithub"},"user":{"url":"https://api.github.com/users/BeaverSoftware","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","login":"BeaverSoftware","id":1424031,"avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png"},"sha":"8a4f306d4b223682dd19410d4a9150636ebe4206"},"updated_at":"2012-05-27T09:25:36Z","issue_url":"https://github.com/jacquev6/PyGithub/issues/31","body":"Body of the pull request","url":"https://api.github.com/repos/jacquev6/PyGithub/pulls/31","comments":0,"base":{"ref":"topic/RewriteWithGeneratedCode","label":"jacquev6:topic/RewriteWithGeneratedCode","repo":{"clone_url":"https://github.com/jacquev6/PyGithub.git","has_downloads":true,"watchers":15,"updated_at":"2012-05-27T08:50:04Z","homepage":"http://vincent-jacques.net/PyGithub","url":"https://api.github.com/repos/jacquev6/PyGithub","mirror_url":null,"has_wiki":false,"has_issues":true,"fork":false,"forks":3,"size":308,"private":false,"open_issues":16,"svn_url":"https://github.com/jacquev6/PyGithub","owner":{"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"},"name":"PyGithub","language":"Python","description":"Python library implementing the full Github API v3","ssh_url":"git@github.com:jacquev6/PyGithub.git","pushed_at":"2012-05-27T07:29:24Z","created_at":"2012-02-25T12:53:47Z","id":3544490,"git_url":"git://github.com/jacquev6/PyGithub.git","html_url":"https://github.com/jacquev6/PyGithub","full_name":"jacquev6/PyGithub"},"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"},"sha":"ed866fc43833802ab553e5ff8581c81bb00dd433"},"number":31,"merged_by":null,"closed_at":null,"title":"Pull request created by PyGithub","deletions":384,"merged_at":null,"diff_url":"https://github.com/jacquev6/PyGithub/pull/31.diff","additions":511,"_links":{"self":{"href":"https://api.github.com/repos/jacquev6/PyGithub/pulls/31"},"comments":{"href":"https://api.github.com/repos/jacquev6/PyGithub/issues/31/comments"},"issue":{"href":"https://api.github.com/repos/jacquev6/PyGithub/issues/31"},"html":{"href":"https://github.com/jacquev6/PyGithub/pull/31"},"review_comments":{"href":"https://api.github.com/repos/jacquev6/PyGithub/pulls/31/comments"}},"created_at":"2012-05-27T09:25:36Z","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"},"state":"open","id":1436215,"review_comments":0,"commits":3,"changed_files":45,"html_url":"https://github.com/jacquev6/PyGithub/pull/31"}
Expand Down
2 changes: 1 addition & 1 deletion github/tests/Repository.py
Expand Up @@ -460,7 +460,7 @@ def testGetSubscribers(self):
self.assertListKeyEqual(self.repo.get_subscribers(), lambda u: u.login, ["jacquev6", "equus12", "bilderbuchi", "hcilab", "hattya", "firstthumb", "gregwjacobs", "sagarsane", "liang456", "berndca", "Lyloa"])

def testCreatePull(self):
pull = self.repo.create_pull("Pull request created by PyGithub", "Body of the pull request", "topic/RewriteWithGeneratedCode", "BeaverSoftware:master")
pull = self.repo.create_pull("Pull request created by PyGithub", "Body of the pull request", "topic/RewriteWithGeneratedCode", "BeaverSoftware:master", True)
self.assertEqual(pull.id, 1436215)

def testCreatePullFromIssue(self):
Expand Down

0 comments on commit 0e5a1d1

Please sign in to comment.