diff --git a/src/github3/repos/repo.py b/src/github3/repos/repo.py index 89e99e76..59f24bfa 100644 --- a/src/github3/repos/repo.py +++ b/src/github3/repos/repo.py @@ -1162,7 +1162,13 @@ def create_project(self, name, body=None): @decorators.requires_auth def create_pull( - self, title, base, head, body=None, maintainer_can_modify=None + self, + title, + base, + head, + head_repo=None, + body=None, + maintainer_can_modify=None, ): """Create a pull request of ``head`` onto ``base`` branch in this repo. @@ -1171,7 +1177,9 @@ def create_pull( :param str base: (required), e.g., 'master' :param str head: - (required), e.g., 'username:branch' + (required), e.g., 'username:branch' or 'branch' when using head_repo + :param str head_repo: + (optional), required for cross-repository pull requests if both repositories are owned by the same organization. e.g., 'organization/repository' :param str body: (optional), markdown formatted description :param bool maintainer_can_modify: @@ -1185,6 +1193,8 @@ def create_pull( data = {"title": title, "body": body, "base": base, "head": head} if maintainer_can_modify is not None: data["maintainer_can_modify"] = maintainer_can_modify + if head_repo is not None: + data["head_repo"] = head_repo return self._create_pull(data) @decorators.requires_auth diff --git a/tests/integration/test_repos_repo.py b/tests/integration/test_repos_repo.py index b1baff0e..32e00d37 100644 --- a/tests/integration/test_repos_repo.py +++ b/tests/integration/test_repos_repo.py @@ -481,6 +481,28 @@ def test_create_pull(self): assert isinstance(pull_request, github3.pulls.ShortPullRequest) + def test_create_pull_head_repo(self): + """Test the ability to create a pull request by fully specifying the organization, repository, and branch.""" + self.token_login() + cassette_name = self.cassette_name("create_pull") + with self.recorder.use_cassette(cassette_name): + original_repository = self.gh.repository( + "github3py", "github3.py" + ) + repository = original_repository.create_fork( + organization="testgh3py" + ) + pull_request = repository.create_pull( + title="Update forked repo", + base="master", + head="develop", + head_repo="testgh3py/github3.py", + body="Testing the ability to create a pull request", + ) + repository.delete() + + assert isinstance(pull_request, github3.pulls.ShortPullRequest) + def test_create_pull_from_issue(self): """Verify creation of a pull request from an issue.""" self.token_login()