Skip to content

Commit 8c4b684

Browse files
committed
Add maintainer_can_modify parameter to create_pull
When we're creating a pull in the destination repo with credentials that don't have write permission on the source, we always get a 422 response from GitHub. This happens because maintainer_can_modify parameter is true by the default, and currently github3.py doesn't support setting of maintainer_can_modify to false when creating a PR. This commit adds this parameter to create_pull Repo method to comply with GitHub API.
1 parent 9345f86 commit 8c4b684

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/github3/repos/repo.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,9 @@ def create_project(self, name, body=None):
11511151
return self._instance_or_null(projects.Project, json)
11521152

11531153
@decorators.requires_auth
1154-
def create_pull(self, title, base, head, body=None):
1154+
def create_pull(
1155+
self, title, base, head, body=None, maintainer_can_modify=None
1156+
):
11551157
"""Create a pull request of ``head`` onto ``base`` branch in this repo.
11561158
11571159
:param str title:
@@ -1162,12 +1164,17 @@ def create_pull(self, title, base, head, body=None):
11621164
(required), e.g., 'username:branch'
11631165
:param str body:
11641166
(optional), markdown formatted description
1167+
:param bool maintainer_can_modify:
1168+
(optional), Indicates whether a maintainer is allowed to modify the
1169+
pull request or not.
11651170
:returns:
11661171
the created pull request
11671172
:rtype:
11681173
:class:`~github3.pulls.ShortPullRequest`
11691174
"""
11701175
data = {"title": title, "body": body, "base": base, "head": head}
1176+
if maintainer_can_modify is not None:
1177+
data["maintainer_can_modify"] = maintainer_can_modify
11711178
return self._create_pull(data)
11721179

11731180
@decorators.requires_auth

tests/unit/test_repos_repo.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,19 @@ def test_create_pull(self):
341341
self.instance.create_pull(**data)
342342
pull.assert_called_once_with(data)
343343

344+
def test_create_pull_maintainer_can_modify(self):
345+
"""Verify maintainer_can_modify option for creating a pull request."""
346+
data = {
347+
"title": "foo",
348+
"base": "master",
349+
"head": "feature_branch",
350+
"body": "body",
351+
"maintainer_can_modify": False
352+
}
353+
with unittest.mock.patch.object(Repository, "_create_pull") as pull:
354+
self.instance.create_pull(**data)
355+
pull.assert_called_once_with(data)
356+
344357
def test_create_pull_from_issue(self):
345358
"""Verify the request for creating a pull request from an issue."""
346359
with unittest.mock.patch.object(Repository, "_create_pull") as pull:

0 commit comments

Comments
 (0)