From 42a9ae31e76e52e94f230b79c9782f9fa72b91cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radek=20Ma=C5=88=C3=A1k?= Date: Tue, 13 Aug 2024 14:43:28 +0200 Subject: [PATCH 1/2] Add support for head_repo param for PR creation This parameter allows the repository containing the PR branch to be fully specified in the head_repo with value of `organization/repository` and using head param for the branch name. This parameter is requried when the fork does not share the name as the original repository. e.g. when the fork repositry is in the same organization as the main repository. --- src/github3/repos/repo.py | 8 ++++++-- tests/integration/test_repos_repo.py | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/github3/repos/repo.py b/src/github3/repos/repo.py index 89e99e76..3e7f02d1 100644 --- a/src/github3/repos/repo.py +++ b/src/github3/repos/repo.py @@ -1162,7 +1162,7 @@ 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 +1171,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 +1187,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() From b9e6a0b7322e53d270778b489f5dbf478c9332f9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 21 Aug 2024 12:43:13 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/github3/repos/repo.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/github3/repos/repo.py b/src/github3/repos/repo.py index 3e7f02d1..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, head_repo=None, 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.