diff --git a/api/client.go b/api/client.go index 3fcf0d930..a3bf486ad 100644 --- a/api/client.go +++ b/api/client.go @@ -310,6 +310,7 @@ func (c Client) REST(hostname string, method string, p string, body io.Reader, d if err != nil { return err } + err = json.Unmarshal(b, &data) if err != nil { return err diff --git a/git/remote.go b/git/remote.go index 7a5890cb6..bea81da90 100644 --- a/git/remote.go +++ b/git/remote.go @@ -153,7 +153,6 @@ func AddRemote(name, u string) (*Remote, error) { } func UpdateRemoteURL(name, u string) error { - fmt.Println(name, u, "=====================name u==============") addCmd, err := GitCommand("remote", "set-url", name, u) if err != nil { return err diff --git a/pkg/cmd/repo/fork/fork_test.go b/pkg/cmd/repo/fork/fork_test.go index 775152440..4028ff929 100644 --- a/pkg/cmd/repo/fork/fork_test.go +++ b/pkg/cmd/repo/fork/fork_test.go @@ -132,6 +132,16 @@ func TestNewCmdFork(t *testing.T) { wantErr: true, errMsg: "unknown flag: --depth\nSeparate git clone flags with '--'.", }, + { + name: "with fork name", + cli: "--fork-name new-fork", + wants: ForkOptions{ + Remote: false, + RemoteName: "origin", + ForkName: "new-fork", + Rename: false, + }, + }, } for _, tt := range tests { @@ -529,6 +539,78 @@ func TestRepoFork(t *testing.T) { cs.Register(`git -C REPO remote add -f upstream https://github\.com/OWNER/REPO\.git`, 0, "") }, }, + { + name: "non tty repo arg with fork-name", + opts: &ForkOptions{ + Repository: "someone/REPO", + Clone: false, + ForkName: "NEW_REPO", + }, + tty: false, + httpStubs: func(reg *httpmock.Registry) { + forkResult := `{ + "node_id": "123", + "name": "REPO", + "clone_url": "https://github.com/OWNER/REPO.git", + "created_at": "2011-01-26T19:01:12Z", + "owner": { + "login": "OWNER" + } + }` + renameResult := `{ + "node_id": "1234", + "name": "NEW_REPO", + "clone_url": "https://github.com/OWNER/NEW_REPO.git", + "created_at": "2012-01-26T19:01:12Z", + "owner": { + "login": "OWNER" + } + }` + reg.Register( + httpmock.REST("POST", "repos/someone/REPO/forks"), + httpmock.StringResponse(forkResult)) + reg.Register( + httpmock.REST("PATCH", "repos/OWNER/REPO"), + httpmock.StringResponse(renameResult)) + }, + wantErrOut: "", + }, + { + name: "tty repo arg with fork-name", + opts: &ForkOptions{ + Repository: "someone/REPO", + Clone: false, + ForkName: "NEW_REPO", + }, + tty: true, + httpStubs: func(reg *httpmock.Registry) { + forkResult := `{ + "node_id": "123", + "name": "REPO", + "clone_url": "https://github.com/OWNER/REPO.git", + "created_at": "2011-01-26T19:01:12Z", + "owner": { + "login": "OWNER" + } + }` + renameResult := `{ + "node_id": "1234", + "name": "NEW_REPO", + "clone_url": "https://github.com/OWNER/NEW_REPO.git", + "created_at": "2012-01-26T19:01:12Z", + "owner": { + "login": "OWNER" + } + }` + reg.Register( + httpmock.REST("POST", "repos/someone/REPO/forks"), + httpmock.StringResponse(forkResult)) + reg.Register( + httpmock.REST("PATCH", "repos/OWNER/REPO"), + httpmock.StringResponse(renameResult)) + }, + wantErrOut: "✓ Created fork OWNER/NEW_REPO\n", + }, } for _, tt := range tests { diff --git a/pkg/cmd/repo/rename/rename.go b/pkg/cmd/repo/rename/rename.go index a0f6ee4bf..54747cff9 100644 --- a/pkg/cmd/repo/rename/rename.go +++ b/pkg/cmd/repo/rename/rename.go @@ -122,18 +122,18 @@ func renameRun(opts *RenameOptions) error { return err } + renamedRepo := ghrepo.New(newRepo.Owner.Login, newRepo.Name) + cs := opts.IO.ColorScheme() if opts.IO.IsStdoutTTY() { fmt.Fprintf(opts.IO.Out, "%s Renamed repository %s\n", cs.SuccessIcon(), ghrepo.FullName(newRepo)) } - fmt.Println(opts.HasRepoOverride, "=========erpo override=============") - if opts.HasRepoOverride { return nil } - remote, err := updateRemote(currRepo, newRepo, opts) + remote, err := updateRemote(currRepo, renamedRepo, opts) if err != nil { fmt.Fprintf(opts.IO.ErrOut, "%s Warning: unable to update remote %q: %v\n", cs.WarningIcon(), remote.Name, err) } else if opts.IO.IsStdoutTTY() { diff --git a/pkg/cmd/repo/rename/rename_test.go b/pkg/cmd/repo/rename/rename_test.go index 042579613..549abc731 100644 --- a/pkg/cmd/repo/rename/rename_test.go +++ b/pkg/cmd/repo/rename/rename_test.go @@ -122,7 +122,7 @@ func TestRenameRun(t *testing.T) { httpStubs: func(reg *httpmock.Registry) { reg.Register( httpmock.REST("PATCH", "repos/OWNER/REPO"), - httpmock.StatusStringResponse(204, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`)) + httpmock.StatusStringResponse(200, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`)) }, execStubs: func(cs *run.CommandStubber) { cs.Register(`git remote set-url origin https://github.com/OWNER/NEW_REPO.git`, 0, "") @@ -141,7 +141,7 @@ func TestRenameRun(t *testing.T) { httpStubs: func(reg *httpmock.Registry) { reg.Register( httpmock.REST("PATCH", "repos/OWNER/REPO"), - httpmock.StatusStringResponse(204, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`)) + httpmock.StatusStringResponse(200, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`)) }, tty: true, }, @@ -154,7 +154,7 @@ func TestRenameRun(t *testing.T) { httpStubs: func(reg *httpmock.Registry) { reg.Register( httpmock.REST("PATCH", "repos/OWNER/REPO"), - httpmock.StatusStringResponse(204, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`)) + httpmock.StatusStringResponse(200, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`)) }, execStubs: func(cs *run.CommandStubber) { cs.Register(`git remote set-url origin https://github.com/OWNER/NEW_REPO.git`, 0, "") @@ -169,7 +169,7 @@ func TestRenameRun(t *testing.T) { httpStubs: func(reg *httpmock.Registry) { reg.Register( httpmock.REST("PATCH", "repos/OWNER/REPO"), - httpmock.StatusStringResponse(204, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`)) + httpmock.StatusStringResponse(200, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`)) }, execStubs: func(cs *run.CommandStubber) { cs.Register(`git remote set-url origin https://github.com/OWNER/NEW_REPO.git`, 0, "") @@ -189,7 +189,7 @@ func TestRenameRun(t *testing.T) { httpStubs: func(reg *httpmock.Registry) { reg.Register( httpmock.REST("PATCH", "repos/OWNER/REPO"), - httpmock.StatusStringResponse(204, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`)) + httpmock.StatusStringResponse(200, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`)) }, execStubs: func(cs *run.CommandStubber) { cs.Register(`git remote set-url origin https://github.com/OWNER/NEW_REPO.git`, 0, "")