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

Function runEnable

pkg/cmd/workflow/enable/enable.go:66–104  ·  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 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}

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