MCPcopy Index your code
hub / github.com/cli/cli / ResolveWorkflow

Function ResolveWorkflow

pkg/cmd/workflow/shared/shared.go:192–233  ·  view source on GitHub ↗
(p iprompter, io *iostreams.IOStreams, client *api.Client, repo ghrepo.Interface, prompt bool, workflowSelector string, states []WorkflowState)

Source from the content-addressed store, hash-verified

190}
191
192func ResolveWorkflow(p iprompter, io *iostreams.IOStreams, client *api.Client, repo ghrepo.Interface, prompt bool, workflowSelector string, states []WorkflowState) (*Workflow, error) {
193 if prompt {
194 workflows, err := GetWorkflows(client, repo, 0)
195 if len(workflows) == 0 {
196 err = errors.New("no workflows are enabled")
197 }
198
199 if err != nil {
200 var httpErr api.HTTPError
201 if errors.As(err, &httpErr) && httpErr.StatusCode == 404 {
202 err = errors.New("no workflows are enabled")
203 }
204
205 return nil, fmt.Errorf("could not fetch workflows for %s: %w", ghrepo.FullName(repo), err)
206 }
207
208 return selectWorkflow(p, workflows, "Select a workflow", states)
209 }
210
211 workflows, err := FindWorkflow(client, repo, workflowSelector, states)
212 if err != nil {
213 return nil, err
214 }
215
216 if len(workflows) == 0 {
217 return nil, fmt.Errorf("could not find any workflows named %s", workflowSelector)
218 }
219
220 if len(workflows) == 1 {
221 return &workflows[0], nil
222 }
223
224 if !io.CanPrompt() {
225 errMsg := "could not resolve to a unique workflow; found:"
226 for _, workflow := range workflows {
227 errMsg += fmt.Sprintf(" %s", workflow.Base())
228 }
229 return nil, errors.New(errMsg)
230 }
231
232 return selectWorkflow(p, workflows, "Which workflow do you mean?", states)
233}
234
235func GetWorkflowContent(client *api.Client, repo ghrepo.Interface, workflow Workflow, ref string) ([]byte, error) {
236 path := fmt.Sprintf("repos/%s/contents/%s", ghrepo.FullName(repo), workflow.Path)

Callers 4

runDisableFunction · 0.92
runViewFunction · 0.92
runEnableFunction · 0.92
runRunFunction · 0.92

Calls 7

FullNameFunction · 0.92
GetWorkflowsFunction · 0.85
selectWorkflowFunction · 0.85
FindWorkflowFunction · 0.85
CanPromptMethod · 0.80
BaseMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected