(owner, repo, ref, workflowPath, host string)
| 1038 | } |
| 1039 | |
| 1040 | func listWorkflowFilesForHost(owner, repo, ref, workflowPath, host string) ([]string, error) { |
| 1041 | remoteLog.Printf("Listing workflow files for %s/%s@%s (path: %s)", owner, repo, ref, workflowPath) |
| 1042 | |
| 1043 | client, err := createRESTClientForHost(host) |
| 1044 | if err != nil { |
| 1045 | remoteLog.Printf("Failed to create REST client, attempting git fallback: %v", err) |
| 1046 | return listWorkflowFilesViaGitForHost(owner, repo, ref, workflowPath, host) |
| 1047 | } |
| 1048 | |
| 1049 | // Define response struct for GitHub contents API (array of file objects) |
| 1050 | var contents []struct { |
| 1051 | Name string `json:"name"` |
| 1052 | Path string `json:"path"` |
| 1053 | Type string `json:"type"` |
| 1054 | } |
| 1055 | |
| 1056 | // Fetch directory contents from GitHub API |
| 1057 | endpoint := buildContentsAPIPath(owner, repo, workflowPath, ref) |
| 1058 | err = client.Get(endpoint, &contents) |
| 1059 | if err != nil { |
| 1060 | errStr := err.Error() |
| 1061 | |
| 1062 | // Check if this is an authentication error |
| 1063 | if gitutil.IsAuthError(errStr) { |
| 1064 | remoteLog.Printf("GitHub API authentication failed, attempting git fallback for %s/%s@%s", owner, repo, ref) |
| 1065 | // Try fallback using git commands for public repositories |
| 1066 | files, gitErr := listWorkflowFilesViaGitForHost(owner, repo, ref, workflowPath, host) |
| 1067 | if gitErr != nil { |
| 1068 | if host == "" || host == "github.com" { |
| 1069 | remoteLog.Printf("Git fallback also failed, attempting unauthenticated API for %s/%s@%s", owner, repo, ref) |
| 1070 | return listWorkflowFilesViaPublicAPI(context.Background(), owner, repo, ref, workflowPath) |
| 1071 | } |
| 1072 | return nil, fmt.Errorf("failed to list workflow files via GitHub API (auth error) and git fallback: API error: %w, Git error: %w", err, gitErr) |
| 1073 | } |
| 1074 | return files, nil |
| 1075 | } |
| 1076 | |
| 1077 | return nil, fmt.Errorf("failed to list workflow files from %s/%s@%s (path: %s): %w", owner, repo, ref, workflowPath, err) |
| 1078 | } |
| 1079 | |
| 1080 | // Filter to only .md files (not in subdirectories) |
| 1081 | var workflowFiles []string |
| 1082 | for _, item := range contents { |
| 1083 | if item.Type == "file" && strings.HasSuffix(strings.ToLower(item.Name), ".md") { |
| 1084 | workflowFiles = append(workflowFiles, item.Path) |
| 1085 | } |
| 1086 | } |
| 1087 | |
| 1088 | remoteLog.Printf("Found %d workflow files in %s/%s@%s (path: %s)", len(workflowFiles), owner, repo, ref, workflowPath) |
| 1089 | return workflowFiles, nil |
| 1090 | } |
| 1091 | |
| 1092 | // ListDirAllFilesForHost lists all files (any extension) that are direct children of |
| 1093 | // the given directory in a remote GitHub repository. Subdirectories and their contents |
no test coverage detected