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

Function runDelete

pkg/cmd/run/delete/delete.go:73–137  ·  view source on GitHub ↗
(opts *DeleteOptions)

Source from the content-addressed store, hash-verified

71}
72
73func runDelete(opts *DeleteOptions) error {
74 httpClient, err := opts.HttpClient()
75 if err != nil {
76 return fmt.Errorf("failed to create http client: %w", err)
77 }
78 client := api.NewClientFromHTTP(httpClient)
79
80 cs := opts.IO.ColorScheme()
81
82 repo, err := opts.BaseRepo()
83 if err != nil {
84 return fmt.Errorf("failed to determine base repo: %w", err)
85 }
86
87 runID := opts.RunID
88 var run *shared.Run
89
90 if opts.Prompt {
91 payload, err := shared.GetRuns(client, repo, nil, defaultRunGetLimit)
92 if err != nil {
93 return fmt.Errorf("failed to get runs: %w", err)
94 }
95
96 runs := payload.WorkflowRuns
97 if len(runs) == 0 {
98 return fmt.Errorf("found no runs to delete")
99 }
100
101 runID, err = shared.SelectRun(opts.Prompter, cs, runs)
102 if err != nil {
103 return err
104 }
105
106 for _, r := range runs {
107 if fmt.Sprintf("%d", r.ID) == runID {
108 run = &r
109 break
110 }
111 }
112 } else {
113 run, err = shared.GetRun(client, repo, runID, 0)
114 if err != nil {
115 if httpErr, ok := errors.AsType[api.HTTPError](err); ok {
116 if httpErr.StatusCode == http.StatusNotFound {
117 err = fmt.Errorf("could not find any workflow run with ID %s", opts.RunID)
118 }
119 }
120 return err
121 }
122 }
123
124 err = deleteWorkflowRun(client, repo, fmt.Sprintf("%d", run.ID))
125 if err != nil {
126 if httpErr, ok := errors.AsType[api.HTTPError](err); ok {
127 if httpErr.StatusCode == http.StatusConflict {
128 err = fmt.Errorf("cannot delete a workflow run that is completed")
129 }
130 }

Callers 2

NewCmdDeleteFunction · 0.70
TestRunDeleteFunction · 0.70

Calls 9

NewClientFromHTTPFunction · 0.92
GetRunsFunction · 0.92
SelectRunFunction · 0.92
GetRunFunction · 0.92
deleteWorkflowRunFunction · 0.85
ColorSchemeMethod · 0.80
SuccessIconMethod · 0.80
ErrorfMethod · 0.65
BaseRepoMethod · 0.65

Tested by 1

TestRunDeleteFunction · 0.56