@@ -3,10 +3,15 @@ package rename
33import (
44 "fmt"
55 "net/http"
6- "strings"
6+
7+ // "strings"
78
89 "github.com/cli/cli/v2/api"
10+ "github.com/cli/cli/v2/internal/config"
911 "github.com/cli/cli/v2/internal/ghinstance"
12+
13+ // "github.com/cli/cli/v2/internal/ghinstance"
14+
1015 "github.com/cli/cli/v2/internal/ghrepo"
1116 "github.com/cli/cli/v2/pkg/cmdutil"
1217 "github.com/cli/cli/v2/pkg/iostreams"
@@ -16,20 +21,23 @@ import (
1621type RenameOptions struct {
1722 HttpClient func () (* http.Client , error )
1823 IO * iostreams.IOStreams
24+ Config func () (config.Config , error )
1925 RepoName string
2026}
2127
22- func MewCmcRename (f * cmdutil.Factory , runf func (* RenameOptions ) error ) * cobra.Command {
28+ func NewCmdRename (f * cmdutil.Factory , runf func (* RenameOptions ) error ) * cobra.Command {
2329 opts := & RenameOptions {
2430 IO : f .IOStreams ,
2531 HttpClient : f .HttpClient ,
2632 }
2733
2834 cmd := & cobra.Command {
29- Use : "rename <user/repo> <user/repo_change" ,
35+ DisableFlagsInUseLine : true ,
36+
37+ Use : "rename <user/repo_name>" ,
3038 Short : "Rename a repository" ,
3139 Long : "Rename a GitHub repository" ,
32- Args : cmdutil .ExactArgs (2 , "cannot rename: repository argument required" ),
40+ Args : cmdutil .ExactArgs (1 , "cannot rename: repository argument required" ),
3341 RunE : func (cmd * cobra.Command , args []string ) error {
3442 opts .RepoName = args [0 ]
3543 if runf != nil {
@@ -43,31 +51,32 @@ func MewCmcRename(f *cmdutil.Factory, runf func(*RenameOptions) error) *cobra.Co
4351
4452
4553func renameRun (opts * RenameOptions ) error {
46- cs := opts .IO .ColorScheme ()
54+ // cs := opts.IO.ColorScheme()
4755 httpClient , err := opts .HttpClient ()
4856 if err != nil {
4957 return err
5058 }
5159 apiClient := api .NewClientFromHTTP (httpClient );
5260
53- var toRename ghrepo.Interface
54-
55- repoURL := opts .RepoName
56-
57- if ! strings .Contains (repoURL , "/" ) {
58- currentUser , err := api .CurrentLoginName (apiClient , ghinstance .Default ())
59- if err != nil {
60- return err
61- }
62- repoURL = currentUser + "/" + repoURL
61+ username , err := api .CurrentLoginName (apiClient , ghinstance .Default ())
62+ if err != nil {
63+ return err
6364 }
6465
65- toRename , err = ghrepo .FromFullName (repoURL )
66+ toRename , err : = ghrepo .FromFullName (opts . RepoName )
6667 if err != nil {
6768 return fmt .Errorf ("argument error: %w" , err )
6869 }
6970
7071 fields := []string {"name" , "owner" , "id" }
72+ repo , err := api .FetchRepository (apiClient , toRename , fields )
73+ if err != nil {
74+ return err
75+ }
76+
77+ if username != repo .Owner .Login {
78+ return fmt .Errorf ("you do not own this repository" );
79+ }
7180
72- repo , err :=
81+ return nil
7382}
0 commit comments