fix: Badge display revision for multiple-sources application #17986 (#22547)

Signed-off-by: fpetr <petr.frantisek@gmail.com>
Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: fpetr <111520435+fpetr@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
fpetr
2025-09-12 21:37:42 +02:00
committed by GitHub
parent 15a35daf16
commit 0793efb5e4
3 changed files with 25 additions and 1 deletions

View File

@@ -132,7 +132,11 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
status = app.Status.Sync.Status
applicationName = name[0]
if app.Status.OperationState != nil && app.Status.OperationState.SyncResult != nil {
revision = app.Status.OperationState.SyncResult.Revision
if len(app.Status.OperationState.SyncResult.Revisions) > 0 {
revision = app.Status.OperationState.SyncResult.Revisions[0]
} else {
revision = app.Status.OperationState.SyncResult.Revision
}
}
} else if errors.IsNotFound(err) {
notFound = true

View File

@@ -451,6 +451,24 @@ func TestHandlerRevisionIsEnabledShortCommitSHA(t *testing.T) {
assert.Contains(t, response, "(abc)")
}
func TestHandlerRevisionIsEnabledMultipleSources(t *testing.T) {
app := testApp()
app.Status.OperationState.SyncResult.Revision = ""
app.Status.OperationState.SyncResult.Revisions = []string{"aa29b85", "cf41g63"}
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
handler := NewHandler(appclientset.NewSimpleClientset(app), settingsMgr, "default", []string{})
req, err := http.NewRequest(http.MethodGet, "/api/badge?name=test-app&revision=true", http.NoBody)
require.NoError(t, err)
rr := httptest.NewRecorder()
handler.ServeHTTP(rr, req)
response := rr.Body.String()
assert.Contains(t, response, "(aa29b85)")
assert.NotContains(t, response, "(cf41g63)")
}
func TestHandlerFeatureIsDisabled(t *testing.T) {
argoCDCmDisabled := argoCDCm()
delete(argoCDCmDisabled.Data, "statusbadge.enabled")