Skip to content

Commit d181467

Browse files
authored
eliminate push event handling (#1785)
1 parent 5ecf5d1 commit d181467

File tree

1 file changed

+1
-65
lines changed

1 file changed

+1
-65
lines changed

backend/controllers/github.go

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,6 @@ func (d DiggerController) GithubAppWebHook(c *gin.Context) {
111111
c.String(http.StatusInternalServerError, err.Error())
112112
return
113113
}
114-
case *github.PushEvent:
115-
log.Printf("Got push event for %d", event.Repo.URL)
116-
err := handlePushEvent(gh, event)
117-
if err != nil {
118-
log.Printf("handlePushEvent error: %v", err)
119-
c.String(http.StatusInternalServerError, err.Error())
120-
return
121-
}
122114
default:
123115
log.Printf("Unhandled event, event type %v", reflect.TypeOf(event))
124116
}
@@ -331,62 +323,6 @@ func handleInstallationDeletedEvent(installation *github.InstallationEvent) erro
331323
return nil
332324
}
333325

334-
func handlePushEvent(gh utils.GithubClientProvider, payload *github.PushEvent) error {
335-
installationId := *payload.Installation.ID
336-
repoName := *payload.Repo.Name
337-
repoFullName := *payload.Repo.FullName
338-
repoOwner := *payload.Repo.Owner.Login
339-
cloneURL := *payload.Repo.CloneURL
340-
ref := *payload.Ref
341-
defaultBranch := *payload.Repo.DefaultBranch
342-
343-
link, err := models.DB.GetGithubAppInstallationLink(installationId)
344-
if err != nil {
345-
log.Printf("Error getting GetGithubAppInstallationLink: %v", err)
346-
return fmt.Errorf("error getting github app link")
347-
}
348-
349-
orgId := link.OrganisationId
350-
diggerRepoName := strings.ReplaceAll(repoFullName, "/", "-")
351-
repo, err := models.DB.GetRepo(orgId, diggerRepoName)
352-
if err != nil {
353-
log.Printf("Error getting Repo: %v", err)
354-
return fmt.Errorf("error getting github app link")
355-
}
356-
if repo == nil {
357-
log.Printf("Repo not found: Org: %v | repo: %v", orgId, diggerRepoName)
358-
return fmt.Errorf("Repo not found: Org: %v | repo: %v", orgId, diggerRepoName)
359-
}
360-
361-
_, token, err := utils.GetGithubService(gh, installationId, repoFullName, repoOwner, repoName)
362-
if err != nil {
363-
log.Printf("Error getting github service: %v", err)
364-
return fmt.Errorf("error getting github service")
365-
}
366-
367-
var isMainBranch bool
368-
if strings.HasSuffix(ref, defaultBranch) {
369-
isMainBranch = true
370-
} else {
371-
isMainBranch = false
372-
}
373-
374-
err = utils.CloneGitRepoAndDoAction(cloneURL, defaultBranch, *token, func(dir string) error {
375-
config, err := dg_configuration.LoadDiggerConfigYaml(dir, true, nil)
376-
if err != nil {
377-
log.Printf("ERROR load digger.yml: %v", err)
378-
return fmt.Errorf("error loading digger.yml %v", err)
379-
}
380-
models.DB.UpdateRepoDiggerConfig(link.OrganisationId, *config, repo, isMainBranch)
381-
return nil
382-
})
383-
if err != nil {
384-
return fmt.Errorf("error while cloning repo: %v", err)
385-
}
386-
387-
return nil
388-
}
389-
390326
func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullRequestEvent, ciBackendProvider ci_backends.CiBackendProvider) error {
391327
appId, err := strconv.ParseInt(os.Getenv("GITHUB_APP_ID"), 10, 64)
392328
if err != nil {
@@ -707,7 +643,7 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
707643
log.Printf("error getting github app isntallation id: %v", err)
708644
return fmt.Errorf("error getting github app installation id")
709645
}
710-
646+
711647
installationId := *payload.Installation.ID
712648
repoName := *payload.Repo.Name
713649
repoOwner := *payload.Repo.Owner.Login

0 commit comments

Comments
 (0)