diff --git a/api/client_test.go b/api/client_test.go index 4d7c64917..12bfbe408 100644 --- a/api/client_test.go +++ b/api/client_test.go @@ -2,7 +2,6 @@ package api import ( "bytes" - "fmt" "io/ioutil" "reflect" "testing" @@ -47,5 +46,7 @@ func TestGraphQLError(t *testing.T) { response := struct{}{} http.StubResponse(200, bytes.NewBufferString(`{"errors":[{"message":"OH NO"}]}`)) err := client.GraphQL("", nil, &response) - eq(t, err, fmt.Errorf("graphql error: 'OH NO'")) + if err == nil || err.Error() != "graphql error: 'OH NO'" { + t.Fatalf("got %q", err.Error()) + } } diff --git a/api/queries_pr.go b/api/queries_pr.go index 382d4255b..9b064cd9b 100644 --- a/api/queries_pr.go +++ b/api/queries_pr.go @@ -404,7 +404,7 @@ func PullRequestForBranch(client *Client, ghRepo Repo, branch string) (*PullRequ } // CreatePullRequest creates a pull request in a GitHub repository -func CreatePullRequest(client *Client, repo Repository, params map[string]interface{}) (*PullRequest, error) { +func CreatePullRequest(client *Client, repo *Repository, params map[string]interface{}) (*PullRequest, error) { query := ` mutation CreatePullRequest($input: CreatePullRequestInput!) { createPullRequest(input: $input) { diff --git a/command/pr_create.go b/command/pr_create.go index 48030bc20..f701081ab 100644 --- a/command/pr_create.go +++ b/command/pr_create.go @@ -61,8 +61,6 @@ func prCreate(cmd *cobra.Command, _ []string) error { return fmt.Errorf("must be on a branch named differently than %q", baseBranch) } - fmt.Fprintf(colorableErr(cmd), "\nCreating pull request for %s into %s in %s/%s\n\n", utils.Cyan(headBranch), utils.Cyan(baseBranch), baseRepo.RepoOwner(), baseRepo.RepoName()) - headRemote, err := repoContext.RemoteForRepo(headRepo) if err != nil { return errors.Wrap(err, "") @@ -86,6 +84,12 @@ func prCreate(cmd *cobra.Command, _ []string) error { return utils.OpenInBrowser(openURL) } + fmt.Fprintf(colorableErr(cmd), "\nCreating pull request for %s into %s in %s/%s\n\n", + utils.Cyan(headBranch), + utils.Cyan(baseBranch), + baseRepo.RepoOwner(), + baseRepo.RepoName()) + title, err := cmd.Flags().GetString("title") if err != nil { return errors.Wrap(err, "could not parse title") @@ -140,8 +144,7 @@ func prCreate(cmd *cobra.Command, _ []string) error { "headRefName": headBranch, } - repo := api.Repository{} - pr, err := api.CreatePullRequest(client, repo, params) + pr, err := api.CreatePullRequest(client, baseRepo, params) if err != nil { return errors.Wrap(err, "failed to create pull request") } @@ -261,7 +264,7 @@ func (r resolvedRemotes) BaseRepo() (*api.Repository, error) { func (r resolvedRemotes) HeadRepo() (*api.Repository, error) { for _, repo := range r.network.Repositories { if repo != nil && repo.ViewerCanPush() { - return repo.Parent, nil + return repo, nil } } return nil, errors.New("none of the repositories have push access") diff --git a/command/pr_create_test.go b/command/pr_create_test.go index 96ac2eb25..77539b16d 100644 --- a/command/pr_create_test.go +++ b/command/pr_create_test.go @@ -52,8 +52,15 @@ func TestPRCreate(t *testing.T) { http := initFakeHTTP() http.StubResponse(200, bytes.NewBufferString(` - { "data": { "repository": { - "id": "REPOID" + { "data": { "repo_000": { + "id": "REPOID", + "name": "REPO", + "owner": {"login": "OWNER"}, + "defaultBranchRef": { + "name": "master", + "target": {"oid": "deadbeef"} + }, + "viewerPermission": "WRITE" } } } `)) http.StubResponse(200, bytes.NewBufferString(` @@ -103,7 +110,20 @@ func TestPRCreate_web(t *testing.T) { initContext = func() context.Context { return ctx } - initFakeHTTP() + http := initFakeHTTP() + + http.StubResponse(200, bytes.NewBufferString(` + { "data": { "repo_000": { + "id": "REPOID", + "name": "REPO", + "owner": {"login": "OWNER"}, + "defaultBranchRef": { + "name": "master", + "target": {"oid": "deadbeef"} + }, + "viewerPermission": "WRITE" + } } } + `)) ranCommands := [][]string{} restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable { @@ -116,11 +136,7 @@ func TestPRCreate_web(t *testing.T) { eq(t, err, nil) eq(t, output.String(), "") - eq(t, output.Stderr(), ` -Creating pull request for feature into master in OWNER/REPO - -Opening https://github.com/OWNER/REPO/pull/feature in your browser. -`) + eq(t, output.Stderr(), "Opening https://github.com/OWNER/REPO/pull/feature in your browser.\n") eq(t, len(ranCommands), 3) eq(t, strings.Join(ranCommands[1], " "), "git push --set-upstream origin HEAD:feature") @@ -139,8 +155,15 @@ func TestPRCreate_ReportsUncommittedChanges(t *testing.T) { http := initFakeHTTP() http.StubResponse(200, bytes.NewBufferString(` - { "data": { "repository": { - "id": "REPOID" + { "data": { "repo_000": { + "id": "REPOID", + "name": "REPO", + "owner": {"login": "OWNER"}, + "defaultBranchRef": { + "name": "master", + "target": {"oid": "deadbeef"} + }, + "viewerPermission": "WRITE" } } } `)) http.StubResponse(200, bytes.NewBufferString(`