Skip to content

Conversation

pbhatnagar-oss
Copy link
Contributor

@pbhatnagar-oss pbhatnagar-oss commented Aug 19, 2025

commit message template for source hydrator. This closes #23679
Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • The title of the PR conforms to the Title of the PR
  • I've included "Closes [ISSUE #]" or "Fixes [ISSUE #]" in the description to automatically close the associated issue.
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Does this PR require documentation updates?
  • I've updated documentation as required by this PR.
  • I have signed off all my commits as required by DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My build is green (troubleshooting builds).
  • My new feature complies with the feature status guidelines.
  • I have added a brief description of why this PR is necessary and/or what this PR solves.
  • Optional. My organization is added to USERS.md.
  • Optional. For bug fixes, I've indicated what older releases this fix should be cherry-picked into (this may or may not happen depending on risk/complexity).

Copy link

bunnyshell bot commented Aug 19, 2025

❌ Preview Environment deleted from Bunnyshell

Available commands (reply to this comment):

  • 🚀 /bns:deploy to deploy the environment

Comment on lines 453 to 455
if tmpl == "" {
return "", errors.New("failed to get hydrated commit message template, template not defined")
}
Copy link
Member

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.


// 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)
Copy link
Member

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.


// 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) {
Copy link
Member

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.

Comment on lines 1011 to 1015
label := argoCDCM.Data[settingsSourceHydratorCommitMessageTemplateKey]
if label == "" {
return "", nil
}
return label, nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
label := argoCDCM.Data[settingsSourceHydratorCommitMessageTemplateKey]
if label == "" {
return "", nil
}
return label, nil
return argoCDCM.Data[settingsSourceHydratorCommitMessageTemplateKey], nil

A bit simpler

// 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) {
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed

Comment on lines 449 to 452
tmpl, errTemplate := h.dependencies.GetHydratorCommitMessageTemplate()
if errTemplate != nil {
return "", fmt.Errorf("failed to get hydrated commit message template %w", errTemplate)
}
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

pbhatnagar-oss and others added 5 commits August 22, 2025 09:16
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: Michael Crenshaw <[email protected]>
delete(sprigFuncMap, "env")
delete(sprigFuncMap, "expandenv")
delete(sprigFuncMap, "getHostByName")
sprigFuncMap["kindIs"] = kindIs
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@crenshaw-dev crenshaw-dev changed the title feat(hydrator): Commit message templating #23679 feat(hydrator): Commit message templating (#23679) Aug 28, 2025
@@ -45,6 +45,21 @@ import (
tlsutil "github.com/argoproj/argo-cd/v3/util/tls"
)

var commitMessageTemplate = `{{ .metadata.subject }}
Copy link
Member

@crenshaw-dev crenshaw-dev Aug 28, 2025

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)?

Copy link
Contributor Author

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
Signed-off-by: pbhatnagar-oss <[email protected]>
Signed-off-by: pbhatnagar-oss <[email protected]>
Copy link

codecov bot commented Aug 28, 2025

Codecov Report

❌ Patch coverage is 63.55140% with 39 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.30%. Comparing base (4c92911) to head (416fca1).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
util/hydrator/template.go 53.84% 12 Missing and 6 partials ⚠️
controller/hydrator/hydrator.go 36.84% 8 Missing and 4 partials ⚠️
util/settings/settings.go 55.55% 3 Missing and 1 partial ⚠️
controller/hydrator_dependencies.go 50.00% 2 Missing and 1 partial ⚠️
commitserver/commit/hydratorhelper.go 71.42% 1 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

@pbhatnagar-oss pbhatnagar-oss marked this pull request as ready for review August 28, 2025 22:58
@pbhatnagar-oss pbhatnagar-oss requested review from a team as code owners August 28, 2025 22:58
Comment on lines 119 to 137
### 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 }}


Copy link
Member

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.

pbhatnagar-oss and others added 5 commits September 2, 2025 13:21
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]>
@crenshaw-dev crenshaw-dev merged commit 6f6c39d into argoproj:master Sep 3, 2025
28 checks passed
Mangaal pushed a commit to Mangaal/argo-cd that referenced this pull request Sep 10, 2025
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

hydrator: Make hydrated commit message template-able
2 participants