X Tutup
Skip to content

Commit 5d43302

Browse files
committed
simplify err handling and change flags
1 parent 9ea36de commit 5d43302

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

pkg/cmd/repo/delete/delete.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Co
3636
Long: `Delete a GitHub repository.
3737
3838
Deletion requires authorization with the "delete_repo" scope.
39-
To authorize, run "gh auth refresh -h github.com -s delete_repo"`,
39+
To authorize, run "gh auth refresh -s delete_repo"`,
4040
Args: cmdutil.ExactArgs(1, "cannot delete: repository argument required"),
4141
RunE: func(cmd *cobra.Command, args []string) error {
4242
opts.RepoArg = args[0]
@@ -47,7 +47,7 @@ To authorize, run "gh auth refresh -h github.com -s delete_repo"`,
4747
},
4848
}
4949

50-
cmd.Flags().BoolVar(&opts.Confirmed, "yes", false, "confirm deletion without prompting")
50+
cmd.Flags().BoolVarP(&opts.Confirmed, "confirm", "c", false, "confirm deletion without prompting")
5151
return cmd
5252
}
5353

@@ -77,7 +77,7 @@ func deleteRun(opts *DeleteOptions) error {
7777

7878
doPrompt := opts.IO.CanPrompt()
7979
if !opts.Confirmed && !doPrompt {
80-
return errors.New("could not prompt: confirmation with prompt or --yes flag required")
80+
return errors.New("could not prompt: confirmation with prompt or --confirm flag required")
8181
}
8282

8383
if !opts.Confirmed && doPrompt {

pkg/cmd/repo/delete/delete_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ func Test_deleteRun(t *testing.T) {
2727
opts: &DeleteOptions{RepoArg: "OWNER/REPO"},
2828
wantStdout: "✓ Deleted repository OWNER/REPO\n",
2929
askStubs: func(q *prompt.AskStubber) {
30-
q.StubOne("NOTOWNER/NOTREPO") // this always passes??
30+
// TODO: survey stubber doesn't have WithValidation support
31+
// so this always passes regardless of prompt input
32+
q.StubOne("OWNER/REPO")
3133
},
3234
httpStubs: func(reg *httpmock.Registry) {
3335
reg.Register(
@@ -51,7 +53,7 @@ func Test_deleteRun(t *testing.T) {
5153
name: "no confirmation no tty",
5254
opts: &DeleteOptions{RepoArg: "OWNER/REPO"},
5355
wantErr: true,
54-
errMsg: "could not prompt: confirmation with prompt or --yes flag required",
56+
errMsg: "could not prompt: confirmation with prompt or --confirm flag required",
5557
},
5658
}
5759
for _, tt := range tests {

pkg/cmd/repo/delete/http.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ func deleteRepo(client *http.Client, repo ghrepo.Interface) error {
1515
ghrepo.FullName(repo))
1616

1717
request, err := http.NewRequest("DELETE", url, nil)
18-
request.Header.Set("Accept", "application/vnd.github.v3+json")
1918
if err != nil {
2019
return err
2120
}
@@ -26,13 +25,8 @@ func deleteRepo(client *http.Client, repo ghrepo.Interface) error {
2625
}
2726
defer resp.Body.Close()
2827

29-
err = api.HandleHTTPError(resp)
30-
if resp.StatusCode == 403 {
31-
return fmt.Errorf(`%w
32-
33-
Deletion requires authorization with the "delete_repo" scope. To authorize, run "gh auth refresh -s delete_repo"`, err)
34-
} else if resp.StatusCode > 204 {
35-
return err
28+
if resp.StatusCode > 299 {
29+
return api.HandleHTTPError(resp)
3630
}
3731

3832
return nil

0 commit comments

Comments
 (0)
X Tutup