Skip to content

Commit 0db76b6

Browse files
motatoesZIJ
andauthored
feat/reconcliation of branches (#2498)
* Bring back docs on local development * Improve local dev docs * Agent task for moving from callbacks to webhooks * Move from callback to webhooks, again * Make repos webhook async; dont comment erorr when installed to all repos * remove unecessary check * unnecessary comments * remove commented out code, ensure code parameter handled gracefully * fix error * ensure no unnecessary ai summaries generated --------- Co-authored-by: Igor Zalutski <izalutski@gmail.com>
1 parent 685501f commit 0db76b6

File tree

10 files changed

+55
-77
lines changed

10 files changed

+55
-77
lines changed

backend/controllers/github.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,15 @@ func (d DiggerController) GithubAppWebHook(c *gin.Context) {
8787
"added", len(event.RepositoriesAdded),
8888
"removed", len(event.RepositoriesRemoved),
8989
)
90-
if err := handleInstallationRepositoriesEvent(c.Request.Context(), gh, event, appId64); err != nil {
91-
slog.Error("Failed to handle installation repositories event", "error", err)
92-
c.String(http.StatusAccepted, "Failed to handle webhook event.")
93-
return
94-
}
90+
91+
// Run in goroutine to avoid webhook timeouts for large installations
92+
go func(ctx context.Context) {
93+
defer logging.InheritRequestLogger(ctx)()
94+
// Use background context so work continues after HTTP response
95+
if err := handleInstallationRepositoriesEvent(context.Background(), gh, event, appId64); err != nil {
96+
slog.Error("Failed to handle installation repositories event", "error", err)
97+
}
98+
}(c.Request.Context())
9599
case *github.PushEvent:
96100
slog.Info("Processing PushEvent",
97101
"repo", *event.Repo.FullName,

backend/controllers/github_callback.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ func (d DiggerController) GithubAppCallbackPage(c *gin.Context) {
3131
code := ""
3232
if codeExists && len(codeParams) > 0 && len(codeParams[0]) > 0 {
3333
code = codeParams[0]
34+
} else {
35+
slog.Debug("No code parameter found, probably a setup update, going to return success since we are relying on webhooks now")
36+
c.HTML(http.StatusOK, "github_success.tmpl", gin.H{})
37+
return
3438
}
3539

3640
appId := c.Request.URL.Query().Get("state")

backend/controllers/github_pull_request.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"runtime/debug"
1010
"slices"
1111
"strconv"
12-
"strings"
1312

1413
"github.com/diggerhq/digger/backend/ci_backends"
1514
config2 "github.com/diggerhq/digger/backend/config"
@@ -138,16 +137,27 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
138137
return nil
139138
}
140139

141-
// Silently skip repos without digger.yml - this is expected for org-wide installations
142-
if strings.Contains(err.Error(), "could not find digger.yml") ||
143-
strings.Contains(err.Error(), "could not find digger.yaml") {
144-
slog.Info("No Digger config found, skipping repo",
140+
// Check if the error is due to missing digger config and the app is installed for all repos
141+
if errors.Is(err, digger_config.ErrDiggerConfigNotFound) {
142+
slog.Debug("Digger config not found, checking if app is installed for all repos",
145143
"prNumber", prNumber,
146144
"repoFullName", repoFullName,
147145
)
148-
return nil
146+
isAllRepos, checkErr := utils.IsAllReposInstallation(appId, installationId)
147+
if checkErr != nil {
148+
slog.Warn("Failed to check if installation is for all repos",
149+
"error", checkErr,
150+
)
151+
} else if isAllRepos {
152+
slog.Info("Digger config not found but GitHub App is installed for all repos, skipping error comment",
153+
"prNumber", prNumber,
154+
"repoFullName", repoFullName,
155+
)
156+
return nil
157+
}
149158
}
150159

160+
151161
slog.Error("Error getting Digger config for PR",
152162
"prNumber", prNumber,
153163
"repoFullName", repoFullName,
@@ -515,7 +525,7 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
515525
commentReporterManager.UpdateComment(fmt.Sprintf(":x: Could not retrieve created batch: %v", err))
516526
return fmt.Errorf("error getting digger batch")
517527
}
518-
528+
519529
if config.CommentRenderMode == digger_config.CommentRenderModeGroupByModule {
520530
slog.Info("Using GroupByModule render mode for comments", "prNumber", prNumber)
521531

backend/controllers/projects.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,6 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
10261026
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error getting refreshed batch"})
10271027
return
10281028
}
1029-
//err = UpdateCheckStatusForBatch(d.GithubClientProvider, refreshedBatch)
10301029
slog.Debug("Attempting to update GitHub Check Run for batch",
10311030
"batchId", batch.ID,
10321031
"checkRunId", refreshedBatch.CheckRunId,
@@ -1056,7 +1055,6 @@ func (d DiggerController) SetJobStatusForProject(c *gin.Context) {
10561055
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error getting refreshed job"})
10571056
return
10581057
}
1059-
//err = UpdateCommitStatusForJob(d.GithubClientProvider, refreshedJob)
10601058
slog.Debug("Attempting to update GitHub Check Run for job",
10611059
"jobId", jobId,
10621060
"checkRunId", refreshedJob.CheckRunId,

backend/controllers/projects_helpers.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,12 @@ func UpdateCheckRunForBatch(gh utils.GithubClientProvider, batch *models.DiggerB
210210
return fmt.Errorf("error generating realtime comment message: %v", err)
211211
}
212212

213-
summary, err := GenerateChecksSummaryForBatch(batch)
214-
if err != nil {
215-
slog.Warn("Error generating checks summary for batch", "batchId", batch.ID, "error", err)
213+
var summary = ""
214+
if batch.Status == orchestrator_scheduler.BatchJobSucceeded || batch.Status == orchestrator_scheduler.BatchJobFailed {
215+
summary, err = GenerateChecksSummaryForBatch(batch)
216+
if err != nil {
217+
slog.Warn("Error generating checks summary for batch", "batchId", batch.ID, "error", err)
218+
}
216219
}
217220

218221
if isPlanBatch {
@@ -397,11 +400,15 @@ func UpdateCheckRunForJob(gh utils.GithubClientProvider, job *models.DiggerJob)
397400
"```\n"
398401

399402

400-
summary, err := GenerateChecksSummaryForJob(job)
401-
if err != nil {
402-
slog.Warn("Error generating checks summary for batch", "batchId", batch.ID, "error", err)
403+
var summary = ""
404+
if job.Status == orchestrator_scheduler.DiggerJobSucceeded || job.Status == orchestrator_scheduler.DiggerJobFailed {
405+
summary, err = GenerateChecksSummaryForJob(job)
406+
if err != nil {
407+
slog.Warn("Error generating checks summary for batch", "batchId", batch.ID, "error", err)
408+
}
403409
}
404410

411+
405412
slog.Debug("Updating PR status for job", "jobId", job.DiggerJobID, "status", status, "conclusion", conclusion)
406413
if isPlan {
407414
title := fmt.Sprintf("%v to create %v to update %v to delete", job.DiggerJobSummary.ResourcesCreated, job.DiggerJobSummary.ResourcesUpdated, job.DiggerJobSummary.ResourcesDeleted)

backend/models/scheduler.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,9 @@ func GetCheckRunConclusionForJob(job *DiggerJob) (string, error) {
259259
return "failure", nil
260260
}
261261
slog.Error("Unknown job status in GetCheckRunConclusionForJob - this will cause GitHub API 422 error",
262-
"jobId", job.DiggerJobID,
263-
"jobStatus", job.Status,
264-
"jobStatusInt", int(job.Status),
265-
"validStatuses", []string{"created", "triggered", "started", "queued_for_run", "succeeded", "failed"})
262+
"jobId", job.DiggerJobID,
263+
"jobStatus", job.Status,
264+
"jobStatusInt", int(job.Status),
265+
"validStatuses", []string{"created", "triggered", "started", "queued_for_run", "succeeded", "failed"})
266266
return "", fmt.Errorf("unknown job status: %v", job.Status)
267267
}

docs/ce/local-development/backend.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Orchestrator local setup
2+
title: Backend (orchestrator) local setup
33
---
44

55
The backend serves orchestration APIs, GitHub app endpoints, and internal APIs the UI relies on.
@@ -51,7 +51,7 @@ The backend serves orchestration APIs, GitHub app endpoints, and internal APIs t
5151

5252
## GitHub app integration
5353

54-
- For a quick install link, set `ORCHESTRATOR_GITHUB_APP_URL` in `ui/.env.local` to your app's install URL (`https://github.com/apps/<app>/installations/new`).
54+
- For a quick install link, set `ORCHESTRATOR_GITHUB_APP_URL` in `ui/.env.local` to your apps install URL (`https://github.com/apps/<app>/installations/new`).
5555
- To create a new app via the backend, open `http://localhost:3000/github/setup` (requires `HOSTNAME` set to a reachable URL for callbacks).
5656

5757
## Troubleshooting

docs/docs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,4 @@
223223
"linkedin": "https://www.linkedin.com/company/diggerhq/"
224224
}
225225
}
226-
}
226+
}

go.work.sum

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,7 @@ github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 h1:YEetp8
14541454
github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc=
14551455
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385 h1:clC1lXBpe2kTj2VHdaIu9ajZQe4kcEY9j0NsnDDBZ3o=
14561456
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM=
1457+
github.com/elazarl/goproxy v1.7.2 h1:Y2o6urb7Eule09PjlhQRGNsqRfPmYI3KKQLFpCAV3+o=
14571458
github.com/elazarl/goproxy v1.7.2/go.mod h1:82vkLNir0ALaW14Rc399OTTjyNREgmdL2cVoIbS6XaE=
14581459
github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2 h1:dWB6v3RcOy03t/bUadywsbyrQwCqZeNIEX6M1OtSZOM=
14591460
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633 h1:H2pdYOb3KQ1/YsqVWoWNLQO+fusocsw354rqGTZtAgw=
@@ -1622,6 +1623,7 @@ github.com/google/go-pkcs11 v0.3.0 h1:PVRnTgtArZ3QQqTGtbtjtnIkzl2iY2kt24yqbrf7td
16221623
github.com/google/go-pkcs11 v0.3.0/go.mod h1:6eQoGcuNJpa7jnd5pMGdkSaQpNDYvPlXWMcjXXThLlY=
16231624
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
16241625
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec=
1626+
github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6 h1:k7nVchz72niMH6YLQNvHSdIE7iqsQxK1P41mySCvssg=
16251627
github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw=
16261628
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db h1:097atOisP2aRj7vFgYQBbFN4U4JNXUNYpxael3UzMyo=
16271629
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
@@ -2031,6 +2033,7 @@ github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
20312033
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
20322034
github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU=
20332035
github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM=
2036+
github.com/onsi/ginkgo/v2 v2.19.0 h1:9Cnnf7UHo57Hy3k6/m5k3dRfGTMXGvxhHFvkDTCTpvA=
20342037
github.com/onsi/ginkgo/v2 v2.19.0/go.mod h1:rlwLi9PilAFJ8jCg9UE1QP6VBpd6/xj3SRC0d6TU0To=
20352038
github.com/onsi/ginkgo/v2 v2.21.0 h1:7rg/4f3rB88pb5obDgNZrNHrQ4e6WpjonchcpuBRnZM=
20362039
github.com/onsi/ginkgo/v2 v2.21.0/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo=
@@ -2139,6 +2142,7 @@ github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4 h1:BN/Nyn2nWMo
21392142
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
21402143
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
21412144
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
2145+
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
21422146
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
21432147
github.com/rs/xid v1.2.1 h1:mhH9Nq+C1fY2l1XIpgxIiUOfNpRBYH1kKcr+qfKgjRc=
21442148
github.com/rs/zerolog v1.15.0 h1:uPRuwkWF4J6fGsJ2R0Gn2jB1EQiav9k3S6CSdygQJXY=
@@ -2179,7 +2183,6 @@ github.com/segmentio/conf v1.2.0 h1:5OT9+6OyVHLsFLsiJa/2KlqiA1m7mpdUBlkB/qYTMts=
21792183
github.com/segmentio/conf v1.2.0/go.mod h1:Y3B9O/PqqWqjyxyWWseyj/quPEtMu1zDp/kVbSWWaB0=
21802184
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
21812185
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
2182-
github.com/sethvargo/go-retry v0.3.0/go.mod h1:mNX17F0C/HguQMyMyJxcnU471gOZGxCLyYaFyAZraas=
21832186
github.com/shirou/gopsutil/v3 v3.23.2 h1:PAWSuiAszn7IhPMBtXsbSCafej7PqUOvY6YywlQUExU=
21842187
github.com/shirou/gopsutil/v3 v3.23.2/go.mod h1:gv0aQw33GLo3pG8SiWKiQrbDzbRY1K80RyZJ7V4Th1M=
21852188
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=

libs/ci/github/github.go

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -490,55 +490,7 @@ func (svc GithubService) UpdateCheckRun(checkRunId string, options GithubCheckRu
490490
opts.Conclusion = github.String(*conclusion)
491491
}
492492

493-
checkRun, resp, err := client.Checks.UpdateCheckRun(ctx, owner, repoName, checkRunIdInt64, opts)
494-
495-
// Log rate limit information
496-
if resp != nil {
497-
limit := resp.Header.Get("X-RateLimit-Limit")
498-
remaining := resp.Header.Get("X-RateLimit-Remaining")
499-
reset := resp.Header.Get("X-RateLimit-Reset")
500-
501-
if limit != "" && remaining != "" {
502-
limitInt, _ := strconv.Atoi(limit)
503-
remainingInt, _ := strconv.Atoi(remaining)
504-
505-
// Calculate percentage remaining
506-
var percentRemaining float64
507-
if limitInt > 0 {
508-
percentRemaining = (float64(remainingInt) / float64(limitInt)) * 100
509-
}
510-
511-
// Log based on severity
512-
if remainingInt == 0 {
513-
slog.Error("GitHub API rate limit EXHAUSTED",
514-
"operation", "UpdateCheckRun",
515-
"checkRunId", checkRunId,
516-
"limit", limit,
517-
"remaining", remaining,
518-
"reset", reset,
519-
"owner", owner,
520-
"repo", repoName)
521-
} else if percentRemaining < 20 {
522-
slog.Warn("GitHub API rate limit getting LOW",
523-
"operation", "UpdateCheckRun",
524-
"checkRunId", checkRunId,
525-
"limit", limit,
526-
"remaining", remaining,
527-
"percentRemaining", fmt.Sprintf("%.1f%%", percentRemaining),
528-
"reset", reset,
529-
"owner", owner,
530-
"repo", repoName)
531-
} else {
532-
slog.Debug("GitHub API rate limit status",
533-
"operation", "UpdateCheckRun",
534-
"checkRunId", checkRunId,
535-
"limit", limit,
536-
"remaining", remaining,
537-
"percentRemaining", fmt.Sprintf("%.1f%%", percentRemaining))
538-
}
539-
}
540-
}
541-
493+
checkRun, _, err := client.Checks.UpdateCheckRun(ctx, owner, repoName, checkRunIdInt64, opts)
542494
if err != nil {
543495
slog.Error("Failed to update check run",
544496
"inputCheckRunId", checkRunId,

0 commit comments

Comments
 (0)