MCPcopy
hub / github.com/cli/cli / FindWorkflow

Function FindWorkflow

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

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