optimize command

This commit is contained in:
Parth Patel 2021-10-12 18:56:32 -04:00
parent 3a936f65e2
commit 4afd1e06bf
2 changed files with 10 additions and 39 deletions

View file

@ -77,12 +77,11 @@ func renameRun(opts *RenameOptions) error {
if err != nil {
return fmt.Errorf("argument error: %w", err)
}
fields := []string{"name", "owner", "id"}
repoDetails, err := api.FetchRepository(apiClient, repo, fields)
if err != nil {
return err
}
// fields := []string{"name", "owner", "id"}
// repoDetails, err := api.FetchRepository(apiClient, repo, fields)
// if err != nil {
// return err
// }
input := renameRepo{
Owner: repo.RepoOwner(),
@ -90,7 +89,7 @@ func renameRun(opts *RenameOptions) error {
Name: newRepoName,
}
err = runRename(apiClient, repo.RepoHost(), repoDetails, input)
err = runRename(apiClient, repo.RepoHost(), input)
if err != nil {
return fmt.Errorf("API called failed: %s, please check your parameters", err.Error())
}
@ -102,8 +101,8 @@ func renameRun(opts *RenameOptions) error {
return nil
}
func runRename(apiClient *api.Client, hostname string, repoDetails *api.Repository, input renameRepo) error {
path := fmt.Sprintf("repos/%s/%s", repoDetails.Owner.Login, repoDetails.Name)
func runRename(apiClient *api.Client, hostname string, input renameRepo) error {
path := fmt.Sprintf("repos/%s/%s", input.Owner, input.Repository)
body := &bytes.Buffer{}
enc := json.NewEncoder(body)

View file

@ -85,20 +85,6 @@ func TestRenameRun(t *testing.T) {
},
wantOut: "✓ Renamed repository OWNER/NEW_REPO\n",
httpStubs: func(reg *httpmock.Registry) {
reg.Register(
httpmock.GraphQL(`query RepositoryInfo\b`),
httpmock.StringResponse(`
{
"data": {
"repository": {
"id": "THE-ID",
"name": "REPO",
"owner": {
"login": "OWNER"
}
}
}
}`))
reg.Register(
httpmock.REST("PATCH", "repos/OWNER/REPO"),
httpmock.StatusStringResponse(204, "{}"))
@ -108,26 +94,12 @@ func TestRenameRun(t *testing.T) {
{
name: "owner repo change name notty",
opts: RenameOptions{
oldRepoName: "OWNER/REPO",
oldRepoName: "NON_OWNER/REPO",
newRepoName: "NEW_REPO",
},
httpStubs: func(reg *httpmock.Registry) {
reg.Register(
httpmock.GraphQL(`query RepositoryInfo\b`),
httpmock.StringResponse(`
{
"data": {
"repository": {
"id": "THE-ID",
"name": "REPO",
"owner": {
"login": "OWNER"
}
}
}
}`))
reg.Register(
httpmock.REST("PATCH", "repos/OWNER/REPO"),
httpmock.REST("PATCH", "repos/NON_OWNER/REPO"),
httpmock.StatusStringResponse(200, "{}"))
},
stdoutTTY: false,