(p iprompter, io *iostreams.IOStreams, client *api.Client, repo ghrepo.Interface, prompt bool, workflowSelector string, states []WorkflowState)
| 193 | } |
| 194 | |
| 195 | func 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 | |
| 239 | func 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) |
no test coverage detected