Skip to content

Commit

Permalink
fix(prow/plugins/trigger): use git client instead of github PushEvent…
Browse files Browse the repository at this point in the history
… while checking files changed.

Signed-off-by: Federico Di Pierro <[email protected]>
  • Loading branch information
FedeDP committed Sep 5, 2023
1 parent 1b805ca commit 128b6d4
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions prow/plugins/trigger/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,25 @@ 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"
"k8s.io/test-infra/prow/github"
"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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 128b6d4

Please sign in to comment.