-
Notifications
You must be signed in to change notification settings - Fork 3
[slack plugin] Accept a real template file for filepath #1071
Copy link
Copy link
Open
Labels
area/pluginIndicates a change to a pluginIndicates a change to a pluginenhancementIndicates an improvement to a featureIndicates an improvement to a feature
Description
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)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area/pluginIndicates a change to a pluginIndicates a change to a pluginenhancementIndicates an improvement to a featureIndicates an improvement to a feature