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

Function ResolveWorkflow

pkg/cmd/workflow/shared/shared.go:200–241  ·  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

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