@@ -5,12 +5,9 @@ import (
55 "log/slog"
66 "net/http"
77 "strconv"
8- "strings"
98
109 "github.com/diggerhq/digger/backend/models"
1110 "github.com/diggerhq/digger/backend/segment"
12- "github.com/diggerhq/digger/backend/utils"
13- "github.com/diggerhq/digger/libs/ci/github"
1411 "github.com/gin-gonic/gin"
1512 "github.com/google/uuid"
1613)
@@ -172,120 +169,9 @@ func (d DiggerController) GithubAppCallbackPage(c *gin.Context) {
172169 return
173170 }
174171
175- slog .Debug ("Getting GitHub client" ,
176- "appId" , * installation .AppID ,
177- "installationId" , installationId64 ,
178- )
179-
180- client , _ , err := d .GithubClientProvider .Get (* installation .AppID , installationId64 )
181- if err != nil {
182- slog .Error ("Error retrieving GitHub client" ,
183- "appId" , * installation .AppID ,
184- "installationId" , installationId64 ,
185- "error" , err ,
186- )
187- c .JSON (http .StatusInternalServerError , gin.H {"error" : "Error fetching organisation" })
188- return
189- }
190-
191- // we get repos accessible to this installation
192- slog .Debug ("Listing repositories for installation" , "installationId" , installationId64 )
193-
194- repos , err := github .ListGithubRepos (client )
195- if err != nil {
196- slog .Error ("Failed to list existing repositories" ,
197- "installationId" , installationId64 ,
198- "error" , err ,
199- )
200- c .String (http .StatusInternalServerError , "Failed to list existing repos: %v" , err )
201- return
202- }
203-
204- // resets all existing installations (soft delete)
205- slog .Debug ("Resetting existing GitHub installations" ,
206- "installationId" , installationId ,
207- )
208-
209- var AppInstallation models.GithubAppInstallation
210- err = models .DB .GormDB .Model (& AppInstallation ).Where ("github_installation_id=?" , installationId ).Update ("status" , models .GithubAppInstallDeleted ).Error
211- if err != nil {
212- slog .Error ("Failed to update GitHub installations" ,
213- "installationId" , installationId ,
214- "error" , err ,
215- )
216- c .String (http .StatusInternalServerError , "Failed to update github installations: %v" , err )
217- return
218- }
219-
220- // reset all existing repos (soft delete)
221- slog .Debug ("Soft deleting existing repositories" ,
222- "orgId" , orgId ,
223- )
224-
225- var ExistingRepos []models.Repo
226- err = models .DB .GormDB .Delete (ExistingRepos , "organisation_id=?" , orgId ).Error
227- if err != nil {
228- slog .Error ("Could not delete repositories" ,
229- "orgId" , orgId ,
230- "error" , err ,
231- )
232- c .String (http .StatusInternalServerError , "could not delete repos: %v" , err )
233- return
234- }
235-
236- // here we mark repos that are available one by one
237- slog .Info ("Adding repositories to organization" ,
238- "orgId" , orgId ,
239- "repoCount" , len (repos ),
240- )
241-
242- for i , repo := range repos {
243- repoFullName := * repo .FullName
244- repoOwner := strings .Split (* repo .FullName , "/" )[0 ]
245- repoName := * repo .Name
246- repoUrl := fmt .Sprintf ("https://%v/%v" , utils .GetGithubHostname (), repoFullName )
247-
248- slog .Debug ("Processing repository" ,
249- "index" , i + 1 ,
250- "repoFullName" , repoFullName ,
251- "repoOwner" , repoOwner ,
252- "repoName" , repoName ,
253- )
254-
255- _ , err := models .DB .GithubRepoAdded (
256- installationId64 ,
257- * installation .AppID ,
258- * installation .Account .Login ,
259- * installation .Account .ID ,
260- repoFullName ,
261- )
262- if err != nil {
263- slog .Error ("Error recording GitHub repository" ,
264- "repoFullName" , repoFullName ,
265- "error" , err ,
266- )
267- c .String (http .StatusInternalServerError , "github repos added error: %v" , err )
268- return
269- }
270-
271- cloneUrl := * repo .CloneURL
272- defaultBranch := * repo .DefaultBranch
273-
274- _ , _ , err = createOrGetDiggerRepoForGithubRepo (repoFullName , repoOwner , repoName , repoUrl , installationId64 , * installation .AppID , defaultBranch , cloneUrl )
275- if err != nil {
276- slog .Error ("Error creating or getting Digger repo" ,
277- "repoFullName" , repoFullName ,
278- "error" , err ,
279- )
280- c .String (http .StatusInternalServerError , "createOrGetDiggerRepoForGithubRepo error: %v" , err )
281- return
282- }
283- }
284-
285- slog .Info ("GitHub app callback processed successfully" ,
172+ slog .Info ("GitHub app callback processed" ,
286173 "installationId" , installationId64 ,
287174 "orgId" , orgId ,
288- "repoCount" , len (repos ),
289175 )
290176
291177 c .HTML (http .StatusOK , "github_success.tmpl" , gin.H {})
0 commit comments