Skip to content

Commit 4afd1e0

Browse files
committed
optimize command
1 parent 3a936f6 commit 4afd1e0

File tree

2 files changed

+10
-39
lines changed

2 files changed

+10
-39
lines changed

pkg/cmd/repo/rename/rename.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,19 @@ func renameRun(opts *RenameOptions) error {
7777
if err != nil {
7878
return fmt.Errorf("argument error: %w", err)
7979
}
80-
81-
fields := []string{"name", "owner", "id"}
82-
repoDetails, err := api.FetchRepository(apiClient, repo, fields)
83-
if err != nil {
84-
return err
85-
}
80+
// fields := []string{"name", "owner", "id"}
81+
// repoDetails, err := api.FetchRepository(apiClient, repo, fields)
82+
// if err != nil {
83+
// return err
84+
// }
8685

8786
input := renameRepo{
8887
Owner: repo.RepoOwner(),
8988
Repository: repo.RepoName(),
9089
Name: newRepoName,
9190
}
9291

93-
err = runRename(apiClient, repo.RepoHost(), repoDetails, input)
92+
err = runRename(apiClient, repo.RepoHost(), input)
9493
if err != nil {
9594
return fmt.Errorf("API called failed: %s, please check your parameters", err.Error())
9695
}
@@ -102,8 +101,8 @@ func renameRun(opts *RenameOptions) error {
102101
return nil
103102
}
104103

105-
func runRename(apiClient *api.Client, hostname string, repoDetails *api.Repository, input renameRepo) error {
106-
path := fmt.Sprintf("repos/%s/%s", repoDetails.Owner.Login, repoDetails.Name)
104+
func runRename(apiClient *api.Client, hostname string, input renameRepo) error {
105+
path := fmt.Sprintf("repos/%s/%s", input.Owner, input.Repository)
107106

108107
body := &bytes.Buffer{}
109108
enc := json.NewEncoder(body)

pkg/cmd/repo/rename/rename_test.go

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,6 @@ func TestRenameRun(t *testing.T) {
8585
},
8686
wantOut: "✓ Renamed repository OWNER/NEW_REPO\n",
8787
httpStubs: func(reg *httpmock.Registry) {
88-
reg.Register(
89-
httpmock.GraphQL(`query RepositoryInfo\b`),
90-
httpmock.StringResponse(`
91-
{
92-
"data": {
93-
"repository": {
94-
"id": "THE-ID",
95-
"name": "REPO",
96-
"owner": {
97-
"login": "OWNER"
98-
}
99-
}
100-
}
101-
}`))
10288
reg.Register(
10389
httpmock.REST("PATCH", "repos/OWNER/REPO"),
10490
httpmock.StatusStringResponse(204, "{}"))
@@ -108,26 +94,12 @@ func TestRenameRun(t *testing.T) {
10894
{
10995
name: "owner repo change name notty",
11096
opts: RenameOptions{
111-
oldRepoName: "OWNER/REPO",
97+
oldRepoName: "NON_OWNER/REPO",
11298
newRepoName: "NEW_REPO",
11399
},
114100
httpStubs: func(reg *httpmock.Registry) {
115101
reg.Register(
116-
httpmock.GraphQL(`query RepositoryInfo\b`),
117-
httpmock.StringResponse(`
118-
{
119-
"data": {
120-
"repository": {
121-
"id": "THE-ID",
122-
"name": "REPO",
123-
"owner": {
124-
"login": "OWNER"
125-
}
126-
}
127-
}
128-
}`))
129-
reg.Register(
130-
httpmock.REST("PATCH", "repos/OWNER/REPO"),
102+
httpmock.REST("PATCH", "repos/NON_OWNER/REPO"),
131103
httpmock.StatusStringResponse(200, "{}"))
132104
},
133105
stdoutTTY: false,

0 commit comments

Comments
 (0)