Skip to content

Commit

Permalink
Add CreatePullRequest() to github pkg and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
puerco committed May 8, 2020
1 parent e600636 commit 276d710
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
22 changes: 15 additions & 7 deletions pkg/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}
15 changes: 15 additions & 0 deletions pkg/github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
10 changes: 10 additions & 0 deletions pkg/github/githubfakes/fake_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pkg/github/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 0 additions & 1 deletion pkg/github/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 276d710

Please sign in to comment.