diff --git a/README.md b/README.md index 11289c26..bf7225b9 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,7 @@ Digger runs Terraform natively in your CI. This is: - Open Policy Agent (OPA) support for RBAC - PR-level locks (on top of Terraform native state locks, similar to Atlantis) to avoid race conditions across multiple PRs - Terragrunt, Workspaces, multiple Terraform versions, static analysis via Checkov, plan persistence, ... -- Drift detection - +- Drift detection ## Getting Started @@ -34,6 +33,7 @@ Digger runs Terraform natively in your CI. This is: ## How it works Digger has 2 main components: + - CLI that runs inside your CI and calls Terraform with the right arguments - Orchestrator - a minimal backend (that can also be self-hosted) that triggers CI jobs in response to events such as PR comments @@ -49,7 +49,8 @@ Digger also stores PR-level locks and plan cache in your cloud account (DynamoDB - Apply-after-merge workflows - Web UI (cloud-based) - Read more about differences with Atlantis in our [blog post](https://medium.com/@DiggerHQ/digger-and-atlantis-key-differences-c08029ffe112) -​ + ​ + ## Compared to Terraform Cloud and other TACOs - Open source; orchestrator can be self-hosted @@ -67,7 +68,7 @@ Please pick an issue that already exists if you’re interested in contributing, Not sure where to get started? You can: -- Join our Slack, and ask us any questions there. +- Join our Slack, and ask us any questions there. ## Telemetry @@ -76,7 +77,15 @@ Digger collects anonymized telemetry. See [usage.go](https://github.com/diggerhq ## Running migrations ``` -atlas migrate apply --url $DATABASE_URL +atlas migrate apply --url $DATABASE_URL --allow-dirty +``` + +## Local postgres + +Might need disabling ssl if running default docker image + +``` +export DATABASE_URL=postgres://postgres:root@localhost:5432/postgres?sslmode=disable ``` ## Resources diff --git a/backend/models/scheduler.go b/backend/models/scheduler.go index 1efac02c..e37d6608 100644 --- a/backend/models/scheduler.go +++ b/backend/models/scheduler.go @@ -52,6 +52,7 @@ type DiggerJob struct { Batch *DiggerBatch BatchID *string `gorm:"index:idx_digger_job_id"` PRCommentUrl string + PRCommentId *int64 DiggerJobSummary DiggerJobSummary DiggerJobSummaryID uint SerializedJobSpec []byte @@ -170,3 +171,4 @@ func (b *DiggerBatch) MapToJsonStruct() (orchestrator_scheduler.SerializedBatch, return res, nil } + diff --git a/backend/models/storage.go b/backend/models/storage.go index f696238f..6a70cb59 100644 --- a/backend/models/storage.go +++ b/backend/models/storage.go @@ -1838,3 +1838,40 @@ func (db *Database) GetRepoCache(orgId uint, repoFullName string) (*RepoCache, e "configSize", len(repoCache.DiggerConfig)) return &repoCache, nil } + +func (db *Database) GetDiggerJobsForPR(orgId uint, repoFullName string, prNumber int) ([]DiggerJob, error) { + // Step 1: Get all batches for the PR + batches := make([]DiggerBatch, 0) + result := db.GormDB.Where("repo_full_name = ? AND pr_number = ?", repoFullName, prNumber).Find(&batches) + if result.Error != nil { + slog.Error("error fetching batches for PR", + "prNumber", prNumber, + "repoFullName", repoFullName, + "orgId", orgId, + "error", result.Error) + return nil, result.Error + } + + // Step 2: Get all jobs for each batch + allJobs := make([]DiggerJob, 0) + for _, batch := range batches { + jobs, err := db.GetDiggerJobsForBatch(batch.ID) + if err != nil { + slog.Error("error fetching digger jobs for batch", + "batchId", batch.ID, + "prNumber", prNumber, + "error", err) + return nil, err + } + allJobs = append(allJobs, jobs...) + } + + slog.Info("fetched all digger jobs for PR", + "prNumber", prNumber, + "repoFullName", repoFullName, + "orgId", orgId, + "batchCount", len(batches), + "jobCount", len(allJobs)) + + return allJobs, nil +} diff --git a/libs/ci/github/github.go b/libs/ci/github/github.go index 6792d66f..1366fe5d 100644 --- a/libs/ci/github/github.go +++ b/libs/ci/github/github.go @@ -200,6 +200,15 @@ func (svc GithubService) EditComment(prNumber int, id string, comment string) er return err } +func (svc GithubService) DeleteComment(id string) error { + commentId, err := strconv.ParseInt(id, 10, 64) + if err != nil { + return fmt.Errorf("could not convert id %v to i64: %v", id, err) + } + _, err = svc.Client.Issues.DeleteComment(context.Background(), svc.Owner, svc.RepoName, commentId) + return err +} + type GithubCommentReaction string const GithubCommentPlusOneReaction GithubCommentReaction = "+1"