Skip to content

Commit

Permalink
Do repo check in application trigger
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Lucidi <[email protected]>
  • Loading branch information
mansam committed Jul 10, 2024
1 parent 7c85d47 commit 81b6daf
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 44 deletions.
52 changes: 24 additions & 28 deletions api/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,20 +249,18 @@ func (h ApplicationHandler) Create(ctx *gin.Context) {
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
}
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 @@ -390,20 +388,18 @@ func (h ApplicationHandler) Update(ctx *gin.Context) {
}
}

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
}
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: 13 additions & 16 deletions importer/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,22 +344,19 @@ func (m *Manager) createApplication(imp *model.Import) (ok bool) {
imp.ErrorMessage = result.Error.Error()
return
}

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)
}
// 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
8 changes: 8 additions & 0 deletions migration/v14/model/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,11 @@ type ImportTag struct {
ImportID uint `gorm:"index"`
Import *Import
}

type Repository struct {
Kind string `json:"kind"`
URL string `json:"url"`
Branch string `json:"branch"`
Tag string `json:"tag"`
Path string `json:"path"`
}
1 change: 1 addition & 0 deletions model/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type TaskError = model.TaskError
type TaskEvent = model.TaskEvent
type TaskPolicy = model.TaskPolicy
type Attachment = model.Attachment
type Repository = model.Repository

// Join tables
type ApplicationTag = model.ApplicationTag
Expand Down
3 changes: 3 additions & 0 deletions trigger/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ func (r *Application) Updated(m *model.Application) (err error) {
if !Settings.Discovery.Enabled {
return
}
if len(m.Repository) == 0 || string(m.Repository) == "null" {
return
}
kinds, err := r.FindTasks(Settings.Discovery.Label)
if err != nil {
return
Expand Down

0 comments on commit 81b6daf

Please sign in to comment.