getRemoteWorkflowFiles fetches the list of workflow files from a remote repository
(repoSpec, workflowPath string, verbose bool, jsonOutput bool)
| 238 | |
| 239 | // getRemoteWorkflowFiles fetches the list of workflow files from a remote repository |
| 240 | func getRemoteWorkflowFiles(repoSpec, workflowPath string, verbose bool, jsonOutput bool) ([]string, error) { |
| 241 | listWorkflowsLog.Printf("Fetching remote workflow files: repoSpec=%s, path=%s", repoSpec, workflowPath) |
| 242 | // Parse repo spec: owner/repo[@ref] |
| 243 | var owner, repo, ref string |
| 244 | parts := strings.SplitN(repoSpec, "@", 2) |
| 245 | repoPart := parts[0] |
| 246 | if len(parts) == 2 { |
| 247 | ref = parts[1] |
| 248 | } else { |
| 249 | ref = "main" // default to main branch |
| 250 | } |
| 251 | |
| 252 | // Parse owner/repo |
| 253 | repoParts := strings.Split(repoPart, "/") |
| 254 | if len(repoParts) != 2 { |
| 255 | return nil, fmt.Errorf("invalid repository format: %s (expected owner/repo or owner/repo@ref)", repoSpec) |
| 256 | } |
| 257 | owner = repoParts[0] |
| 258 | repo = repoParts[1] |
| 259 | |
| 260 | if verbose && !jsonOutput { |
| 261 | fmt.Fprintf(os.Stderr, "Fetching workflow files from %s/%s@%s (path: %s)\n", owner, repo, ref, workflowPath) |
| 262 | } |
| 263 | |
| 264 | // Use the parser package to list workflow files |
| 265 | listWorkflowsLog.Printf("Listing remote workflow files: owner=%s, repo=%s, ref=%s, path=%s", owner, repo, ref, workflowPath) |
| 266 | files, err := parser.ListWorkflowFiles(owner, repo, ref, workflowPath) |
| 267 | if err != nil { |
| 268 | listWorkflowsLog.Printf("Failed to list remote workflow files: %v", err) |
| 269 | return nil, fmt.Errorf("failed to list workflow files from %s/%s: %w", owner, repo, err) |
| 270 | } |
| 271 | |
| 272 | listWorkflowsLog.Printf("Found %d remote workflow files", len(files)) |
| 273 | return files, nil |
| 274 | } |
no test coverage detected