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)
| 124 | |
| 125 | // FindWorkflow looks up a workflow either by numeric database ID, file name, or its Name field |
| 126 | func 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 | |
| 149 | func GetWorkflow(client *api.Client, repo ghrepo.Interface, workflowID int64) (*Workflow, error) { |
| 150 | return getWorkflowByID(client, repo, strconv.FormatInt(workflowID, 10)) |