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)
| 840 | // DiscoverSkillFiles returns all file paths belonging to a skill directory |
| 841 | // by fetching the skill's subtree directly using its tree SHA. |
| 842 | func DiscoverSkillFiles(client *api.Client, host, owner, repo, treeSHA, skillPath string) ([]SkillFile, error) { |
| 843 | apiPath, err := safeurl.JoinPath("repos", owner, repo, "git", "trees", treeSHA) |
| 844 | if err != nil { |
| 845 | return nil, err |
| 846 | } |
| 847 | apiPath.SetQuery("recursive", "true") |
| 848 | var tree treeResponse |
| 849 | if err := client.REST(host, "GET", apiPath.String(), nil, &tree); err != nil { |
| 850 | return nil, fmt.Errorf("could not fetch skill tree: %w", err) |
| 851 | } |
| 852 | |
| 853 | if tree.Truncated { |
| 854 | // Recursive fetch was truncated. Fall back to walking subtrees individually. |
| 855 | return walkTree(client, host, owner, repo, treeSHA, skillPath, 0) |
| 856 | } |
| 857 | |
| 858 | var files []SkillFile |
| 859 | for _, entry := range tree.Tree { |
| 860 | if entry.Type == "blob" { |
| 861 | files = append(files, SkillFile{ |
| 862 | Path: skillPath + "/" + entry.Path, |
| 863 | SHA: entry.SHA, |
| 864 | Size: entry.Size, |
| 865 | }) |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | return files, nil |
| 870 | } |
| 871 | |
| 872 | // ListSkillFiles returns all files in a skill directory as public SkillFile |
| 873 | // structs with paths relative to the skill root. |