Repository: google/go-github
Pull request #2873 (2023-08-15 17:41:39)

Adding missing field important to find branch in fork from same owner
Hello there! I opened an [issue](https://github.com/google/go-github/issues/2872) to explain this suggestion.

I put the new field on your tests and keep working as before! There was a change that could solve my problem!

Fixes: #2872.

r-aramizu: Thank you @gmlewis ! My bad for forgot this 😅 
Done!
gmlewis: @r-aramizu - please follow the CLA instructions from the comment above:
https://github.com/google/go-github/pull/2873#issuecomment-1679373226
in order to sign the Google CLA.  Thank you!
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/google/go-github/pull/2873?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
> Merging [#2873](https://app.codecov.io/gh/google/go-github/pull/2873?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (263a3f3) into [master](https://app.codecov.io/gh/google/go-github/commit/352e4c8b9466dd650b09a8152b83655fc4634726?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (352e4c8) will **not change** coverage.
> The diff coverage is `n/a`.

```diff
@@           Coverage Diff           @@
##           master    #2873   +/-   ##
=======================================
  Coverage   98.07%   98.07%           
=======================================
  Files         139      139           
  Lines       12357    12357           
=======================================
  Hits        12119    12119           
  Misses        162      162           
  Partials       76       76           
```


| [Files Changed](https://app.codecov.io/gh/google/go-github/pull/2873?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) | Coverage Δ | |
|---|---|---|
| [github/pulls.go](https://app.codecov.io/gh/google/go-github/pull/2873?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google#diff-Z2l0aHViL3B1bGxzLmdv) | `96.77% <ø> (ø)` | |



Patch:
diff --git a/example/commitpr/main.go b/example/commitpr/main.go
index 2977928c..da3c5a58 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 8b82604e..06564f25 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/pulls.go b/github/pulls.go
index 533e86b5..29549e24 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"`


Test patch:
diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go
index 7d8729ee..46716b88 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_test.go b/github/pulls_test.go
index 87f6f41c..4ea6bfa9 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,