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