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

Function runRun

pkg/cmd/workflow/run/run.go:258–395  ·  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 cachedClient := api.NewCachedHTTPClient(c, time.Hour*24)
272 opts.Detector = fd.NewDetector(cachedClient, repo.RepoHost())
273 }
274
275 ref := opts.Ref
276
277 if ref == "" {
278 ref, err = api.RepoDefaultBranch(client, repo)
279 if err != nil {
280 return fmt.Errorf("unable to determine default branch for %s: %w", ghrepo.FullName(repo), err)
281 }
282 }
283
284 states := []shared.WorkflowState{shared.Active}
285 workflow, err := shared.ResolveWorkflow(opts.Prompter,
286 opts.IO, client, repo, opts.Prompt, opts.Selector, states)
287 if err != nil {
288 var fae shared.FilteredAllError
289 if errors.As(err, &fae) {
290 return errors.New("no workflows are enabled on this repository")
291 }
292 return err
293 }
294
295 providedInputs := map[string]string{}
296
297 if len(opts.MagicFields)+len(opts.RawFields) > 0 {
298 providedInputs, err = parseFields(*opts)
299 if err != nil {
300 return err
301 }
302 } else if opts.JSONInput != "" {
303 err := json.Unmarshal([]byte(opts.JSONInput), &providedInputs)
304 if err != nil {
305 return fmt.Errorf("could not parse provided JSON: %w", err)
306 }
307 } else if opts.Prompt {
308 yamlContent, err := shared.GetWorkflowContent(client, repo, *workflow, ref)
309 if err != nil {
310 return fmt.Errorf("unable to fetch workflow file content: %w", err)
311 }
312 providedInputs, err = collectInputs(opts.Prompter, yamlContent)
313 if err != nil {
314 return err
315 }

Callers 2

NewCmdRunFunction · 0.85
TestRunFunction · 0.85

Calls 15

NewClientFromHTTPFunction · 0.92
NewCachedHTTPClientFunction · 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

Tested by 1

TestRunFunction · 0.68