| 255 | } |
| 256 | |
| 257 | func runRun(opts *RunOptions) error { |
| 258 | c, err := opts.HttpClient() |
| 259 | if err != nil { |
| 260 | return fmt.Errorf("could not build http client: %w", err) |
| 261 | } |
| 262 | client := api.NewClientFromHTTP(c) |
| 263 | |
| 264 | repo, err := opts.BaseRepo() |
| 265 | if err != nil { |
| 266 | return err |
| 267 | } |
| 268 | |
| 269 | if opts.Detector == nil { |
| 270 | cachedClient := api.NewCachedHTTPClient(c, time.Hour*24) |
| 271 | opts.Detector = fd.NewDetector(cachedClient, repo.RepoHost()) |
| 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 | var fae shared.FilteredAllError |
| 288 | if errors.As(err, &fae) { |
| 289 | return errors.New("no workflows are enabled on this repository") |
| 290 | } |
| 291 | return err |
| 292 | } |
| 293 | |
| 294 | providedInputs := map[string]string{} |
| 295 | |
| 296 | if len(opts.MagicFields)+len(opts.RawFields) > 0 { |
| 297 | providedInputs, err = parseFields(*opts) |
| 298 | if err != nil { |
| 299 | return err |
| 300 | } |
| 301 | } else if opts.JSONInput != "" { |
| 302 | err := json.Unmarshal([]byte(opts.JSONInput), &providedInputs) |
| 303 | if err != nil { |
| 304 | return fmt.Errorf("could not parse provided JSON: %w", err) |
| 305 | } |
| 306 | } else if opts.Prompt { |
| 307 | yamlContent, err := shared.GetWorkflowContent(client, repo, *workflow, ref) |
| 308 | if err != nil { |
| 309 | return fmt.Errorf("unable to fetch workflow file content: %w", err) |
| 310 | } |
| 311 | providedInputs, err = collectInputs(opts.Prompter, yamlContent) |
| 312 | if err != nil { |
| 313 | return err |
| 314 | } |