Skip to content

Commit 67f1821

Browse files
committed
Add helper functions for comment handling
1 parent e03f303 commit 67f1821

File tree

4 files changed

+62
-5
lines changed

4 files changed

+62
-5
lines changed

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ Digger runs Terraform natively in your CI. This is:
2323
- Open Policy Agent (OPA) support for RBAC
2424
- PR-level locks (on top of Terraform native state locks, similar to Atlantis) to avoid race conditions across multiple PRs
2525
- Terragrunt, Workspaces, multiple Terraform versions, static analysis via Checkov, plan persistence, ...
26-
- Drift detection
27-
26+
- Drift detection
2827

2928
## Getting Started
3029

@@ -34,6 +33,7 @@ Digger runs Terraform natively in your CI. This is:
3433
## How it works
3534

3635
Digger has 2 main components:
36+
3737
- CLI that runs inside your CI and calls Terraform with the right arguments
3838
- Orchestrator - a minimal backend (that can also be self-hosted) that triggers CI jobs in response to events such as PR comments
3939

@@ -49,7 +49,8 @@ Digger also stores PR-level locks and plan cache in your cloud account (DynamoDB
4949
- Apply-after-merge workflows
5050
- Web UI (cloud-based)
5151
- Read more about differences with Atlantis in our [blog post](https://medium.com/@DiggerHQ/digger-and-atlantis-key-differences-c08029ffe112)
52-
52+
53+
5354
## Compared to Terraform Cloud and other TACOs
5455

5556
- Open source; orchestrator can be self-hosted
@@ -67,7 +68,7 @@ Please pick an issue that already exists if you’re interested in contributing,
6768

6869
Not sure where to get started? You can:
6970

70-
- Join our <a href="https://join.slack.com/t/diggertalk/shared_invite/zt-1tocl4w0x-E3RkpPiK7zQkehl8O78g8Q">Slack</a>, and ask us any questions there.
71+
- Join our <a href="https://join.slack.com/t/diggertalk/shared_invite/zt-1tocl4w0x-E3RkpPiK7zQkehl8O78g8Q">Slack</a>, and ask us any questions there.
7172

7273
## Telemetry
7374

@@ -76,7 +77,15 @@ Digger collects anonymized telemetry. See [usage.go](https://github.com/diggerhq
7677
## Running migrations
7778

7879
```
79-
atlas migrate apply --url $DATABASE_URL
80+
atlas migrate apply --url $DATABASE_URL --allow-dirty
81+
```
82+
83+
## Local postgres
84+
85+
Might need disabling ssl if running default docker image
86+
87+
```
88+
export DATABASE_URL=postgres://postgres:root@localhost:5432/postgres?sslmode=disable
8089
```
8190

8291
## Resources

backend/models/scheduler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type DiggerJob struct {
5252
Batch *DiggerBatch
5353
BatchID *string `gorm:"index:idx_digger_job_id"`
5454
PRCommentUrl string
55+
PRCommentId *int64
5556
DiggerJobSummary DiggerJobSummary
5657
DiggerJobSummaryID uint
5758
SerializedJobSpec []byte
@@ -170,3 +171,4 @@ func (b *DiggerBatch) MapToJsonStruct() (orchestrator_scheduler.SerializedBatch,
170171

171172
return res, nil
172173
}
174+

backend/models/storage.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,3 +1838,40 @@ func (db *Database) GetRepoCache(orgId uint, repoFullName string) (*RepoCache, e
18381838
"configSize", len(repoCache.DiggerConfig))
18391839
return &repoCache, nil
18401840
}
1841+
1842+
func (db *Database) GetDiggerJobsForPR(orgId uint, repoFullName string, prNumber int) ([]DiggerJob, error) {
1843+
// Step 1: Get all batches for the PR
1844+
batches := make([]DiggerBatch, 0)
1845+
result := db.GormDB.Where("repo_full_name = ? AND pr_number = ?", repoFullName, prNumber).Find(&batches)
1846+
if result.Error != nil {
1847+
slog.Error("error fetching batches for PR",
1848+
"prNumber", prNumber,
1849+
"repoFullName", repoFullName,
1850+
"orgId", orgId,
1851+
"error", result.Error)
1852+
return nil, result.Error
1853+
}
1854+
1855+
// Step 2: Get all jobs for each batch
1856+
allJobs := make([]DiggerJob, 0)
1857+
for _, batch := range batches {
1858+
jobs, err := db.GetDiggerJobsForBatch(batch.ID)
1859+
if err != nil {
1860+
slog.Error("error fetching digger jobs for batch",
1861+
"batchId", batch.ID,
1862+
"prNumber", prNumber,
1863+
"error", err)
1864+
return nil, err
1865+
}
1866+
allJobs = append(allJobs, jobs...)
1867+
}
1868+
1869+
slog.Info("fetched all digger jobs for PR",
1870+
"prNumber", prNumber,
1871+
"repoFullName", repoFullName,
1872+
"orgId", orgId,
1873+
"batchCount", len(batches),
1874+
"jobCount", len(allJobs))
1875+
1876+
return allJobs, nil
1877+
}

libs/ci/github/github.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@ func (svc GithubService) EditComment(prNumber int, id string, comment string) er
200200
return err
201201
}
202202

203+
func (svc GithubService) DeleteComment(id string) error {
204+
commentId, err := strconv.ParseInt(id, 10, 64)
205+
if err != nil {
206+
return fmt.Errorf("could not convert id %v to i64: %v", id, err)
207+
}
208+
_, err = svc.Client.Issues.DeleteComment(context.Background(), svc.Owner, svc.RepoName, commentId)
209+
return err
210+
}
211+
203212
type GithubCommentReaction string
204213

205214
const GithubCommentPlusOneReaction GithubCommentReaction = "+1"

0 commit comments

Comments
 (0)