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)
| 806 | // ListSkillFiles returns all files in a skill directory as public SkillFile |
| 807 | // structs with paths relative to the skill root. |
| 808 | func ListSkillFiles(client *api.Client, host, owner, repo, treeSHA string) ([]SkillFile, error) { |
| 809 | apiPath := fmt.Sprintf("repos/%s/%s/git/trees/%s?recursive=true", url.PathEscape(owner), url.PathEscape(repo), url.PathEscape(treeSHA)) |
| 810 | var tree treeResponse |
| 811 | if err := client.REST(host, "GET", apiPath, nil, &tree); err != nil { |
| 812 | return nil, fmt.Errorf("could not fetch skill tree: %w", err) |
| 813 | } |
| 814 | |
| 815 | if tree.Truncated { |
| 816 | // Fall back to non-recursive traversal when the tree is too large. |
| 817 | return walkTree(client, host, owner, repo, treeSHA, "", 0) |
| 818 | } |
| 819 | |
| 820 | var files []SkillFile |
| 821 | for _, entry := range tree.Tree { |
| 822 | if entry.Type == "blob" { |
| 823 | files = append(files, SkillFile{ |
| 824 | Path: entry.Path, |
| 825 | SHA: entry.SHA, |
| 826 | Size: entry.Size, |
| 827 | }) |
| 828 | } |
| 829 | } |
| 830 | return files, nil |
| 831 | } |
| 832 | |
| 833 | // maxTreeDepth bounds the recursion in walkTree to prevent unbounded |
| 834 | // API calls on deeply nested repositories. |