diff --git a/pkg/github/github.go b/pkg/github/github.go index d6acc6c1b81..2fd5fa8c0cf 100644 --- a/pkg/github/github.go +++ b/pkg/github/github.go @@ -193,14 +193,9 @@ func (g *githubClient) ListTags( } } -// CreatePullRequest Creates a new pull request in owner/repo:baseBranch to merge changes from headBranchName -// which is a string containing a branch in the same repository or a user:branch pair func (g *githubClient) CreatePullRequest( ctx context.Context, owner, repo, baseBranchName, headBranchName, title, body string, ) (*github.PullRequest, error) { - - // headBranchName := fmt.Sprintf("%s:%s", owner, sourceBranch) - newPullRequest := &github.NewPullRequest{ Title: &title, Head: &headBranchName, @@ -214,8 +209,7 @@ func (g *githubClient) CreatePullRequest( return pr, err } - // sugar.Infof("PR created: %s\n", pr.GetHTMLURL()) - logrus.Infof("Succesfully created PR #%d", pr.GetNumber()) + logrus.Infof("Successfully created PR #%d", pr.GetNumber()) return pr, nil } @@ -323,3 +317,17 @@ func (g *GitHub) Releases(owner, repo string, includePrereleases bool) ([]*githu return releases, nil } + +// CreatePullRequest Creates a new pull request in owner/repo:baseBranch to merge changes from headBranchName +// which is a string containing a branch in the same repository or a user:branch pair +func (g *GitHub) CreatePullRequest( + owner, repo, baseBranchName, headBranchName, title, body string, +) (*github.PullRequest, error) { + // Use the client to create a new PR + pr, err := g.Client().CreatePullRequest(context.Background(), owner, repo, baseBranchName, headBranchName, title, body) + if err != nil { + return pr, err + } + + return pr, nil +} diff --git a/pkg/github/github_test.go b/pkg/github/github_test.go index e5f6c7775e3..4783350b7ba 100644 --- a/pkg/github/github_test.go +++ b/pkg/github/github_test.go @@ -272,3 +272,18 @@ func TestReleasesFailed(t *testing.T) { require.NotNil(t, err) require.Nil(t, res, nil) } + +func TestCreatePullRequest(t *testing.T) { + // Given + sut, client := newSUT() + fakeID := int64(1234) + client.CreatePullRequestReturns(&gogithub.PullRequest{ID: &fakeID}, nil) + + // When + pr, err := sut.CreatePullRequest("kubernetes-fake-org", "kubernetes-fake-repo", "master", "user:head-branch", "PR Title", "PR Body") + + // Then + require.Nil(t, err) + require.NotNil(t, pr, nil) + require.Equal(t, fakeID, pr.GetID()) +} diff --git a/pkg/github/githubfakes/fake_client.go b/pkg/github/githubfakes/fake_client.go index 6d2fb62cd42..5b02c621620 100644 --- a/pkg/github/githubfakes/fake_client.go +++ b/pkg/github/githubfakes/fake_client.go @@ -723,4 +723,14 @@ func (fake *FakeClient) CreatePullRequest( return fakeReturns.result1, fakeReturns.result2 } +func (fake *FakeClient) CreatePullRequestReturns(result1 *githuba.PullRequest, result2 error) { + fake.createPullRequestMutex.Lock() + defer fake.createPullRequestMutex.Unlock() + fake.CreatePullRequestStub = nil + fake.createPullRequestReturns = struct { + result1 *githuba.PullRequest + result2 error + }{result1, result2} +} + var _ github.Client = new(FakeClient) diff --git a/pkg/github/record.go b/pkg/github/record.go index bec911a38fa..e98af3ec910 100644 --- a/pkg/github/record.go +++ b/pkg/github/record.go @@ -150,7 +150,6 @@ func (c *githubNotesRecordClient) ListTags( func (c *githubNotesRecordClient) CreatePullRequest( ctx context.Context, owner, repo, baseBranchName, headBranchName, title, body string, ) (*github.PullRequest, error) { - return &github.PullRequest{}, nil } diff --git a/pkg/github/replay.go b/pkg/github/replay.go index 17b69d3f78f..fe31aa68490 100644 --- a/pkg/github/replay.go +++ b/pkg/github/replay.go @@ -138,7 +138,6 @@ func (c *githubNotesReplayClient) ListTags( func (c *githubNotesReplayClient) CreatePullRequest( ctx context.Context, owner, repo, baseBranchName, headBranchName, title, body string, ) (*github.PullRequest, error) { - return &github.PullRequest{}, nil }