diff --git a/example/commitpr/main.go b/example/commitpr/main.go index 2977928cc6..da3c5a5819 100644 --- a/example/commitpr/main.go +++ b/example/commitpr/main.go @@ -38,6 +38,7 @@ var ( sourceRepo = flag.String("source-repo", "", "Name of repo to create the commit in.") commitMessage = flag.String("commit-message", "", "Content of the commit message.") commitBranch = flag.String("commit-branch", "", "Name of branch to create the commit in. If it does not already exists, it will be created using the `base-branch` parameter") + repoBranch = flag.String("repo-branch", "", "Name of the repository where the changes in the pull request were made. This field is required for cross-repository pull requests if both repositories are owned by the same organization") baseBranch = flag.String("base-branch", "master", "Name of branch to create the `commit-branch` from.") prRepoOwner = flag.String("merge-repo-owner", "", "Name of the owner (user or org) of the repo to create the PR against. If not specified, the value of the `-source-owner` flag will be used.") prRepo = flag.String("merge-repo", "", "Name of repo to create the PR against. If not specified, the value of the `-source-repo` flag will be used.") @@ -164,6 +165,7 @@ func createPR() (err error) { newPR := &github.NewPullRequest{ Title: prSubject, Head: commitBranch, + HeadRepo: repoBranch, Base: prBranch, Body: prDescription, MaintainerCanModify: github.Bool(true), diff --git a/github/github-accessors.go b/github/github-accessors.go index 8b82604e9e..06564f250c 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -11374,6 +11374,14 @@ func (n *NewPullRequest) GetHead() string { return *n.Head } +// GetHeadRepo returns the HeadRepo field if it's non-nil, zero value otherwise. +func (n *NewPullRequest) GetHeadRepo() string { + if n == nil || n.HeadRepo == nil { + return "" + } + return *n.HeadRepo +} + // GetIssue returns the Issue field if it's non-nil, zero value otherwise. func (n *NewPullRequest) GetIssue() int { if n == nil || n.Issue == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 7d8729ee3f..46716b8806 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -13315,6 +13315,16 @@ func TestNewPullRequest_GetHead(tt *testing.T) { n.GetHead() } +func TestNewPullRequest_GetHeadRepo(tt *testing.T) { + var zeroValue string + n := &NewPullRequest{HeadRepo: &zeroValue} + n.GetHeadRepo() + n = &NewPullRequest{} + n.GetHeadRepo() + n = nil + n.GetHeadRepo() +} + func TestNewPullRequest_GetIssue(tt *testing.T) { var zeroValue int n := &NewPullRequest{Issue: &zeroValue} diff --git a/github/pulls.go b/github/pulls.go index 533e86b5f0..29549e24b8 100644 --- a/github/pulls.go +++ b/github/pulls.go @@ -244,6 +244,7 @@ func (s *PullRequestsService) GetRaw(ctx context.Context, owner string, repo str type NewPullRequest struct { Title *string `json:"title,omitempty"` Head *string `json:"head,omitempty"` + HeadRepo *string `json:"head_repo,omitempty"` Base *string `json:"base,omitempty"` Body *string `json:"body,omitempty"` Issue *int `json:"issue,omitempty"` diff --git a/github/pulls_test.go b/github/pulls_test.go index 87f6f41cfb..4ea6bfa9d1 100644 --- a/github/pulls_test.go +++ b/github/pulls_test.go @@ -933,6 +933,7 @@ func TestNewPullRequest_Marshal(t *testing.T) { u := &NewPullRequest{ Title: String("eh"), Head: String("eh"), + HeadRepo: String("eh"), Base: String("eh"), Body: String("eh"), Issue: Int(1), @@ -943,6 +944,7 @@ func TestNewPullRequest_Marshal(t *testing.T) { want := `{ "title": "eh", "head": "eh", + "head_repo": "eh", "base": "eh", "body": "eh", "issue": 1,