MCPcopy Index your code
hub / github.com/cli/cli / runDelete

Function runDelete

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

Source from the content-addressed store, hash-verified

70}
71
72func runDelete(opts *DeleteOptions) error {
73 httpClient, err := opts.HttpClient()
74 if err != nil {
75 return fmt.Errorf("failed to create http client: %w", err)
76 }
77 client := api.NewClientFromHTTP(httpClient)
78
79 cs := opts.IO.ColorScheme()
80
81 repo, err := opts.BaseRepo()
82 if err != nil {
83 return fmt.Errorf("failed to determine base repo: %w", err)
84 }
85
86 runID := opts.RunID
87 var run *shared.Run
88
89 if opts.Prompt {
90 payload, err := shared.GetRuns(client, repo, nil, defaultRunGetLimit)
91 if err != nil {
92 return fmt.Errorf("failed to get runs: %w", err)
93 }
94
95 runs := payload.WorkflowRuns
96 if len(runs) == 0 {
97 return fmt.Errorf("found no runs to delete")
98 }
99
100 runID, err = shared.SelectRun(opts.Prompter, cs, runs)
101 if err != nil {
102 return err
103 }
104
105 for _, r := range runs {
106 if fmt.Sprintf("%d", r.ID) == runID {
107 run = &r
108 break
109 }
110 }
111 } else {
112 run, err = shared.GetRun(client, repo, runID, 0)
113 if err != nil {
114 var httpErr api.HTTPError
115 if errors.As(err, &httpErr) {
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 var httpErr api.HTTPError
127 if errors.As(err, &httpErr) {
128 if httpErr.StatusCode == http.StatusConflict {
129 err = fmt.Errorf("cannot delete a workflow run that is completed")

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