Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for head_repo param for PR creation #1192

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/github3/repos/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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:
Expand All @@ -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
Expand Down
22 changes: 22 additions & 0 deletions tests/integration/test_repos_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading