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 <michael@weave.works>
This commit is contained in:
Michael Bridgen 2021-03-04 13:24:45 +00:00
parent 2eebaa46c7
commit cfa5a9c574
1 changed files with 28 additions and 25 deletions

View File

@ -143,9 +143,9 @@ spec:
will result in commits with the author `Fluxbot <flux@example.com>`. will result in commits with the author `Fluxbot <flux@example.com>`.
The `messageTemplate` field is a string which will be used as the commit message. If empty, there is The `messageTemplate` field is a string which will be used as a template for the commit message. If
a default message; but you will likely want to provide your own, especially if you want to put empty, there is a default message; but you will likely want to provide your own, especially if you
tokens in to control how CI reacts to commits made by automation. For example, want to put tokens in to control how CI reacts to commits made by automation. For example,
```yaml ```yaml
spec: spec:
@ -158,7 +158,8 @@ spec:
### Commit template data ### 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 ```go
// controllers/imageupdateautomation_controller.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 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: an example of using the fields and methods in a template:
```go ```yaml
commitTemplate := ` spec:
`Automated image update commit:
messsageTemplate: |
Automated image update
Automation name: {{ .AutomationObject }} Automation name: {{ .AutomationObject }}
Files: Files:
{{ range $filename, $_ := .Updated.Files -}} {{ range $filename, $_ := .Updated.Files -}}
- {{ $filename }} - {{ $filename }}
{{ end -}} {{ end -}}
Objects: Objects:
{{ range $resource, $_ := .Updated.Objects -}} {{ range $resource, $_ := .Updated.Objects -}}
- {{ $resource.Kind }} {{ $resource.Name }} - {{ $resource.Kind }} {{ $resource.Name }}
{{ end -}} {{ end -}}
Images: Images:
{{ range .Updated.Images -}} {{ range .Updated.Images -}}
- {{.}} - {{.}}
{{ end -}} {{ end -}}
`
``` ```
## Status ## Status
@ -295,3 +297,4 @@ resulted in a commit.
[git-repo-ref]: https://toolkit.fluxcd.io/components/source/gitrepositories/ [git-repo-ref]: https://toolkit.fluxcd.io/components/source/gitrepositories/
[durations]: https://godoc.org/time#ParseDuration [durations]: https://godoc.org/time#ParseDuration
[source-docs]: https://toolkit.fluxcd.io/components/source/gitrepositories/#git-implementation [source-docs]: https://toolkit.fluxcd.io/components/source/gitrepositories/#git-implementation
[go-text-template]: https://golang.org/pkg/text/template/