| 62 | } |
| 63 | |
| 64 | func runEnable(opts *EnableOptions) error { |
| 65 | c, err := opts.HttpClient() |
| 66 | if err != nil { |
| 67 | return fmt.Errorf("could not build http client: %w", err) |
| 68 | } |
| 69 | client := api.NewClientFromHTTP(c) |
| 70 | |
| 71 | repo, err := opts.BaseRepo() |
| 72 | if err != nil { |
| 73 | return err |
| 74 | } |
| 75 | |
| 76 | states := []shared.WorkflowState{shared.DisabledManually, shared.DisabledInactivity} |
| 77 | workflow, err := shared.ResolveWorkflow(opts.Prompter, |
| 78 | opts.IO, client, repo, opts.Prompt, opts.Selector, states) |
| 79 | if err != nil { |
| 80 | var fae shared.FilteredAllError |
| 81 | if errors.As(err, &fae) { |
| 82 | return errors.New("there are no disabled workflows to enable") |
| 83 | } |
| 84 | return err |
| 85 | } |
| 86 | |
| 87 | path := fmt.Sprintf("repos/%s/actions/workflows/%d/enable", ghrepo.FullName(repo), workflow.ID) |
| 88 | err = client.REST(repo.RepoHost(), "PUT", path, nil, nil) |
| 89 | if err != nil { |
| 90 | return fmt.Errorf("failed to enable workflow: %w", err) |
| 91 | } |
| 92 | |
| 93 | if opts.IO.CanPrompt() { |
| 94 | cs := opts.IO.ColorScheme() |
| 95 | fmt.Fprintf(opts.IO.Out, "%s Enabled %s\n", cs.SuccessIcon(), cs.Bold(workflow.Name)) |
| 96 | } |
| 97 | |
| 98 | return nil |
| 99 | } |