FetchBlob retrieves the content of a blob by SHA. The blob is base64-encoded inside the JSON response and decoded here, so it is returned as iostreams.Untrusted and callers must choose sanitized display or raw round-tripping.
(client *api.Client, host, owner, repo, sha string)
| 945 | // iostreams.Untrusted and callers must choose sanitized display or raw |
| 946 | // round-tripping. |
| 947 | func FetchBlob(client *api.Client, host, owner, repo, sha string) (iostreams.Untrusted, error) { |
| 948 | apiPath, err := safeurl.JoinPath("repos", owner, repo, "git", "blobs", sha) |
| 949 | if err != nil { |
| 950 | return iostreams.Untrusted{}, err |
| 951 | } |
| 952 | var resp struct { |
| 953 | SHA string `json:"sha"` |
| 954 | Content string `json:"content"` |
| 955 | Encoding string `json:"encoding"` |
| 956 | } |
| 957 | if err := client.REST(host, "GET", apiPath.String(), nil, &resp); err != nil { |
| 958 | return iostreams.Untrusted{}, fmt.Errorf("could not fetch blob: %w", err) |
| 959 | } |
| 960 | |
| 961 | if resp.Encoding != "base64" { |
| 962 | return iostreams.Untrusted{}, fmt.Errorf("unexpected blob encoding: %s", resp.Encoding) |
| 963 | } |
| 964 | |
| 965 | // GitHub API returns base64 with embedded newlines; use the StdEncoding |
| 966 | // decoder via a reader to handle them transparently. |
| 967 | decoded, err := io.ReadAll(base64.NewDecoder(base64.StdEncoding, strings.NewReader(resp.Content))) |
| 968 | if err != nil { |
| 969 | return iostreams.Untrusted{}, fmt.Errorf("could not decode blob content: %w", err) |
| 970 | } |
| 971 | |
| 972 | return iostreams.NewUntrustedBytes(decoded), nil |
| 973 | } |
| 974 | |
| 975 | // DiscoverLocalSkills finds non-hidden-dir skills in a local directory using |
| 976 | // the same conventions as remote discovery. Hidden-dir skills are excluded; use |