(opts *DeleteOptions)
| 74 | } |
| 75 | |
| 76 | func deleteRun(opts *DeleteOptions) error { |
| 77 | cs := opts.IO.ColorScheme() |
| 78 | |
| 79 | httpClient, err := opts.HttpClient() |
| 80 | if err != nil { |
| 81 | return err |
| 82 | } |
| 83 | |
| 84 | baseRepo, err := opts.BaseRepo() |
| 85 | if err != nil { |
| 86 | return err |
| 87 | } |
| 88 | |
| 89 | issue, err := shared.FindIssueOrPR(httpClient, baseRepo, opts.IssueNumber, []string{"id", "number", "title"}) |
| 90 | if err != nil { |
| 91 | return err |
| 92 | } |
| 93 | if issue.IsPullRequest() { |
| 94 | return fmt.Errorf("issue %s#%d is a pull request and cannot be deleted", ghrepo.FullName(baseRepo), issue.Number) |
| 95 | } |
| 96 | |
| 97 | // When executed in an interactive shell, require confirmation, unless |
| 98 | // already provided. Otherwise skip confirmation. |
| 99 | if opts.IO.CanPrompt() && !opts.Confirmed { |
| 100 | cs := opts.IO.ColorScheme() |
| 101 | fmt.Printf("%s Deleted issues cannot be recovered.\n", cs.WarningIcon()) |
| 102 | err := opts.Prompter.ConfirmDeletion(fmt.Sprintf("%d", issue.Number)) |
| 103 | if err != nil { |
| 104 | return err |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | if err := apiDelete(httpClient, baseRepo, issue.ID); err != nil { |
| 109 | return err |
| 110 | } |
| 111 | |
| 112 | if opts.IO.IsStdoutTTY() { |
| 113 | fmt.Fprintf(opts.IO.ErrOut, "%s Deleted issue %s#%d (%s).\n", cs.Red("✔"), ghrepo.FullName(baseRepo), issue.Number, issue.Title) |
| 114 | } |
| 115 | |
| 116 | return nil |
| 117 | } |
| 118 | |
| 119 | func apiDelete(httpClient *http.Client, repo ghrepo.Interface, issueID string) error { |
| 120 | var mutation struct { |
no test coverage detected