From 7c85d47d0c9b312f2195e38f70f1751916561d98 Mon Sep 17 00:00:00 2001 From: Sam Lucidi Date: Tue, 9 Jul 2024 13:34:43 -0400 Subject: [PATCH] Only trigger discovery if the app has a repository Signed-off-by: Sam Lucidi --- api/application.go | 52 ++++++++++++++++++++++++--------------------- importer/manager.go | 29 +++++++++++++------------ 2 files changed, 44 insertions(+), 37 deletions(-) diff --git a/api/application.go b/api/application.go index 7169d1c2e..31cac330a 100644 --- a/api/application.go +++ b/api/application.go @@ -249,18 +249,20 @@ func (h ApplicationHandler) Create(ctx *gin.Context) { return } - rtx := RichContext(ctx) - tr := trigger.Application{ - Trigger: trigger.Trigger{ - TaskManager: rtx.TaskManager, - Client: rtx.Client, - DB: h.DB(ctx), - }, - } - err = tr.Created(m) - if err != nil { - _ = ctx.Error(err) - return + if r.Repository != nil { + rtx := RichContext(ctx) + tr := trigger.Application{ + Trigger: trigger.Trigger{ + TaskManager: rtx.TaskManager, + Client: rtx.Client, + DB: h.DB(ctx), + }, + } + err = tr.Created(m) + if err != nil { + _ = ctx.Error(err) + return + } } h.Respond(ctx, http.StatusCreated, r) @@ -388,18 +390,20 @@ func (h ApplicationHandler) Update(ctx *gin.Context) { } } - rtx := RichContext(ctx) - tr := trigger.Application{ - Trigger: trigger.Trigger{ - TaskManager: rtx.TaskManager, - Client: rtx.Client, - DB: h.DB(ctx), - }, - } - err = tr.Updated(m) - if err != nil { - _ = ctx.Error(err) - return + if r.Repository != nil { + rtx := RichContext(ctx) + tr := trigger.Application{ + Trigger: trigger.Trigger{ + TaskManager: rtx.TaskManager, + Client: rtx.Client, + DB: h.DB(ctx), + }, + } + err = tr.Updated(m) + if err != nil { + _ = ctx.Error(err) + return + } } h.Status(ctx, http.StatusNoContent) diff --git a/importer/manager.go b/importer/manager.go index b11f45e4b..36f61bcd2 100644 --- a/importer/manager.go +++ b/importer/manager.go @@ -344,19 +344,22 @@ func (m *Manager) createApplication(imp *model.Import) (ok bool) { imp.ErrorMessage = result.Error.Error() return } - // best effort - tr := trigger.Application{ - Trigger: trigger.Trigger{ - TaskManager: m.TaskManager, - Client: m.Client, - DB: m.DB, - }, - } - err := tr.Created(app) - if err != nil { - imp.ErrorMessage = fmt.Sprintf( - "Failed to launch discovery tasks for Application '%s'.", - app.Name) + + if repository.URL != "" { + // best effort + tr := trigger.Application{ + Trigger: trigger.Trigger{ + TaskManager: m.TaskManager, + Client: m.Client, + DB: m.DB, + }, + } + err := tr.Created(app) + if err != nil { + imp.ErrorMessage = fmt.Sprintf( + "Failed to launch discovery tasks for Application '%s'.", + app.Name) + } } ok = true