MCPcopy
hub / github.com/cli/cli / deleteRun

Function deleteRun

pkg/cmd/issue/delete/delete.go:76–117  ·  view source on GitHub ↗
(opts *DeleteOptions)

Source from the content-addressed store, hash-verified

74}
75
76func 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
119func apiDelete(httpClient *http.Client, repo ghrepo.Interface, issueID string) error {
120 var mutation struct {

Callers 1

NewCmdDeleteFunction · 0.70

Calls 13

FindIssueOrPRFunction · 0.92
FullNameFunction · 0.92
apiDeleteFunction · 0.85
ColorSchemeMethod · 0.80
CanPromptMethod · 0.80
WarningIconMethod · 0.80
IsStdoutTTYMethod · 0.80
RedMethod · 0.80
BaseRepoMethod · 0.65
ErrorfMethod · 0.65
PrintfMethod · 0.65
ConfirmDeletionMethod · 0.65

Tested by

no test coverage detected