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

Function runRun

pkg/cmd/workflow/run/run.go:258–393  ·  view source on GitHub ↗
(opts *RunOptions)

Source from the content-addressed store, hash-verified

256}
257
258func runRun(opts *RunOptions) error {
259 c, err := opts.HttpClient()
260 if err != nil {
261 return fmt.Errorf("could not build http client: %w", err)
262 }
263 client := api.NewClientFromHTTP(c)
264
265 repo, err := opts.BaseRepo()
266 if err != nil {
267 return err
268 }
269
270 if opts.Detector == nil {
271 opts.Detector = fd.NewCachedDetector(c, repo.RepoHost(), time.Hour*24)
272 }
273
274 ref := opts.Ref
275
276 if ref == "" {
277 ref, err = api.RepoDefaultBranch(client, repo)
278 if err != nil {
279 return fmt.Errorf("unable to determine default branch for %s: %w", ghrepo.FullName(repo), err)
280 }
281 }
282
283 states := []shared.WorkflowState{shared.Active}
284 workflow, err := shared.ResolveWorkflow(opts.Prompter,
285 opts.IO, client, repo, opts.Prompt, opts.Selector, states)
286 if err != nil {
287 if _, ok := errors.AsType[shared.FilteredAllError](err); ok {
288 return errors.New("no workflows are enabled on this repository")
289 }
290 return err
291 }
292
293 providedInputs := map[string]string{}
294
295 if len(opts.MagicFields)+len(opts.RawFields) > 0 {
296 providedInputs, err = parseFields(*opts)
297 if err != nil {
298 return err
299 }
300 } else if opts.JSONInput != "" {
301 err := json.Unmarshal([]byte(opts.JSONInput), &providedInputs)
302 if err != nil {
303 return fmt.Errorf("could not parse provided JSON: %w", err)
304 }
305 } else if opts.Prompt {
306 yamlContent, err := shared.GetWorkflowContent(client, repo, *workflow, ref)
307 if err != nil {
308 return fmt.Errorf("unable to fetch workflow file content: %w", err)
309 }
310 providedInputs, err = collectInputs(opts.Prompter, yamlContent)
311 if err != nil {
312 return err
313 }
314 }
315

Callers 2

NewCmdRunFunction · 0.85
TestRunFunction · 0.85

Calls 15

NewClientFromHTTPFunction · 0.92
RepoDefaultBranchFunction · 0.92
FullNameFunction · 0.92
ResolveWorkflowFunction · 0.92
GetWorkflowContentFunction · 0.92
JoinPathFunction · 0.92
collectInputsFunction · 0.85
IsStdoutTTYMethod · 0.80
ColorSchemeMethod · 0.80
SuccessIconMethod · 0.80
CyanMethod · 0.80
BaseMethod · 0.80

Tested by 1

TestRunFunction · 0.68