Hugo

Having trouble unmarshalling yaml from Github API (content)

I am using getJSON with the GitHub API to document info from some of our public repos. We maintain a lot of our example projects through a single repository, where each example repo has its own subdirectory within it (acting as an upstream to update individual example repos).

My goal: I want to place requests against the central repo, and pull information from each of example repos contained within it. Specifically, there is a single yaml content file (that is base64 encoded by GitHub) I want to request, decode, then parse, but I’m having trouble parsing at the end.

As an example, here is our template Hugo project within that central repo, and here is the endpoint for the file in that repo I am trying to get information from.

The file content is base64 encoded, so I would think the steps here would be

  • getJSON
  • base64Decode
  • transform.Unmarshal

Here’s my code:

# Retrieves  the list of subdirectories
{{ $results := getJSON "https://api.github.com/repos/platformsh/template-builder/contents/templates" }}

  {{ range $results }}  # ranges through all template projects
    {{ if ne .name "__init__.py" }} # only request subdirectories that contain templates
      {{ $info := ( printf "https://api.github.com/repos/platformsh/template-builder/contents/templates/%s/.platform.template.yaml" .name ) }}
      {{ $info = getJSON $info }}
      {{ $info = $info.content | base64Decode }}
      {{ $info = $info | transform.Unmarshal }}

      {{ $info }}

    {{ end }}
  {{ end }}

I’m getting variations on the following error:

ERROR 2020/01/06 08:43:01 Rebuild failed:

ERROR 2020/01/06 08:43:01 "/Users/chadcarlson/Documents/work/docs/themes/platformsh-docs/content/english/development/templates.md:12:1": failed to render shortcode "repolist": failed to process shortcode: "/Users/chadcarlson/Documents/work/docs/themes/platformsh-docs/themes/avocado/layouts/shortcodes/repolist.html:14:34": execute of template failed: template: shortcodes/repolist.html:14:34: executing "shortcodes/repolist.html" at <transform.Unmarshal>: error calling Unmarshal: record on line 11: wrong number of fields

Placing requests on other files in these subdirectories (i.e. https://github.com/platformsh/template-builder/blob/master/templates/hugo/files/.platform.app.yaml) doesn’t seem to have the same issue, but the code is identical.

It’s not clear to me what this error means from the docs, anybody else run into this issue unmarshalling yaml, maybe even with the Github api?

Thanks

What is the rough structure of content after it’s decoded?

For the hugo example, this is the file https://github.com/platformsh/template-builder/blob/master/templates/hugo/.platform.template.yaml