diff --git a/backend/models/storage_projects.go b/backend/models/storage_projects.go index 25e0170b2..ce39cb490 100644 --- a/backend/models/storage_projects.go +++ b/backend/models/storage_projects.go @@ -6,21 +6,11 @@ import ( ) func (db *Database) LoadProjectsForOrg(orgId uint) ([]*Project, error) { - orgProjects := make([]*Project, 0) - var repos []*Repo - err := db.GormDB.Where("organisation_id = ?", orgId).Find(&repos).Error + var projects []*Project + err := db.GormDB.Preload("Organisation").Where("organisation_id = ?", orgId).Find(&projects).Error if err != nil { - log.Printf("could not find repos for org %v", orgId) - return nil, fmt.Errorf("could not find repos for org %v", orgId) + log.Printf("could not query projects for org: %v", orgId) + return nil, fmt.Errorf("could not query projects for org: %v", orgId) } - for _, repo := range repos { - var projects []*Project - err := db.GormDB.Preload("Organisation").Where("repo_full_name = ?", repo.RepoFullName).Find(&projects).Error - if err != nil { - log.Printf("could not query projects for repo: %v", repo.ID) - return nil, fmt.Errorf("could not query projects for repo: %v", repo.ID) - } - orgProjects = append(orgProjects, projects...) - } - return orgProjects, nil + return projects, nil } diff --git a/drift/controllers/drift.go b/drift/controllers/drift.go index 739b41401..54dd45cae 100644 --- a/drift/controllers/drift.go +++ b/drift/controllers/drift.go @@ -4,16 +4,17 @@ import ( "bytes" "encoding/json" "fmt" - "github.com/diggerhq/digger/backend/models" "log" "net/http" "net/url" "os" "time" + "github.com/diggerhq/digger/backend/models" + "github.com/diggerhq/digger/backend/ci_backends" - services2 "github.com/diggerhq/digger/drift/services" - "github.com/diggerhq/digger/drift/utils" + services2 "github.com/diggerhq/digger/drift/services" + "github.com/diggerhq/digger/drift/utils" "github.com/diggerhq/digger/libs/ci/generic" dg_configuration "github.com/diggerhq/digger/libs/digger_config" "github.com/diggerhq/digger/libs/scheduler" @@ -305,14 +306,14 @@ func (mc MainController) ProcessDriftForOrg(c *gin.Context) { jsonPayload, err := json.Marshal(payload) if err != nil { fmt.Println("Process Drift: error marshaling JSON:", err) - return + continue } // Create a new request req, err := http.NewRequest("POST", triggerDriftUrl, bytes.NewBuffer(jsonPayload)) if err != nil { fmt.Println("Process Drift: Error creating request:", err) - return + continue } // Set headers @@ -324,7 +325,7 @@ func (mc MainController) ProcessDriftForOrg(c *gin.Context) { resp, err := client.Do(req) if err != nil { fmt.Println("Error sending request:", err) - return + continue } defer resp.Body.Close()