From 0e1c0f085852b2ce3a99fd8a7f7d1886d6c02de1 Mon Sep 17 00:00:00 2001 From: r-aramizu Date: Fri, 11 Aug 2023 16:42:14 -0300 Subject: [PATCH 1/5] adding head repo field in PullRequest structure --- example/commitpr/main.go | 2 ++ github/pulls.go | 1 + 2 files changed, 3 insertions(+) diff --git a/example/commitpr/main.go b/example/commitpr/main.go index 2977928cc66..da3c5a5819a 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/pulls.go b/github/pulls.go index 533e86b5f0a..ee42d155d2d 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"` Base *string `json:"base,omitempty"` Body *string `json:"body,omitempty"` Issue *int `json:"issue,omitempty"` From 1215c0d4cae2ba12d87bb3016715d14c09b7f9ca Mon Sep 17 00:00:00 2001 From: r-aramizu Date: Tue, 15 Aug 2023 12:48:30 -0300 Subject: [PATCH 2/5] adding head_repo field in new pull request marshal test --- github/pulls_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/github/pulls_test.go b/github/pulls_test.go index 87f6f41cfb8..586d0a2ced1 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), From e5eab782121b1b5b30c5c23accadc5ab7b7cf1db Mon Sep 17 00:00:00 2001 From: r-aramizu Date: Tue, 15 Aug 2023 12:48:54 -0300 Subject: [PATCH 3/5] adding head_repo field in new pull request marshal test --- github/pulls_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/github/pulls_test.go b/github/pulls_test.go index 586d0a2ced1..4ea6bfa9d1e 100644 --- a/github/pulls_test.go +++ b/github/pulls_test.go @@ -944,6 +944,7 @@ func TestNewPullRequest_Marshal(t *testing.T) { want := `{ "title": "eh", "head": "eh", + "head_repo": "eh", "base": "eh", "body": "eh", "issue": 1, From 3f3659daa03962bd94be57fbba28aa307dbd28d0 Mon Sep 17 00:00:00 2001 From: r-aramizu Date: Tue, 15 Aug 2023 12:50:28 -0300 Subject: [PATCH 4/5] adding omitempty HeadRepo field on struct --- github/pulls.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/pulls.go b/github/pulls.go index ee42d155d2d..29549e24b86 100644 --- a/github/pulls.go +++ b/github/pulls.go @@ -244,7 +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"` + HeadRepo *string `json:"head_repo,omitempty"` Base *string `json:"base,omitempty"` Body *string `json:"body,omitempty"` Issue *int `json:"issue,omitempty"` From 431f1c1eaab12d94a1a8bd8672e1223b10df77ff Mon Sep 17 00:00:00 2001 From: r-aramizu Date: Tue, 15 Aug 2023 15:08:45 -0300 Subject: [PATCH 5/5] fixing tests --- github/github-accessors.go | 8 ++++++++ github/github-accessors_test.go | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/github/github-accessors.go b/github/github-accessors.go index 3f665ede5cb..dde2e9b5693 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -11342,6 +11342,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 712d8fc94dd..bd3f5e31c9c 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -13275,6 +13275,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}