Skip to content

Commit de6a760

Browse files
fix/drift settings (#2026)
* fix drift settings * Update ee/drift/controllers/drift.go Co-authored-by: bismuthdev[bot] <177057995+bismuthdev[bot]@users.noreply.github.com> * fix drift settings --------- Co-authored-by: bismuthdev[bot] <177057995+bismuthdev[bot]@users.noreply.github.com>
1 parent 4ff804b commit de6a760

File tree

4 files changed

+63
-26
lines changed

4 files changed

+63
-26
lines changed

backend/bootstrap/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,14 @@ func Bootstrap(templates embed.FS, diggerController controllers.DiggerController
231231

232232
billingApiGroup := apiGroup.Group("/billing")
233233
billingApiGroup.GET("/", controllers.BillingStatusApi)
234-
234+
235235
reposApiGroup := apiGroup.Group("/repos")
236236
reposApiGroup.GET("/", controllers.ListReposApi)
237237
reposApiGroup.GET("/:repo_id/jobs", controllers.GetJobsForRepoApi)
238238

239239
projectsApiGroup := apiGroup.Group("/projects")
240240
projectsApiGroup.GET("/", controllers.ListProjectsApi)
241+
projectsApiGroup.GET("/:project_id/", controllers.ProjectsDetailsApi)
241242
projectsApiGroup.PUT("/:project_id/", controllers.UpdateProjectApi)
242243

243244
githubApiGroup := apiGroup.Group("/github")

backend/controllers/projects.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,41 @@ func ListProjectsApi(c *gin.Context) {
7171
c.JSON(http.StatusOK, response)
7272
}
7373

74+
func ProjectsDetailsApi(c *gin.Context) {
75+
// assume all exists as validated in middleware
76+
organisationId := c.GetString(middleware.ORGANISATION_ID_KEY)
77+
organisationSource := c.GetString(middleware.ORGANISATION_SOURCE_KEY)
78+
projectId := c.Param("project_id")
79+
80+
var org models.Organisation
81+
err := models.DB.GormDB.Where("external_id = ? AND external_source = ?", organisationId, organisationSource).First(&org).Error
82+
if err != nil {
83+
if errors.Is(err, gorm.ErrRecordNotFound) {
84+
slog.Info("Organisation not found", "organisationId", organisationId, "source", organisationSource)
85+
c.String(http.StatusNotFound, "Could not find organisation: "+organisationId)
86+
} else {
87+
slog.Error("Error fetching organisation", "organisationId", organisationId, "source", organisationSource, "error", err)
88+
c.String(http.StatusInternalServerError, "Error fetching organisation")
89+
}
90+
return
91+
}
92+
93+
var project models.Project
94+
err = models.DB.GormDB.Preload("Organisation").Where("projects.organisation_id = ? AND projects.id = ?", org.ID, projectId).First(&project).Error
95+
if err != nil {
96+
if errors.Is(err, gorm.ErrRecordNotFound) {
97+
slog.Info("Project not found", "organisationId", organisationId, "orgId", org.ID)
98+
c.String(http.StatusNotFound, "Could not find project")
99+
} else {
100+
slog.Error("Error fetching project", "organisationId", organisationId, "orgId", org.ID, "error", err)
101+
c.String(http.StatusInternalServerError, "Unknown error occurred while fetching database")
102+
}
103+
return
104+
}
105+
106+
c.JSON(http.StatusOK, project.MapToJsonStruct())
107+
}
108+
74109
func UpdateProjectApi(c *gin.Context) {
75110
// assume all exists as validated in middleware
76111
organisationId := c.GetString(middleware.ORGANISATION_ID_KEY)

backend/models/orgs.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -116,28 +116,28 @@ type Project struct {
116116
}
117117

118118
func (p *Project) MapToJsonStruct() interface{} {
119-
lastRun, _ := DB.GetLastDiggerRunForProject(p.Name)
120-
status := RunSucceeded
121-
if lastRun != nil {
122-
status = lastRun.Status
123-
}
119+
//lastRun, _ := DB.GetLastDiggerRunForProject(p.Name)
120+
//status := RunSucceeded
121+
//if lastRun != nil {
122+
// status = lastRun.Status
123+
//}
124124
return struct {
125-
Id uint `json:"id"`
126-
Name string `json:"name"`
127-
Directory string `json:"directory"`
128-
OrganisationID uint `json:"organisation_id"`
129-
OrganisationName string `json:"organisation_name"`
130-
RepoID uint `json:"repo_id"`
131-
RepoFullName string `json:"repo_full_name"`
132-
IsInMainBranch bool `json:"is_in_main_branch"`
133-
IsGenerated bool `json:"is_generated"`
134-
DriftEnabled bool `json:"drift_enabled"`
135-
DriftStatus string `json:"drift_status"`
136-
LatestDriftCheck string `json:"latest_drift_check"`
137-
DriftTerraformPlan string `json:"drift_terraform_plan"`
138-
LastActivityTimestamp string `json:"last_activity_timestamp"`
139-
LastActivityAuthor string `json:"last_activity_author"`
140-
LastActivityStatus string `json:"last_activity_status"`
125+
Id uint `json:"id"`
126+
Name string `json:"name"`
127+
Directory string `json:"directory"`
128+
OrganisationID uint `json:"organisation_id"`
129+
OrganisationName string `json:"organisation_name"`
130+
RepoID uint `json:"repo_id"`
131+
RepoFullName string `json:"repo_full_name"`
132+
IsInMainBranch bool `json:"is_in_main_branch"`
133+
IsGenerated bool `json:"is_generated"`
134+
DriftEnabled bool `json:"drift_enabled"`
135+
DriftStatus string `json:"drift_status"`
136+
LatestDriftCheck time.Time `json:"latest_drift_check"`
137+
DriftTerraformPlan string `json:"drift_terraform_plan"`
138+
LastActivityTimestamp string `json:"last_activity_timestamp"`
139+
LastActivityAuthor string `json:"last_activity_author"`
140+
LastActivityStatus string `json:"last_activity_status"`
141141
}{
142142
Id: p.ID,
143143
Name: p.Name,
@@ -147,13 +147,13 @@ func (p *Project) MapToJsonStruct() interface{} {
147147
RepoFullName: p.RepoFullName,
148148
DriftEnabled: p.DriftEnabled,
149149
DriftStatus: string(p.DriftStatus),
150-
LatestDriftCheck: p.LatestDriftCheck.String(),
150+
LatestDriftCheck: p.LatestDriftCheck,
151151
DriftTerraformPlan: p.DriftTerraformPlan,
152152
LastActivityTimestamp: p.UpdatedAt.String(),
153153
LastActivityAuthor: "unknown",
154-
LastActivityStatus: string(status),
155-
IsGenerated: p.IsGenerated,
156-
IsInMainBranch: p.IsInMainBranch,
154+
//LastActivityStatus: string(status),
155+
IsGenerated: p.IsGenerated,
156+
IsInMainBranch: p.IsInMainBranch,
157157
}
158158
}
159159
func (r *Repo) MapToJsonStruct() interface{} {

ee/drift/controllers/ci_jobs.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ func ProjectDriftStateMachineApply(project models.Project, tfplan string, resour
137137
project.DriftToCreate = resourcesCreated
138138
project.DriftToUpdate = resourcesUpdated
139139
project.DriftToDelete = resourcesDeleted
140+
project.LatestDriftCheck = time.Now()
140141
result := models.DB.GormDB.Save(&project)
141142
if result.Error != nil {
142143
return result.Error

0 commit comments

Comments
 (0)