MCPcopy Create free account
hub / github.com/cli/cli / deleteRun

Function deleteRun

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

Source from the content-addressed store, hash-verified

94}
95
96func deleteRun(opts *DeleteOptions) error {
97 repo, err := opts.BaseRepo()
98 if err != nil {
99 return err
100 }
101 if err := shared.CheckHost(repo.RepoHost()); err != nil {
102 return err
103 }
104
105 c, err := opts.Client()
106 if err != nil {
107 return err
108 }
109 if err := shared.CheckIssue(c, repo, opts.IssueNumber); err != nil {
110 return err
111 }
112
113 // Every number is looked up before anything is deleted: the prompt and the
114 // result lines name each artifact, and without --yes one failed lookup
115 // stops the command.
116 lookups := make([]lookup, 0, len(opts.ArtifactNumbers))
117 for _, number := range opts.ArtifactNumbers {
118 l := lookup{number: number}
119 a, err := c.Get(repo, opts.IssueNumber, number)
120 if err != nil {
121 l.err = err
122 } else {
123 l.name = text.RemoveExcessiveWhitespace(a.Name)
124 }
125 lookups = append(lookups, l)
126 }
127
128 issueRef := fmt.Sprintf("%s#%d", ghrepo.FullName(repo), opts.IssueNumber)
129 cs := opts.IO.ColorScheme()
130
131 if !opts.Confirmed {
132 hasLookupFailure := slices.ContainsFunc(lookups, func(l lookup) bool { return l.err != nil })
133 if hasLookupFailure {
134 for _, l := range lookups {
135 if l.err != nil {
136 printFailure(opts.IO, l.number, l.err)
137 }
138 }
139 fmt.Fprintln(opts.IO.ErrOut, "No artifacts were deleted.")
140 return cmdutil.SilentError
141 }
142
143 fmt.Fprintf(opts.IO.Out, "%s Deleted artifacts cannot be recovered.\n", cs.WarningIcon())
144 confirmed, err := opts.Prompter.Confirm(confirmationPrompt(lookups, issueRef), false)
145 if err != nil {
146 return err
147 }
148 if !confirmed {
149 return cmdutil.CancelError
150 }
151 }
152
153 failed := false

Callers 2

NewCmdDeleteFunction · 0.70
TestDeleteRunFunction · 0.70

Calls 15

CheckHostFunction · 0.92
CheckIssueFunction · 0.92
FullNameFunction · 0.92
printFailureFunction · 0.85
confirmationPromptFunction · 0.85
ColorSchemeMethod · 0.80
WarningIconMethod · 0.80
IsStdoutTTYMethod · 0.80
SuccessIconWithColorMethod · 0.80
BaseRepoMethod · 0.65
RepoHostMethod · 0.65

Tested by 1

TestDeleteRunFunction · 0.56