MCPcopy Index your code
hub / github.com/cli/cli / ListSkillFiles

Function ListSkillFiles

internal/skills/discovery/discovery.go:808–831  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

806// ListSkillFiles returns all files in a skill directory as public SkillFile
807// structs with paths relative to the skill root.
808func 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.

Callers 2

previewRunFunction · 0.92
TestListSkillFilesFunction · 0.85

Calls 3

walkTreeFunction · 0.85
RESTMethod · 0.65
ErrorfMethod · 0.65

Tested by 1

TestListSkillFilesFunction · 0.68