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

Function runEnable

pkg/cmd/workflow/enable/enable.go:66–103  ·  view source on GitHub ↗
(opts *EnableOptions)

Source from the content-addressed store, hash-verified

64}
65
66func 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 if _, ok := errors.AsType[shared.FilteredAllError](err); ok {
83 return errors.New("there are no disabled workflows to enable")
84 }
85 return err
86 }
87
88 path, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "actions", "workflows", strconv.FormatInt(workflow.ID, 10), "enable")
89 if err != nil {
90 return err
91 }
92 err = client.REST(repo.RepoHost(), "PUT", path.String(), nil, nil)
93 if err != nil {
94 return fmt.Errorf("failed to enable workflow: %w", err)
95 }
96
97 if opts.IO.CanPrompt() {
98 cs := opts.IO.ColorScheme()
99 fmt.Fprintf(opts.IO.Out, "%s Enabled %s\n", cs.SuccessIcon(), cs.Bold(workflow.Name))
100 }
101
102 return nil
103}

Callers 2

NewCmdEnableFunction · 0.85
TestEnableRunFunction · 0.85

Calls 14

NewClientFromHTTPFunction · 0.92
ResolveWorkflowFunction · 0.92
JoinPathFunction · 0.92
CanPromptMethod · 0.80
ColorSchemeMethod · 0.80
SuccessIconMethod · 0.80
BoldMethod · 0.80
ErrorfMethod · 0.65
BaseRepoMethod · 0.65
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RESTMethod · 0.65

Tested by 1

TestEnableRunFunction · 0.68