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

Function runCancel

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

Source from the content-addressed store, hash-verified

63}
64
65func runCancel(opts *CancelOptions) error {
66 if opts.RunID != "" {
67 _, err := strconv.Atoi(opts.RunID)
68 if err != nil {
69 return fmt.Errorf("invalid run-id %#v", opts.RunID)
70 }
71 }
72 httpClient, err := opts.HttpClient()
73 if err != nil {
74 return fmt.Errorf("failed to create http client: %w", err)
75 }
76 client := api.NewClientFromHTTP(httpClient)
77
78 cs := opts.IO.ColorScheme()
79
80 repo, err := opts.BaseRepo()
81 if err != nil {
82 return fmt.Errorf("failed to determine base repo: %w", err)
83 }
84
85 runID := opts.RunID
86 var run *shared.Run
87
88 if opts.Prompt {
89 runs, err := shared.GetRunsWithFilter(client, repo, nil, 10, func(run shared.Run) bool {
90 return run.Status != shared.Completed
91 })
92 if err != nil {
93 return fmt.Errorf("failed to get runs: %w", err)
94 }
95 if len(runs) == 0 {
96 return fmt.Errorf("found no in progress runs to cancel")
97 }
98 if runID, err = shared.SelectRun(opts.Prompter, cs, runs); err != nil {
99 return err
100 }
101 // TODO silly stopgap until dust settles and SelectRun can just return a run
102 for _, r := range runs {
103 if fmt.Sprintf("%d", r.ID) == runID {
104 run = &r
105 break
106 }
107 }
108 } else {
109 run, err = shared.GetRun(client, repo, runID, 0)
110 if err != nil {
111 var httpErr api.HTTPError
112 if errors.As(err, &httpErr) {
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

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