From cfa5a9c574b78a14ed35a3ece3ba19616a72af9c Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Thu, 4 Mar 2021 13:24:45 +0000 Subject: [PATCH] Phrase the message template example as YAML not go The message template is used in YAML files, not in go code. I've also explained up-front that it's a text template -- something not mentioned to this point. Signed-off-by: Michael Bridgen --- docs/spec/v1alpha1/imageupdateautomations.md | 53 +++++++++++--------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/docs/spec/v1alpha1/imageupdateautomations.md b/docs/spec/v1alpha1/imageupdateautomations.md index 6fe31da..02c23f4 100644 --- a/docs/spec/v1alpha1/imageupdateautomations.md +++ b/docs/spec/v1alpha1/imageupdateautomations.md @@ -143,9 +143,9 @@ spec: will result in commits with the author `Fluxbot `. -The `messageTemplate` field is a string which will be used as the commit message. If empty, there is -a default message; but you will likely want to provide your own, especially if you want to put -tokens in to control how CI reacts to commits made by automation. For example, +The `messageTemplate` field is a string which will be used as a template for the commit message. If +empty, there is a default message; but you will likely want to provide your own, especially if you +want to put tokens in to control how CI reacts to commits made by automation. For example, ```yaml spec: @@ -158,7 +158,8 @@ spec: ### Commit template data -The data available to the commit message template have this structure (not reproduced verbatim): +The message template is a [Go text template][go-text-template]. The data available to the template +have this structure (not reproduced verbatim): ```go // controllers/imageupdateautomation_controller.go @@ -231,27 +232,28 @@ func (r Result) Objects() map[ObjectIdentifier][]ImageRef { The methods let you range over the objects and images without descending the data structure. Here's an example of using the fields and methods in a template: -```go -commitTemplate := ` -`Automated image update - -Automation name: {{ .AutomationObject }} - -Files: -{{ range $filename, $_ := .Updated.Files -}} -- {{ $filename }} -{{ end -}} - -Objects: -{{ range $resource, $_ := .Updated.Objects -}} -- {{ $resource.Kind }} {{ $resource.Name }} -{{ end -}} - -Images: -{{ range .Updated.Images -}} -- {{.}} -{{ end -}} -` +```yaml +spec: + commit: + messsageTemplate: | + Automated image update + + Automation name: {{ .AutomationObject }} + + Files: + {{ range $filename, $_ := .Updated.Files -}} + - {{ $filename }} + {{ end -}} + + Objects: + {{ range $resource, $_ := .Updated.Objects -}} + - {{ $resource.Kind }} {{ $resource.Name }} + {{ end -}} + + Images: + {{ range .Updated.Images -}} + - {{.}} + {{ end -}} ``` ## Status @@ -295,3 +297,4 @@ resulted in a commit. [git-repo-ref]: https://toolkit.fluxcd.io/components/source/gitrepositories/ [durations]: https://godoc.org/time#ParseDuration [source-docs]: https://toolkit.fluxcd.io/components/source/gitrepositories/#git-implementation +[go-text-template]: https://golang.org/pkg/text/template/