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

Function ResolveWorkflow

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

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

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

Tested by

no test coverage detected