From bba9ea4266e82afdac27030323536af245a1299f Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Tue, 5 Sep 2023 11:54:46 +0200 Subject: [PATCH] fix(prow/plugins/trigger): use git client instead of github PushEvent while checking files changed. Signed-off-by: Federico Di Pierro --- prow/plugins/trigger/push.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/prow/plugins/trigger/push.go b/prow/plugins/trigger/push.go index 5040ebe4fe37..bb3156f53018 100644 --- a/prow/plugins/trigger/push.go +++ b/prow/plugins/trigger/push.go @@ -18,6 +18,7 @@ package trigger import ( "context" + "k8s.io/test-infra/prow/git/v2" prowapi "k8s.io/test-infra/prow/apis/prowjobs/v1" "k8s.io/test-infra/prow/config" @@ -25,8 +26,17 @@ import ( "k8s.io/test-infra/prow/pjutil" ) -func listPushEventChanges(pe github.PushEvent) config.ChangedFilesProvider { +func listPushEventChanges(gc git.ClientFactory, pe github.PushEvent) config.ChangedFilesProvider { return func() ([]string, error) { + if gc != nil { + repoClient, err := gc.ClientFor(pe.Repo.Owner.Name, pe.Repo.Name) + if err != nil { + // Use git client since Github PushEvent is limited to 3000 keys: + // https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#list-pull-requests-files + return repoClient.Diff(pe.After, pe.Before) + } + } + // Fallback to use PushEvent changed := make(map[string]bool) for _, commit := range pe.Commits { for _, added := range commit.Added { @@ -74,7 +84,7 @@ func handlePE(c Client, pe github.PushEvent) error { postsubmits := getPostsubmits(c.Logger, c.GitClient, c.Config, org+"/"+repo, shaGetter) for _, j := range postsubmits { - if shouldRun, err := j.ShouldRun(pe.Branch(), listPushEventChanges(pe)); err != nil { + if shouldRun, err := j.ShouldRun(pe.Branch(), listPushEventChanges(c.GitClient, pe)); err != nil { return err } else if !shouldRun { continue