-
Notifications
You must be signed in to change notification settings - Fork 6.4k
feat(hydrator): Commit message templating (#23679) #24204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(hydrator): Commit message templating (#23679) #24204
Conversation
Signed-off-by: pbhatnagar-oss <[email protected]>
Signed-off-by: pbhatnagar-oss <[email protected]>
Signed-off-by: pbhatnagar-oss <[email protected]>
Signed-off-by: pbhatnagar-oss <[email protected]>
…t-message-templating
❌ Preview Environment deleted from BunnyshellAvailable commands (reply to this comment):
|
…ed files Signed-off-by: pbhatnagar-oss <[email protected]>
controller/hydrator/hydrator.go
Outdated
if tmpl == "" { | ||
return "", errors.New("failed to get hydrated commit message template, template not defined") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's drop this check. An empty template is still a template. We can just pass it on to the renderer to handle.
util/hydrator/hydrator.go
Outdated
|
||
// GetHydratorCommitMetadata takes repo, drySha and commitMetadata and returns a HydratorCommitMetadata which is a | ||
// common contract controller and commitServer | ||
func GetHydratorCommitMetadata(repoUrl, drySha string, dryCommitMetadata *appv1.RevisionMetadata) (*HydratorCommitMetadata, error) { //nolint:revive //FIXME(var-naming) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this just return the struct instead of a pointer? Saves callers from worrying about nil pointer checks.
util/hydrator/template.go
Outdated
|
||
// Render use a parsed template and calls the Execute to apply the data. | ||
// currently the method supports struct and a map[string]any as data | ||
func Render(tmpl string, data any) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's change this function to accept the hydrator metadata struct instead of any
, since that's the only use case for now. That'll let us remove all the reflection stuff below.
util/settings/settings.go
Outdated
label := argoCDCM.Data[settingsSourceHydratorCommitMessageTemplateKey] | ||
if label == "" { | ||
return "", nil | ||
} | ||
return label, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
label := argoCDCM.Data[settingsSourceHydratorCommitMessageTemplateKey] | |
if label == "" { | |
return "", nil | |
} | |
return label, nil | |
return argoCDCM.Data[settingsSourceHydratorCommitMessageTemplateKey], nil |
A bit simpler
controller/hydrator/hydrator.go
Outdated
// 1. Get the commit message template defined in the configMap | ||
// 2. Get the data template engine would use to render the template | ||
// 3. Pass the output of Step 1 and Step 2 to template Render | ||
func (h *Hydrator) getHydratorCommitMessage(repoURL, revision string, dryCommitMetadata *appv1.RevisionMetadata) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rename this just getCommitMessage
. We're already in the hydrator code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed
controller/hydrator/hydrator.go
Outdated
tmpl, errTemplate := h.dependencies.GetHydratorCommitMessageTemplate() | ||
if errTemplate != nil { | ||
return "", fmt.Errorf("failed to get hydrated commit message template %w", errTemplate) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move this to the caller and make this function a plain function instead of a receiver? That'll make it easier to unit test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Co-authored-by: Michael Crenshaw <[email protected]> Signed-off-by: pbhatnagar-oss <[email protected]>
Co-authored-by: Michael Crenshaw <[email protected]> Signed-off-by: pbhatnagar-oss <[email protected]>
Signed-off-by: pbhatnagar-oss <[email protected]>
Signed-off-by: pbhatnagar-oss <[email protected]>
Signed-off-by: pbhatnagar-oss <[email protected]>
Signed-off-by: Michael Crenshaw <[email protected]>
util/hydrator/template.go
Outdated
delete(sprigFuncMap, "env") | ||
delete(sprigFuncMap, "expandenv") | ||
delete(sprigFuncMap, "getHostByName") | ||
sprigFuncMap["kindIs"] = kindIs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this, it shouldn't be needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Signed-off-by: pbhatnagar-oss <[email protected]>
util/settings/settings.go
Outdated
@@ -45,6 +45,21 @@ import ( | |||
tlsutil "github.com/argoproj/argo-cd/v3/util/tls" | |||
) | |||
|
|||
var commitMessageTemplate = `{{ .metadata.subject }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we expose this as a public var and use it in the other places where we have this template hardcoded (i.e. tests)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Co-authored-by: Michael Crenshaw <[email protected]> Signed-off-by: pbhatnagar-oss <[email protected]>
…t-message-templating Signed-off-by: pbhatnagar-oss <[email protected]> # Conflicts: # docs/user-guide/source-hydrator.md
…/argo-cd into commit-message-templating
Signed-off-by: pbhatnagar-oss <[email protected]>
Signed-off-by: pbhatnagar-oss <[email protected]>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #24204 +/- ##
==========================================
+ Coverage 60.23% 60.30% +0.06%
==========================================
Files 348 350 +2
Lines 59872 59959 +87
==========================================
+ Hits 36063 36157 +94
+ Misses 20918 20909 -9
- Partials 2891 2893 +2 ☔ View full report in Codecov by Sentry. |
manifests/base/config/argocd-cm.yaml
Outdated
### SourceHydrator commit message template. | ||
# This template iterates through the fields in the `.metadata` object, | ||
# and formats them based on their type (map, array, or primitive values). | ||
# This is the default template and targets specific metadata properties. | ||
sourceHydrator.commitMessageTemplate: | | ||
{{ .metadata.subject }} | ||
{{- if .metadata.body }} | ||
{{ .metadata.body }} | ||
{{- end }} | ||
{{ range $ref := .metadata.references }} | ||
{{- if and $ref.commit $ref.commit.author }} | ||
Co-authored-by: {{ $ref.commit.author }} | ||
{{- end }} | ||
{{- end }} | ||
{{- if .metadata.author }} | ||
Co-authored-by: {{ .metadata.author }} | ||
{{- end }} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this from the base, since the default is now hard-coded in settings.
Co-authored-by: Michael Crenshaw <[email protected]> Signed-off-by: pbhatnagar-oss <[email protected]>
Co-authored-by: Michael Crenshaw <[email protected]> Signed-off-by: pbhatnagar-oss <[email protected]>
Signed-off-by: pbhatnagar-oss <[email protected]>
…/argo-cd into commit-message-templating
…/argo-cd into commit-message-templating Signed-off-by: pbhatnagar-oss <[email protected]>
…/argo-cd into commit-message-templating
Signed-off-by: pbhatnagar-oss <[email protected]>
Co-authored-by: Michael Crenshaw <[email protected]> Signed-off-by: pbhatnagar-oss <[email protected]>
Co-authored-by: Michael Crenshaw <[email protected]> Signed-off-by: pbhatnagar-oss <[email protected]>
Co-authored-by: Michael Crenshaw <[email protected]> Signed-off-by: pbhatnagar-oss <[email protected]>
Signed-off-by: pbhatnagar-oss <[email protected]>
…t-message-templating
…24204) Signed-off-by: pbhatnagar-oss <[email protected]> Signed-off-by: Michael Crenshaw <[email protected]> Co-authored-by: Michael Crenshaw <[email protected]> Signed-off-by: Mangaal <[email protected]>
commit message template for source hydrator. This closes #23679
Checklist: