Skip to content

Commit 2d6c1e2

Browse files
committed
added a bunch of stuff
1 parent cd1eec5 commit 2d6c1e2

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

pkg/cmd/repo/rename/rename.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package rename
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
"strings"
7+
8+
"github.com/cli/cli/v2/api"
9+
"github.com/cli/cli/v2/internal/ghinstance"
10+
"github.com/cli/cli/v2/internal/ghrepo"
11+
"github.com/cli/cli/v2/pkg/cmdutil"
12+
"github.com/cli/cli/v2/pkg/iostreams"
13+
"github.com/spf13/cobra"
14+
)
15+
16+
type RenameOptions struct{
17+
HttpClient func() (*http.Client, error)
18+
IO *iostreams.IOStreams
19+
RepoName string
20+
}
21+
22+
func MewCmcRename(f *cmdutil.Factory, runf func(*RenameOptions) error) *cobra.Command {
23+
opts:= &RenameOptions {
24+
IO: f.IOStreams,
25+
HttpClient: f.HttpClient,
26+
}
27+
28+
cmd := &cobra.Command{
29+
Use: "rename <user/repo> <user/repo_change",
30+
Short: "Rename a repository",
31+
Long: "Rename a GitHub repository",
32+
Args: cmdutil.ExactArgs(2, "cannot rename: repository argument required"),
33+
RunE: func (cmd *cobra.Command, args []string) error {
34+
opts.RepoName = args[0]
35+
if runf != nil {
36+
return runf(opts)
37+
}
38+
return renameRun(opts)
39+
},
40+
}
41+
return cmd
42+
}
43+
44+
45+
func renameRun(opts *RenameOptions) error {
46+
cs := opts.IO.ColorScheme()
47+
httpClient, err := opts.HttpClient()
48+
if err != nil {
49+
return err
50+
}
51+
apiClient := api.NewClientFromHTTP(httpClient);
52+
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
63+
}
64+
65+
toRename, err = ghrepo.FromFullName(repoURL)
66+
if err != nil {
67+
return fmt.Errorf("argument error: %w", err)
68+
}
69+
70+
fields := []string{"name", "owner", "id"}
71+
72+
repo, err :=
73+
}

0 commit comments

Comments
 (0)