Skip to content

[WIP] Delete old plan comments on PR update #1943

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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 <a href="https://join.slack.com/t/diggertalk/shared_invite/zt-1tocl4w0x-E3RkpPiK7zQkehl8O78g8Q">Slack</a>, and ask us any questions there.
- Join our <a href="https://join.slack.com/t/diggertalk/shared_invite/zt-1tocl4w0x-E3RkpPiK7zQkehl8O78g8Q">Slack</a>, and ask us any questions there.

## Telemetry

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions backend/models/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -170,3 +171,4 @@ func (b *DiggerBatch) MapToJsonStruct() (orchestrator_scheduler.SerializedBatch,

return res, nil
}

37 changes: 37 additions & 0 deletions backend/models/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}
Comment on lines +1856 to +1867
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider using a single query with JOIN to fetch all jobs instead of multiple queries in a loop to improve performance


slog.Info("fetched all digger jobs for PR",
"prNumber", prNumber,
"repoFullName", repoFullName,
"orgId", orgId,
"batchCount", len(batches),
"jobCount", len(allJobs))

return allJobs, nil
}
9 changes: 9 additions & 0 deletions libs/ci/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +208 to +209
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider adding structured logging here to match the rest of the codebase's logging pattern

}

type GithubCommentReaction string

const GithubCommentPlusOneReaction GithubCommentReaction = "+1"
Expand Down
Loading