MCPcopy Create free account
hub / github.com/cli/cli / encodeContent

Function encodeContent

script/ghmock/restscaffold.go:302–321  ·  view source on GitHub ↗

encodeContent fixes file contents in GitHub's examples, which say they're base64 but hold plain text such as "encoded content ...". gh decodes them, so gh repo view fails on the README. It returns how many it fixed.

(v any)

Source from the content-addressed store, hash-verified

300// base64 but hold plain text such as "encoded content ...". gh decodes them,
301// so gh repo view fails on the README. It returns how many it fixed.
302func encodeContent(v any) int {
303 fixed := 0
304 switch v := v.(type) {
305 case map[string]any:
306 if content, ok := v["content"].(string); ok && v["encoding"] == "base64" {
307 if _, err := base64.StdEncoding.DecodeString(strings.ReplaceAll(content, "\n", "")); err != nil {
308 v["content"] = base64.StdEncoding.EncodeToString([]byte(content))
309 fixed++
310 }
311 }
312 for _, child := range v {
313 fixed += encodeContent(child)
314 }
315 case []any:
316 for _, child := range v {
317 fixed += encodeContent(child)
318 }
319 }
320 return fixed
321}
322
323func stringPlaceholder(format, name string) string {
324 switch format {

Callers 1

scaffoldMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected