Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ba877df

Browse files
committedOct 21, 2024·
Additional values for commit message template
This adds .spec.git.commit.messageTemplateValues as a map of strings that can be used to supplement the rendering of the commit message template. Signed-off-by: Kevin McDermott <bigkevmcd@gmail.com>
1 parent 3ff8476 commit ba877df

File tree

6 files changed

+68
-0
lines changed

6 files changed

+68
-0
lines changed
 

‎api/v1beta2/git.go

+4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ type CommitSpec struct {
6767
// into which will be interpolated the details of the change made.
6868
// +optional
6969
MessageTemplate string `json:"messageTemplate,omitempty"`
70+
71+
// MessageTemplateValues provides additional values to be available to the
72+
// templating rendering.
73+
MessageTemplateValues map[string]string `json:"messageTemplateValues,omitempty"`
7074
}
7175

7276
type CommitUser struct {

‎api/v1beta2/zz_generated.deepcopy.go

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎config/crd/bases/image.toolkit.fluxcd.io_imageupdateautomations.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,13 @@ spec:
427427
MessageTemplate provides a template for the commit message,
428428
into which will be interpolated the details of the change made.
429429
type: string
430+
messageTemplateValues:
431+
additionalProperties:
432+
type: string
433+
description: |-
434+
MessageTemplateValues provides additional values to be available to the
435+
templating rendering.
436+
type: object
430437
signingKey:
431438
description: SigningKey provides the option to sign commits
432439
with a GPG key

‎docs/api/v1beta2/image-automation.md

+12
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ string
7070
into which will be interpolated the details of the change made.</p>
7171
</td>
7272
</tr>
73+
<tr>
74+
<td>
75+
<code>messageTemplateValues</code><br>
76+
<em>
77+
map[string]string
78+
</em>
79+
</td>
80+
<td>
81+
<p>MessageTemplateValues provides additional values to be available to the
82+
templating rendering.</p>
83+
</td>
84+
</tr>
7385
</tbody>
7486
</table>
7587
</div>

‎internal/source/source.go

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type TemplateData struct {
5454
AutomationObject types.NamespacedName
5555
Updated update.Result
5656
Changed update.ResultV2
57+
Values map[string]string
5758
}
5859

5960
// SourceManager manages source.
@@ -245,6 +246,7 @@ func (sm SourceManager) CommitAndPush(ctx context.Context, obj *imagev1.ImageUpd
245246
AutomationObject: sm.automationObjKey,
246247
Updated: policyResult.ImageResult,
247248
Changed: policyResult,
249+
Values: obj.Spec.GitSpec.Commit.MessageTemplateValues,
248250
}
249251
commitMsg, err := templateMsg(obj.Spec.GitSpec.Commit.MessageTemplate, templateValues)
250252
if err != nil {

‎internal/source/source_test.go

+36
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ Automation: {{ .AutomationObject }}
9393
{{ end -}}
9494
{{ end -}}
9595
{{ end -}}
96+
`
97+
98+
testCommitTemplateWithValues = `Commit summary
99+
100+
Automation: {{ .AutomationObject }}
101+
102+
Cluster: {{ index .Values "cluster" }}
103+
Testing: {{ .Values.testing }}
96104
`
97105
)
98106

@@ -472,6 +480,34 @@ Automation: test-ns/test-update
472480
- helloworld:1.0.0 -> helloworld:1.0.1
473481
`,
474482
},
483+
{
484+
name: "push to cloned branch with template and values",
485+
gitSpec: &imagev1.GitSpec{
486+
Push: &imagev1.PushSpec{
487+
Branch: "main",
488+
},
489+
Commit: imagev1.CommitSpec{
490+
MessageTemplate: testCommitTemplateWithValues,
491+
MessageTemplateValues: map[string]string{
492+
"cluster": "prod",
493+
"testing": "value",
494+
},
495+
},
496+
},
497+
gitRepoReference: &sourcev1.GitRepositoryRef{
498+
Branch: "main",
499+
},
500+
latestImage: "helloworld:1.0.1",
501+
wantErr: false,
502+
wantCommitMsg: `Commit summary
503+
504+
Automation: test-ns/test-update
505+
506+
Cluster: prod
507+
Testing: value
508+
`,
509+
},
510+
475511
{
476512
name: "push to different branch",
477513
gitSpec: &imagev1.GitSpec{

0 commit comments

Comments
 (0)
Please sign in to comment.