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 a6a3aec
Show file tree
Hide file tree
Showing 5 changed files with 59 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
13 changes: 13 additions & 0 deletions trigger/application.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package trigger

import (
"encoding/json"
"fmt"

liberr "github.com/jortel/go-utils/error"
"github.com/konveyor/tackle2-hub/model"
tasking "github.com/konveyor/tackle2-hub/task"
)
Expand All @@ -23,6 +25,17 @@ func (r *Application) Updated(m *model.Application) (err error) {
if !Settings.Discovery.Enabled {
return
}

repo := model.Repository{}
err = json.Unmarshal(m.Repository, &repo)
if err != nil {
err = liberr.Wrap(err)
return
}
if repo == (model.Repository{}) {
return
}

kinds, err := r.FindTasks(Settings.Discovery.Label)
if err != nil {
return
Expand Down

0 comments on commit a6a3aec

Please sign in to comment.