Skip to content

Commit e6e8d72

Browse files
committed
added full functionality
1 parent 7725116 commit e6e8d72

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

pkg/cmd/repo/rename/rename.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77
"net/http"
8+
"strings"
89

910
"github.com/cli/cli/v2/api"
1011
"github.com/cli/cli/v2/internal/config"
@@ -37,7 +38,7 @@ func NewCmdRename(f *cmdutil.Factory, runf func(*RenameOptions) error) *cobra.Co
3738
cmd := &cobra.Command{
3839
DisableFlagsInUseLine: true,
3940

40-
Use: "rename <user/repo_name> <user/new_repo_name>",
41+
Use: "rename <old_repo_name> <new_repo_name>",
4142
Short: "Rename a repository",
4243
Long: "Rename a GitHub repository",
4344
Args: cmdutil.ExactArgs(2, "cannot rename: repository argument required"),
@@ -53,21 +54,24 @@ func NewCmdRename(f *cmdutil.Factory, runf func(*RenameOptions) error) *cobra.Co
5354
}
5455

5556
func renameRun(opts *RenameOptions) error {
56-
oldRepoName := opts.RepoName[0]
57-
newRepoName := opts.RepoName[1]
58-
59-
// cs := opts.IO.ColorScheme()
57+
cs := opts.IO.ColorScheme()
6058
httpClient, err := opts.HttpClient()
6159
if err != nil {
6260
return err
6361
}
6462
apiClient := api.NewClientFromHTTP(httpClient)
6563

66-
username, err := api.CurrentLoginName(apiClient, ghinstance.Default())
64+
currentUser, err := api.CurrentLoginName(apiClient, ghinstance.Default())
6765
if err != nil {
6866
return err
6967
}
7068

69+
oldRepoName := opts.RepoName[0]
70+
if !strings.Contains(oldRepoName, "/") {
71+
oldRepoName = currentUser + "/" + oldRepoName
72+
}
73+
newRepoName := opts.RepoName[1]
74+
7175
repo, err := ghrepo.FromFullName(oldRepoName)
7276
if err != nil {
7377
return fmt.Errorf("argument error: %w", err)
@@ -79,7 +83,7 @@ func renameRun(opts *RenameOptions) error {
7983
return err
8084
}
8185

82-
if username != repoDetails.Owner.Login {
86+
if currentUser != repoDetails.Owner.Login {
8387
return fmt.Errorf("you do not own this repository")
8488
}
8589

@@ -94,7 +98,9 @@ func renameRun(opts *RenameOptions) error {
9498
return err
9599
}
96100

97-
101+
if opts.IO.IsStdoutTTY() {
102+
fmt.Fprintf(opts.IO.Out, "%s Renamed repository %s\n", cs.SuccessIcon(), currentUser + "/" + newRepoName)
103+
}
98104

99105
return nil
100106
}

0 commit comments

Comments
 (0)