Skip to content

[slack plugin] Accept a real template file for filepath #1071

@colindean

Description

@colindean

Description

I periodically experience JSON interpolation problems, wherein a branch name or commit message contains a quotation mark or something else invalid in JSON when interpolated unsafely.

{
  "attachments": [
    {
      "color": "#36a64f",
      "pretext": "*Event*: {{.BuildEvent}}",
      "text": "*Status*: SUCCESS\n*Repo*: {{ .RepositoryName }} | *Branch*: {{ .BuildBranch }} | *Author*: {{ .BuildAuthor }}\n*Build*: {{ .BuildLink }}\n*Message*: {{ .BuildMessage }}"
    }
  ]
}

I wrote up this Gotemplate to generate JSON thinking that it would work, because, well, the template above has Gotemplate-syntax placeholders, right?

{{- $root := dict -}}
{{- $text := print "*Status*: SUCCESS\n*Repo*: " .RepositoryName " | *Branch*: " .BuildBranch " | *Author*: " .BuildAuthor "\n*Build*: " .BuildLink "\n*Message*: " .BuildMessage -}}
{{- $pretext := print "*Event*: " .BuildEvent -}}
{{- $msg := dict "color" "#36a64f" "pretext" $pretext "text" $text -}}
{{- $_ := set $root "attachments" (list $msg) -}}
{{- $root | toJson -}}

I was wrong. It doesn't… It seems to expect JSON.

Value

It would be lovely to maintain these templates with something other than Gotemplates inside of JSON. That's a hard proposition.

Definition of Done

  • filepath can be a Gotemplate that produces JSON
  • Optional: filepath can be a Starlark template that emits a JSON-able dict

Effort (Optional)

I'd wager probably 3–4 hrs inclusive of testing.

Impacted Personas (Optional)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/pluginIndicates a change to a pluginenhancementIndicates an improvement to a feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions