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

Function runCancel

pkg/cmd/run/cancel/cancel.go:66–141  ·  view source on GitHub ↗
(opts *CancelOptions)

Source from the content-addressed store, hash-verified

64}
65
66func runCancel(opts *CancelOptions) error {
67 if opts.RunID != "" {
68 _, err := strconv.Atoi(opts.RunID)
69 if err != nil {
70 return fmt.Errorf("invalid run-id %#v", opts.RunID)
71 }
72 }
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 runs, err := shared.GetRunsWithFilter(client, repo, nil, 10, func(run shared.Run) bool {
91 return run.Status != shared.Completed
92 })
93 if err != nil {
94 return fmt.Errorf("failed to get runs: %w", err)
95 }
96 if len(runs) == 0 {
97 return fmt.Errorf("found no in progress runs to cancel")
98 }
99 if runID, err = shared.SelectRun(opts.Prompter, cs, runs); err != nil {
100 return err
101 }
102 // TODO silly stopgap until dust settles and SelectRun can just return a run
103 for _, r := range runs {
104 if fmt.Sprintf("%d", r.ID) == runID {
105 run = &r
106 break
107 }
108 }
109 } else {
110 run, err = shared.GetRun(client, repo, runID, 0)
111 if err != nil {
112 if httpErr, ok := errors.AsType[api.HTTPError](err); ok {
113 if httpErr.StatusCode == http.StatusNotFound {
114 err = fmt.Errorf("Could not find any workflow run with ID %s", opts.RunID)
115 }
116 }
117 return err
118 }
119 }
120
121 force := opts.Force
122
123 err = cancelWorkflowRun(client, repo, fmt.Sprintf("%d", run.ID), force)

Callers 2

TestRunCancelFunction · 0.85
NewCmdCancelFunction · 0.85

Calls 9

NewClientFromHTTPFunction · 0.92
GetRunsWithFilterFunction · 0.92
SelectRunFunction · 0.92
GetRunFunction · 0.92
cancelWorkflowRunFunction · 0.85
ColorSchemeMethod · 0.80
SuccessIconMethod · 0.80
ErrorfMethod · 0.65
BaseRepoMethod · 0.65

Tested by 1

TestRunCancelFunction · 0.68