ListSkillFiles returns all files in a skill directory as public SkillFile structs with paths relative to the skill root.
(client *api.Client, host, owner, repo, treeSHA string)
| 872 | // ListSkillFiles returns all files in a skill directory as public SkillFile |
| 873 | // structs with paths relative to the skill root. |
| 874 | func ListSkillFiles(client *api.Client, host, owner, repo, treeSHA string) ([]SkillFile, error) { |
| 875 | apiPath, err := safeurl.JoinPath("repos", owner, repo, "git", "trees", treeSHA) |
| 876 | if err != nil { |
| 877 | return nil, err |
| 878 | } |
| 879 | apiPath.SetQuery("recursive", "true") |
| 880 | var tree treeResponse |
| 881 | if err := client.REST(host, "GET", apiPath.String(), nil, &tree); err != nil { |
| 882 | return nil, fmt.Errorf("could not fetch skill tree: %w", err) |
| 883 | } |
| 884 | |
| 885 | if tree.Truncated { |
| 886 | // Fall back to non-recursive traversal when the tree is too large. |
| 887 | return walkTree(client, host, owner, repo, treeSHA, "", 0) |
| 888 | } |
| 889 | |
| 890 | var files []SkillFile |
| 891 | for _, entry := range tree.Tree { |
| 892 | if entry.Type == "blob" { |
| 893 | files = append(files, SkillFile{ |
| 894 | Path: entry.Path, |
| 895 | SHA: entry.SHA, |
| 896 | Size: entry.Size, |
| 897 | }) |
| 898 | } |
| 899 | } |
| 900 | return files, nil |
| 901 | } |
| 902 | |
| 903 | // maxTreeDepth bounds the recursion in walkTree to prevent unbounded |
| 904 | // API calls on deeply nested repositories. |