Skip to content

Commit

Permalink
Only trigger discovery if the app has a repository
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Lucidi <[email protected]>
  • Loading branch information
mansam committed Jul 9, 2024
1 parent da9fca4 commit 7c85d47
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 37 deletions.
52 changes: 28 additions & 24 deletions api/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
29 changes: 16 additions & 13 deletions importer/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7c85d47

Please sign in to comment.