Skip to content

Commit 1ba1da0

Browse files
committed
Revert "Switch from callbacks to webhooks for repos (#2466)"
This reverts commit 04b2fe8.
1 parent 04b2fe8 commit 1ba1da0

File tree

15 files changed

+196
-602
lines changed

15 files changed

+196
-602
lines changed

agent-tasks/github-webhook-repo-sync-plan.md

Lines changed: 0 additions & 43 deletions
This file was deleted.

backend/bootstrap/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ func Bootstrap(templates embed.FS, diggerController controllers.DiggerController
242242

243243
githubApiGroup := apiGroup.Group("/github")
244244
githubApiGroup.POST("/link", controllers.LinkGithubInstallationToOrgApi)
245-
githubApiGroup.POST("/resync", controllers.ResyncGithubInstallationApi)
246245

247246
vcsApiGroup := apiGroup.Group("/connections")
248247
vcsApiGroup.GET("/:id", controllers.GetVCSConnection)

backend/controllers/github.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,6 @@ func (d DiggerController) GithubAppWebHook(c *gin.Context) {
7373
c.String(http.StatusAccepted, "Failed to handle webhook event.")
7474
return
7575
}
76-
} else if *event.Action == "created" || *event.Action == "unsuspended" || *event.Action == "new_permissions_accepted" {
77-
if err := handleInstallationUpsertEvent(c.Request.Context(), gh, event, appId64); err != nil {
78-
slog.Error("Failed to handle installation upsert event", "error", err)
79-
c.String(http.StatusAccepted, "Failed to handle webhook event.")
80-
return
81-
}
82-
}
83-
case *github.InstallationRepositoriesEvent:
84-
slog.Info("Processing InstallationRepositoriesEvent",
85-
"action", event.GetAction(),
86-
"installationId", event.Installation.GetID(),
87-
"added", len(event.RepositoriesAdded),
88-
"removed", len(event.RepositoriesRemoved),
89-
)
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
9476
}
9577
case *github.PushEvent:
9678
slog.Info("Processing PushEvent",

backend/controllers/github_api.go

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ import (
88

99
"github.com/diggerhq/digger/backend/middleware"
1010
"github.com/diggerhq/digger/backend/models"
11-
"github.com/diggerhq/digger/backend/utils"
12-
ci_github "github.com/diggerhq/digger/libs/ci/github"
1311
"github.com/gin-gonic/gin"
14-
"github.com/google/go-github/v61/github"
1512
"gorm.io/gorm"
1613
)
1714

@@ -88,82 +85,3 @@ func LinkGithubInstallationToOrgApi(c *gin.Context) {
8885
c.JSON(http.StatusOK, gin.H{"status": "Successfully created Github installation link"})
8986
return
9087
}
91-
92-
func ResyncGithubInstallationApi(c *gin.Context) {
93-
type ResyncInstallationRequest struct {
94-
InstallationId string `json:"installation_id"`
95-
}
96-
97-
var request ResyncInstallationRequest
98-
if err := c.BindJSON(&request); err != nil {
99-
slog.Error("Error binding JSON for resync", "error", err)
100-
c.JSON(http.StatusBadRequest, gin.H{"status": "Invalid request format"})
101-
return
102-
}
103-
104-
installationId, err := strconv.ParseInt(request.InstallationId, 10, 64)
105-
if err != nil {
106-
slog.Error("Failed to convert InstallationId to int64", "installationId", request.InstallationId, "error", err)
107-
c.JSON(http.StatusBadRequest, gin.H{"status": "installationID should be a valid integer"})
108-
return
109-
}
110-
111-
link, err := models.DB.GetGithubAppInstallationLink(installationId)
112-
if err != nil {
113-
slog.Error("Could not get installation link for resync", "installationId", installationId, "error", err)
114-
c.JSON(http.StatusInternalServerError, gin.H{"status": "Could not get installation link"})
115-
return
116-
}
117-
if link == nil {
118-
slog.Warn("Installation link not found for resync", "installationId", installationId)
119-
c.JSON(http.StatusNotFound, gin.H{"status": "Installation link not found"})
120-
return
121-
}
122-
123-
var installationRecord models.GithubAppInstallation
124-
if err := models.DB.GormDB.Where("github_installation_id = ?", installationId).Order("updated_at desc").First(&installationRecord).Error; err != nil {
125-
if errors.Is(err, gorm.ErrRecordNotFound) {
126-
slog.Warn("No installation records found for resync", "installationId", installationId)
127-
c.JSON(http.StatusNotFound, gin.H{"status": "No installation records found"})
128-
return
129-
}
130-
slog.Error("Failed to fetch installation record for resync", "installationId", installationId, "error", err)
131-
c.JSON(http.StatusInternalServerError, gin.H{"status": "Could not fetch installation records"})
132-
return
133-
}
134-
135-
appId := installationRecord.GithubAppId
136-
ghProvider := utils.DiggerGithubRealClientProvider{}
137-
138-
client, _, err := ghProvider.Get(appId, installationId)
139-
if err != nil {
140-
slog.Error("Failed to create GitHub client for resync", "installationId", installationId, "appId", appId, "error", err)
141-
c.JSON(http.StatusInternalServerError, gin.H{"status": "Failed to create GitHub client"})
142-
return
143-
}
144-
145-
repos, err := ci_github.ListGithubRepos(client)
146-
if err != nil {
147-
slog.Error("Failed to list repos for resync", "installationId", installationId, "error", err)
148-
c.JSON(http.StatusInternalServerError, gin.H{"status": "Failed to list repos for resync"})
149-
return
150-
}
151-
152-
installationPayload := &github.Installation{
153-
ID: github.Int64(installationId),
154-
AppID: github.Int64(appId),
155-
}
156-
resyncEvent := &github.InstallationEvent{
157-
Installation: installationPayload,
158-
Repositories: repos,
159-
}
160-
161-
if err := handleInstallationUpsertEvent(c.Request.Context(), ghProvider, resyncEvent, appId); err != nil {
162-
slog.Error("Resync failed", "installationId", installationId, "error", err)
163-
c.JSON(http.StatusInternalServerError, gin.H{"status": "Resync failed"})
164-
return
165-
}
166-
167-
slog.Info("Resync completed", "installationId", installationId, "repoCount", len(repos))
168-
c.JSON(http.StatusOK, gin.H{"status": "Resync completed", "repoCount": len(repos)})
169-
}

0 commit comments

Comments
 (0)