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

Function FindWorkflow

pkg/cmd/workflow/shared/shared.go:129–149  ·  view source on GitHub ↗

FindWorkflow looks up a workflow either by numeric database ID, file name, or its Name field

(client *api.Client, repo ghrepo.Interface, workflowSelector string, states []WorkflowState)

Source from the content-addressed store, hash-verified

127
128// FindWorkflow looks up a workflow either by numeric database ID, file name, or its Name field
129func FindWorkflow(client *api.Client, repo ghrepo.Interface, workflowSelector string, states []WorkflowState) ([]Workflow, error) {
130 if workflowSelector == "" {
131 return nil, errors.New("empty workflow selector")
132 }
133
134 if _, err := strconv.Atoi(workflowSelector); err == nil || isWorkflowFile(workflowSelector) {
135 workflow, err := getWorkflowByID(client, repo, workflowSelector)
136 if err != nil {
137 if httpErr, ok := errors.AsType[api.HTTPError](err); ok {
138 if httpErr.StatusCode == 404 {
139 httpErr.Message = fmt.Sprintf("workflow %s not found on the default branch", workflowSelector)
140 }
141 return nil, httpErr
142 }
143 return nil, err
144 }
145 return []Workflow{*workflow}, nil
146 }
147
148 return getWorkflowsByName(client, repo, workflowSelector, states)
149}
150
151func GetWorkflow(client *api.Client, repo ghrepo.Interface, workflowID int64) (*Workflow, error) {
152 return getWorkflowByID(client, repo, strconv.FormatInt(workflowID, 10))

Callers 3

TestFindWorkflowFunction · 0.85
ResolveWorkflowFunction · 0.85

Calls 3

isWorkflowFileFunction · 0.85
getWorkflowByIDFunction · 0.85
getWorkflowsByNameFunction · 0.85

Tested by 2

TestFindWorkflowFunction · 0.68