listWorkflowFilesViaPublicAPI lists workflow .md files using an unauthenticated call to the public GitHub API. Used as a last-resort fallback when both authenticated API and git clone fail.
(ctx context.Context, owner, repo, ref, workflowPath string)
| 1521 | // call to the public GitHub API. Used as a last-resort fallback when both |
| 1522 | // authenticated API and git clone fail. |
| 1523 | func listWorkflowFilesViaPublicAPI(ctx context.Context, owner, repo, ref, workflowPath string) ([]string, error) { |
| 1524 | remoteLog.Printf("Attempting unauthenticated public API for listing workflow files: %s/%s@%s (path: %s)", owner, repo, ref, workflowPath) |
| 1525 | body, err := fetchPublicGitHubContentsAPI(ctx, owner, repo, workflowPath, ref) |
| 1526 | if err != nil { |
| 1527 | return nil, fmt.Errorf("unauthenticated public API also failed for %s/%s@%s (path: %s): %w", owner, repo, ref, workflowPath, err) |
| 1528 | } |
| 1529 | |
| 1530 | var contents []struct { |
| 1531 | Name string `json:"name"` |
| 1532 | Path string `json:"path"` |
| 1533 | Type string `json:"type"` |
| 1534 | } |
| 1535 | if err := json.Unmarshal(body, &contents); err != nil { |
| 1536 | return nil, fmt.Errorf("failed to parse public API response: %w", err) |
| 1537 | } |
| 1538 | |
| 1539 | var workflowFiles []string |
| 1540 | for _, item := range contents { |
| 1541 | if item.Type == "file" && strings.HasSuffix(strings.ToLower(item.Name), ".md") { |
| 1542 | workflowFiles = append(workflowFiles, item.Path) |
| 1543 | } |
| 1544 | } |
| 1545 | remoteLog.Printf("Found %d workflow files via public API for %s/%s@%s (path: %s)", len(workflowFiles), owner, repo, ref, workflowPath) |
| 1546 | return workflowFiles, nil |
| 1547 | } |
no test coverage detected