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

Function listContentsRecursivelyWithDepth

pkg/parser/remote_fetch.go:1249–1279  ·  view source on GitHub ↗
(client *api.RESTClient, owner, repo, ref, dirPath string, depth, maxDepth int)

Source from the content-addressed store, hash-verified

1247}
1248
1249func listContentsRecursivelyWithDepth(client *api.RESTClient, owner, repo, ref, dirPath string, depth, maxDepth int) ([]string, error) {
1250 if depth > maxDepth {
1251 return nil, fmt.Errorf("maximum skill directory recursion depth exceeded at %q (max depth: %d)", dirPath, maxDepth)
1252 }
1253
1254 var contents []struct {
1255 Name string `json:"name"`
1256 Path string `json:"path"`
1257 Type string `json:"type"`
1258 }
1259
1260 endpoint := buildContentsAPIPath(owner, repo, dirPath, ref)
1261 if err := client.Get(endpoint, &contents); err != nil {
1262 return nil, fmt.Errorf("failed to list dir files from %s/%s (path: %s): %w", owner, repo, dirPath, err)
1263 }
1264
1265 var files []string
1266 for _, item := range contents {
1267 switch item.Type {
1268 case "file":
1269 files = append(files, item.Path)
1270 case "dir":
1271 subFiles, err := listContentsRecursivelyWithDepth(client, owner, repo, ref, item.Path, depth+1, maxDepth)
1272 if err != nil {
1273 return nil, err
1274 }
1275 files = append(files, subFiles...)
1276 }
1277 }
1278 return files, nil
1279}
1280
1281func listDirAllFilesRecursivelyViaGitForHost(owner, repo, ref, dirPath, host string) ([]string, error) {
1282 remoteLog.Printf("Git fallback for listing all dir files recursively: %s/%s@%s (path: %s)", owner, repo, ref, dirPath)

Calls 3

buildContentsAPIPathFunction · 0.85
ErrorfMethod · 0.45
GetMethod · 0.45