MCPcopy Create free account
hub / github.com/github/gh-aw / listWorkflowFilesViaPublicAPI

Function listWorkflowFilesViaPublicAPI

pkg/parser/remote_fetch.go:1523–1547  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1521// call to the public GitHub API. Used as a last-resort fallback when both
1522// authenticated API and git clone fail.
1523func 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}

Callers 1

listWorkflowFilesForHostFunction · 0.85

Calls 4

ToLowerMethod · 0.80
PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected