DiscoverSkillFiles returns all file paths belonging to a skill directory by fetching the skill's subtree directly using its tree SHA.
(client *api.Client, host, owner, repo, treeSHA, skillPath string)
| 811 | // DiscoverSkillFiles returns all file paths belonging to a skill directory |
| 812 | // by fetching the skill's subtree directly using its tree SHA. |
| 813 | func DiscoverSkillFiles(client *api.Client, host, owner, repo, treeSHA, skillPath string) ([]SkillFile, error) { |
| 814 | apiPath, err := safeurl.JoinPath("repos", owner, repo, "git", "trees", treeSHA) |
| 815 | if err != nil { |
| 816 | return nil, err |
| 817 | } |
| 818 | apiPath.SetQuery("recursive", "true") |
| 819 | var tree treeResponse |
| 820 | if err := client.REST(host, "GET", apiPath.String(), nil, &tree); err != nil { |
| 821 | return nil, fmt.Errorf("could not fetch skill tree: %w", err) |
| 822 | } |
| 823 | |
| 824 | if tree.Truncated { |
| 825 | // Recursive fetch was truncated. Fall back to walking subtrees individually. |
| 826 | return walkTree(client, host, owner, repo, treeSHA, skillPath, 0) |
| 827 | } |
| 828 | |
| 829 | var files []SkillFile |
| 830 | for _, entry := range tree.Tree { |
| 831 | if entry.Type == "blob" { |
| 832 | files = append(files, SkillFile{ |
| 833 | Path: skillPath + "/" + entry.Path, |
| 834 | SHA: entry.SHA, |
| 835 | Size: entry.Size, |
| 836 | }) |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | return files, nil |
| 841 | } |
| 842 | |
| 843 | // ListSkillFiles returns all files in a skill directory as public SkillFile |
| 844 | // structs with paths relative to the skill root. |