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)
| 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. |
| 302 | func 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 | |
| 323 | func stringPlaceholder(format, name string) string { |
| 324 | switch format { |