Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: fix(prow/plugins/trigger): use git client instead of github PushEvent while checking files changed #30615

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use this as a fallback method

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But how can we know when do we need to fallback? I mean, we cannot know in advance whether the Github Event contains truncated list of changed files, right?
Unless we state that if len(changedFiles) == 3000 then we must fallback to the git client method. Of course that would work for a post submit that changed exactly 3000 files too :D

Copy link
Contributor

@jmguzik jmguzik Sep 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is Idk what are the consequences of this decision and what would be the difference, but I know trigger is quite important plugin and I do not want to break it's compatibility. So either you properly test the code and prove your solution is a good a valid replacement or you just execute github version, you fail because of the limit you mentioned and then renew using git client. The github version was working up until now for most of cases.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I know trigger is quite important plugin and I do not want to break it's compatibility

💯

The github version was working up until now for most of cases.

Agree, of course!

So either you properly test the code and prove your solution is a good a valid replacement or you just execute github version, you fail because of the limit you mentioned and then renew using git client.

If only there was a way to know whether Github truncated its event, it would be fairly easy.
I will dig into that, thank you very much!

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