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)
| 843 | // ListSkillFiles returns all files in a skill directory as public SkillFile |
| 844 | // structs with paths relative to the skill root. |
| 845 | func ListSkillFiles(client *api.Client, host, owner, repo, treeSHA string) ([]SkillFile, error) { |
| 846 | apiPath, err := safeurl.JoinPath("repos", owner, repo, "git", "trees", treeSHA) |
| 847 | if err != nil { |
| 848 | return nil, err |
| 849 | } |
| 850 | apiPath.SetQuery("recursive", "true") |
| 851 | var tree treeResponse |
| 852 | if err := client.REST(host, "GET", apiPath.String(), nil, &tree); err != nil { |
| 853 | return nil, fmt.Errorf("could not fetch skill tree: %w", err) |
| 854 | } |
| 855 | |
| 856 | if tree.Truncated { |
| 857 | // Fall back to non-recursive traversal when the tree is too large. |
| 858 | return walkTree(client, host, owner, repo, treeSHA, "", 0) |
| 859 | } |
| 860 | |
| 861 | var files []SkillFile |
| 862 | for _, entry := range tree.Tree { |
| 863 | if entry.Type == "blob" { |
| 864 | files = append(files, SkillFile{ |
| 865 | Path: entry.Path, |
| 866 | SHA: entry.SHA, |
| 867 | Size: entry.Size, |
| 868 | }) |
| 869 | } |
| 870 | } |
| 871 | return files, nil |
| 872 | } |
| 873 | |
| 874 | // maxTreeDepth bounds the recursion in walkTree to prevent unbounded |
| 875 | // API calls on deeply nested repositories. |