Skip to content

Commit bf1ee5b

Browse files
committed
fix tests for libs
1 parent 76e48a3 commit bf1ee5b

File tree

5 files changed

+39
-6
lines changed

5 files changed

+39
-6
lines changed

backend/controllers/projects.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,15 +1518,43 @@ func DeleteOlderPRCommentsIfEnabled(gh utils.GithubClientProvider, batch *models
15181518
}
15191519

15201520
for _, prBatch := range prBatches {
1521+
if prBatch.BatchType == orchestrator_scheduler.DiggerCommandApply {
1522+
slog.Info("found previous apply job for PR therefore not deleting earlier comments")
1523+
return nil
1524+
}
1525+
}
1526+
1527+
allDeletesSuccessful := true
1528+
for _, prBatch := range prBatches {
1529+
if prBatch.ID == batch.ID {
1530+
// don't delete the current batch comments
1531+
continue
1532+
}
15211533
jobs, err := models.DB.GetDiggerJobsForBatch(prBatch.ID)
15221534
if err != nil {
1523-
1535+
slog.Error("could not get jobs for batch", "batchId", prBatch.ID, "error", err)
1536+
// won't return error here since can still continue deleting rest of batches
1537+
continue
15241538
}
15251539
for _, prJob := range jobs {
1526-
prService.DeleteComment(strconv.FormatInt(*prJob.PRCommentId, 10))
1540+
if prJob.PRCommentId == nil {
1541+
slog.Debug("PR comment not found for job, ignoring deletion", "JobID", prJob.ID)
1542+
continue
1543+
}
1544+
err = prService.DeleteComment(strconv.FormatInt(*prJob.PRCommentId, 10))
1545+
if err != nil {
1546+
slog.Error("Could not delete comment for job", "jobID", prJob.ID, "commentID", prJob.PRCommentId, "error", err)
1547+
allDeletesSuccessful = false
1548+
}
15271549
}
15281550
}
15291551

1552+
if !allDeletesSuccessful {
1553+
slog.Warn("some of the previous comments failed to delete")
1554+
}
1555+
1556+
return nil
1557+
15301558
} else {
15311559
if batch.BatchType != orchestrator_scheduler.DiggerCommandPlan {
15321560
slog.Debug("Skipping deletion of prior comments - not an plan command",

backend/migrations/20250512213729.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Modify "digger_batches" table
2+
ALTER TABLE "public"."digger_batches" ADD COLUMN "created_at" timestamptz NULL, ADD COLUMN "updated_at" timestamptz NULL, ADD COLUMN "deleted_at" timestamptz NULL;
3+
-- Create index "idx_digger_batches_deleted_at" to table: "digger_batches"
4+
CREATE INDEX "idx_digger_batches_deleted_at" ON "public"."digger_batches" ("deleted_at");

backend/migrations/atlas.sum

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
h1:0Z77pgu5xSmp7FGW57wL3fSpDTpVmqh3DKj/F67WBX8=
1+
h1:7qYia+JfrMJUdNvsjR8hZosttT36aVdOje5TP3ekX4w=
22
20231227132525.sql h1:43xn7XC0GoJsCnXIMczGXWis9d504FAWi4F1gViTIcw=
33
20240115170600.sql h1:IW8fF/8vc40+eWqP/xDK+R4K9jHJ9QBSGO6rN9LtfSA=
44
20240116123649.sql h1:R1JlUIgxxF6Cyob9HdtMqiKmx/BfnsctTl5rvOqssQw=
@@ -48,3 +48,4 @@ h1:0Z77pgu5xSmp7FGW57wL3fSpDTpVmqh3DKj/F67WBX8=
4848
20250325134924.sql h1:5vywDVuT0FPmQKP75AvxopxOeuKXsTEN00rgQjnA+ss=
4949
20250416152705.sql h1:yeszz4c/BlyVgUUIk7aTUz/DUNMC40+9fe1Q8Ya4TVI=
5050
20250512172515.sql h1:iIZIhFq3TTyjTzsxNWv3k4FcIkXfOCdHtmHNmYqjBMM=
51+
20250512213729.sql h1:n8bYIXWko9xOUs+FPcG7lS3GXMVQBSygXX7Hpj20eVs=

backend/models/scheduler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const DiggerVCSGitlab DiggerVCSType = "gitlab"
2424
const DiggerVCSBitbucket DiggerVCSType = "bitbucket"
2525

2626
type DiggerBatch struct {
27+
gorm.Model
2728
ID uuid.UUID `gorm:"primary_key"`
2829
VCS DiggerVCSType
2930
PrNumber int
@@ -172,4 +173,3 @@ func (b *DiggerBatch) MapToJsonStruct() (orchestrator_scheduler.SerializedBatch,
172173

173174
return res, nil
174175
}
175-

libs/digger_config/converters.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ func ConvertDiggerYamlToConfig(diggerYaml *DiggerConfigYaml) (*DiggerConfig, gra
210210
}
211211

212212
if diggerYaml.DeletePriorComments != nil {
213-
diggerConfig.DeletePriorComments = false
214-
} else {
215213
diggerConfig.DeletePriorComments = *diggerYaml.DeletePriorComments
214+
} else {
215+
diggerConfig.DeletePriorComments = false
216216
}
217217

218218
if diggerYaml.AutoMergeStrategy != nil {

0 commit comments

Comments
 (0)