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

Function ResolveWorkflow

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

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