argoproj / argoproj/notifications-engine
[Feature] Support multi-source Applications in repo.GetCommitMetadata
- Dominant language
- Go
- Stars
- 334
- Forks
- 217
- PR merge metrics
- No merged PRs in 30d
Description
## Summary
The template helper `repo.GetCommitMetadata(revision)` reads `application.spec.source.repoURL` to determine which repo to query. For multi-source ArgoCD Applications (where `spec.source` is empty and the source list lives at `spec.sources[]`), the helper fails with:
```
error calling call: failed to get application source repo URL
```
This kills the entire notification template render — no message is delivered.
## Repro
ArgoCD ≥ 2.6 supports multi-source Applications. Example spec:
```yaml
spec:
sources:
- repoURL: https://github.com/org/gitops.git
path: chart
helm:
valueFiles:
- $values/envs/prod.yaml
- repoURL: https://github.com/org/gitops.git
ref: values
```
Notification template using:
```
{{ $commit := call .repo.GetCommitMetadata (index .app.status.sync.revisions 0) }}
{{ $commit.Author }}
```
fails to render. The same App displays commit metadata correctly in the ArgoCD UI, which uses `ApplicationService.RevisionMetadata` with a `sourceIndex` parameter.
## Proposed Fix
Two options, not mutually exclusive:
**Option A — make `GetCommitMetadata` fall back to `sources[0]`** (backwards-compatible, fixes most users with no template changes):
```go
func GetCommitMetadata(revision string) (CommitMetadata, error) {
repoURL := app.Spec.Source.RepoURL
if repoURL == "" && len(app.Spec.Sources) > 0 {
repoURL = app.Spec.Sources[0].RepoURL
}
// ... existing lookup
}
```
**Option B — add a sibling helper that takes a source index** (explicit, handles non-zero indices):
```go
func GetCommitMetadataFromSource(sourceIndex int, revision string) (CommitMetadata, error)
```
Template usage:
```
{{ call .repo.GetCommitMetadataFromSource 0 (index .app.status.sync.revisions 0) }}
```
## Impact
Anyone using the standard `app-deployed` / `app-sync-failed` / `app-health-degraded` templates with multi-source Applications loses commit author/message in Slack/email. Affects GitOps setups that use the chart-source + values-source split, which is common since ArgoCD 2.6.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the repo.GetCommitMetadata entry point and compare it with ArgoCD's ApplicationService.RevisionMetadata, which accepts a sourceIndex. Review the standard app-deployed, app-sync-failed, and app-health-degraded templates to understand current usage. Done means multi-source Applications render commit metadata without breaking existing single-source behavior, with support for the chosen fallback or indexed helper design.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100