From fd7ce56567a9b5ba1a1fd901d50936d4a0718a72 Mon Sep 17 00:00:00 2001 From: Steve Kuznetsov Date: Tue, 19 Nov 2019 08:07:35 -0800 Subject: [PATCH] git: refactor to use v1 clients adapted to v2 interfaces This is a large commit but it's mechanical: - update the import from git to git/v2 - change Clone(name) to ClientFor(org, repo) Signed-off-by: Steve Kuznetsov --- prow/cmd/deck/BUILD.bazel | 3 +-- prow/cmd/deck/main.go | 11 ++++++----- prow/cmd/deck/pr_history.go | 6 +++--- prow/cmd/deck/pr_history_test.go | 3 +-- prow/cmd/hook/BUILD.bazel | 1 + prow/cmd/hook/main.go | 5 +++-- prow/cmd/tide/BUILD.bazel | 1 + prow/cmd/tide/main.go | 3 ++- prow/config/BUILD.bazel | 3 +-- prow/config/config.go | 4 ++-- prow/config/tide.go | 4 ++-- prow/config/tide_test.go | 3 +-- prow/external-plugins/cherrypicker/BUILD.bazel | 2 +- prow/external-plugins/cherrypicker/main.go | 3 ++- prow/external-plugins/cherrypicker/server.go | 8 ++++---- prow/git/git_test.go | 14 +++++++------- prow/git/localgit/BUILD.bazel | 5 ++++- prow/git/localgit/localgit.go | 7 ++++--- prow/git/v2/adapter.go | 12 +++++++++++- prow/plugins/BUILD.bazel | 2 +- prow/plugins/buildifier/BUILD.bazel | 2 +- prow/plugins/buildifier/buildifier.go | 8 ++++---- prow/plugins/golint/BUILD.bazel | 2 +- prow/plugins/golint/golint.go | 10 +++++----- prow/plugins/mergecommitblocker/BUILD.bazel | 2 +- .../mergecommitblocker/mergecommitblocker.go | 6 +++--- prow/plugins/override/BUILD.bazel | 2 +- prow/plugins/override/override.go | 4 ++-- prow/plugins/plugins.go | 6 +++--- prow/plugins/skip/BUILD.bazel | 3 +-- prow/plugins/skip/skip.go | 4 ++-- prow/plugins/skip/skip_test.go | 3 +-- prow/plugins/trigger/BUILD.bazel | 3 +-- prow/plugins/trigger/generic-comment_test.go | 3 +-- prow/plugins/trigger/pull-request_test.go | 3 +-- prow/plugins/trigger/trigger.go | 4 ++-- prow/plugins/trigger/trigger_test.go | 3 +-- prow/plugins/updateconfig/BUILD.bazel | 4 ++-- prow/plugins/updateconfig/updateconfig.go | 11 +++-------- prow/plugins/updateconfig/updateconfig_test.go | 4 ++-- prow/plugins/verify-owners/BUILD.bazel | 2 +- prow/plugins/verify-owners/verify-owners.go | 8 ++++---- prow/plugins/verify-owners/verify-owners_test.go | 2 +- prow/repoowners/BUILD.bazel | 2 +- prow/repoowners/repoowners.go | 10 +++++----- prow/tide/BUILD.bazel | 3 +-- prow/tide/status.go | 6 +++--- prow/tide/tide.go | 12 ++++++------ prow/tide/tide_test.go | 9 ++++----- 49 files changed, 122 insertions(+), 119 deletions(-) diff --git a/prow/cmd/deck/BUILD.bazel b/prow/cmd/deck/BUILD.bazel index 215da0988b813..4cc5385be25f2 100644 --- a/prow/cmd/deck/BUILD.bazel +++ b/prow/cmd/deck/BUILD.bazel @@ -66,7 +66,6 @@ go_test( "//prow/client/clientset/versioned/fake:go_default_library", "//prow/config:go_default_library", "//prow/flagutil:go_default_library", - "//prow/git:go_default_library", "//prow/github:go_default_library", "//prow/github/fakegithub:go_default_library", "//prow/githuboauth:go_default_library", @@ -115,7 +114,7 @@ go_library( "//prow/errorutil:go_default_library", "//prow/flagutil:go_default_library", "//prow/gcsupload:go_default_library", - "//prow/git:go_default_library", + "//prow/git/v2:go_default_library", "//prow/github:go_default_library", "//prow/githuboauth:go_default_library", "//prow/interrupts:go_default_library", diff --git a/prow/cmd/deck/main.go b/prow/cmd/deck/main.go index 1d4336727d8bd..bb6c1f0e45d9e 100644 --- a/prow/cmd/deck/main.go +++ b/prow/cmd/deck/main.go @@ -61,7 +61,7 @@ import ( "k8s.io/test-infra/prow/config/secret" "k8s.io/test-infra/prow/deck/jobs" prowflagutil "k8s.io/test-infra/prow/flagutil" - "k8s.io/test-infra/prow/git" + "k8s.io/test-infra/prow/git/v2" prowgithub "k8s.io/test-infra/prow/github" "k8s.io/test-infra/prow/githuboauth" "k8s.io/test-infra/prow/kube" @@ -581,7 +581,7 @@ func prodOnlyMain(cfg config.Getter, pluginAgent *plugins.ConfigAgent, o options // When inrepoconfig is enabled, both the GitHubClient and the gitClient are used to resolve // presubmits dynamically which we need for the PR history page. var githubClient deckGitHubClient - var gitClient *git.Client + var gitClient git.ClientFactory secretAgent := &secret.Agent{} if o.github.TokenPath != "" { if err := secretAgent.Start([]string{o.github.TokenPath}); err != nil { @@ -591,10 +591,11 @@ func prodOnlyMain(cfg config.Getter, pluginAgent *plugins.ConfigAgent, o options if err != nil { logrus.WithError(err).Fatal("Error getting GitHub client.") } - gitClient, err = o.github.GitClient(secretAgent, o.dryRun) + g, err := o.github.GitClient(secretAgent, o.dryRun) if err != nil { logrus.WithError(err).Fatal("Error getting Git client.") } + gitClient = git.ClientFactoryFrom(g) } if o.spyglass { @@ -709,7 +710,7 @@ func prodOnlyMain(cfg config.Getter, pluginAgent *plugins.ConfigAgent, o options return mux } -func initSpyglass(cfg config.Getter, o options, mux *http.ServeMux, ja *jobs.JobAgent, gitHubClient deckGitHubClient, gitClient *git.Client) { +func initSpyglass(cfg config.Getter, o options, mux *http.ServeMux, ja *jobs.JobAgent, gitHubClient deckGitHubClient, gitClient git.ClientFactory) { var c *storage.Client var err error if o.gcsCredentialsFile == "" { @@ -896,7 +897,7 @@ func handleJobHistory(o options, cfg config.Getter, gcsClient *storage.Client, l // The url must look like this: // // /pr-history?org=&repo=&pr= -func handlePRHistory(o options, cfg config.Getter, gcsClient *storage.Client, gitHubClient deckGitHubClient, gitClient *git.Client, log *logrus.Entry) http.HandlerFunc { +func handlePRHistory(o options, cfg config.Getter, gcsClient *storage.Client, gitHubClient deckGitHubClient, gitClient git.ClientFactory, log *logrus.Entry) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { setHeadersNoCaching(w) tmpl, err := getPRHistory(r.URL, cfg(), gcsClient, gitHubClient, gitClient) diff --git a/prow/cmd/deck/pr_history.go b/prow/cmd/deck/pr_history.go index 3ab73bf337fa4..595325c05cafc 100644 --- a/prow/cmd/deck/pr_history.go +++ b/prow/cmd/deck/pr_history.go @@ -32,7 +32,7 @@ import ( v1 "k8s.io/test-infra/prow/apis/prowjobs/v1" "k8s.io/test-infra/prow/config" "k8s.io/test-infra/prow/gcsupload" - "k8s.io/test-infra/prow/git" + "k8s.io/test-infra/prow/git/v2" "k8s.io/test-infra/prow/pod-utils/downwardapi" ) @@ -202,7 +202,7 @@ func parsePullURL(u *url.URL) (org, repo string, pr int, err error) { } // getGCSDirsForPR returns a map from bucket names -> set of "directories" containing presubmit data -func getGCSDirsForPR(c *config.Config, gitHubClient deckGitHubClient, gitClient *git.Client, org, repo string, prNumber int) (map[string]sets.String, error) { +func getGCSDirsForPR(c *config.Config, gitHubClient deckGitHubClient, gitClient git.ClientFactory, org, repo string, prNumber int) (map[string]sets.String, error) { toSearch := make(map[string]sets.String) fullRepo := org + "/" + repo @@ -244,7 +244,7 @@ func getGCSDirsForPR(c *config.Config, gitHubClient deckGitHubClient, gitClient return toSearch, nil } -func getPRHistory(url *url.URL, config *config.Config, gcsClient *storage.Client, gitHubClient deckGitHubClient, gitClient *git.Client) (prHistoryTemplate, error) { +func getPRHistory(url *url.URL, config *config.Config, gcsClient *storage.Client, gitHubClient deckGitHubClient, gitClient git.ClientFactory) (prHistoryTemplate, error) { start := time.Now() template := prHistoryTemplate{} diff --git a/prow/cmd/deck/pr_history_test.go b/prow/cmd/deck/pr_history_test.go index 93de48ba6bb85..7493b8e814735 100644 --- a/prow/cmd/deck/pr_history_test.go +++ b/prow/cmd/deck/pr_history_test.go @@ -28,7 +28,6 @@ import ( "k8s.io/apimachinery/pkg/util/sets" prowapi "k8s.io/test-infra/prow/apis/prowjobs/v1" "k8s.io/test-infra/prow/config" - "k8s.io/test-infra/prow/git" "k8s.io/test-infra/prow/github" "k8s.io/test-infra/prow/github/fakegithub" ) @@ -425,7 +424,7 @@ func TestGetGCSDirsForPR(t *testing.T) { 123: {Number: 123}, }, } - toSearch, err := getGCSDirsForPR(tc.config, gitHubClient, &git.Client{}, tc.org, tc.repo, tc.pr) + toSearch, err := getGCSDirsForPR(tc.config, gitHubClient, nil, tc.org, tc.repo, tc.pr) if (err != nil) != tc.expErr { t.Errorf("%s: unexpected error %v", tc.name, err) } diff --git a/prow/cmd/hook/BUILD.bazel b/prow/cmd/hook/BUILD.bazel index de550ca54e528..7da50f6453f03 100644 --- a/prow/cmd/hook/BUILD.bazel +++ b/prow/cmd/hook/BUILD.bazel @@ -43,6 +43,7 @@ go_library( "//prow/config:go_default_library", "//prow/config/secret:go_default_library", "//prow/flagutil:go_default_library", + "//prow/git/v2:go_default_library", "//prow/hook:go_default_library", "//prow/interrupts:go_default_library", "//prow/logrusutil:go_default_library", diff --git a/prow/cmd/hook/main.go b/prow/cmd/hook/main.go index 14cff549bff8b..fa122acfadb2b 100644 --- a/prow/cmd/hook/main.go +++ b/prow/cmd/hook/main.go @@ -18,6 +18,7 @@ package main import ( "flag" + "k8s.io/test-infra/prow/git/v2" "net/http" "os" "strconv" @@ -180,14 +181,14 @@ func main() { ownersDirBlacklist := func() config.OwnersDirBlacklist { return configAgent.Config().OwnersDirBlacklist } - ownersClient := repoowners.NewClient(gitClient, githubClient, mdYAMLEnabled, skipCollaborators, ownersDirBlacklist) + ownersClient := repoowners.NewClient(git.ClientFactoryFrom(gitClient), githubClient, mdYAMLEnabled, skipCollaborators, ownersDirBlacklist) clientAgent := &plugins.ClientAgent{ GitHubClient: githubClient, ProwJobClient: prowJobClient, KubernetesClient: infrastructureClient, BuildClusterCoreV1Clients: buildClusterCoreV1Clients, - GitClient: gitClient, + GitClient: git.ClientFactoryFrom(gitClient), SlackClient: slackClient, OwnersClient: ownersClient, BugzillaClient: bugzillaClient, diff --git a/prow/cmd/tide/BUILD.bazel b/prow/cmd/tide/BUILD.bazel index 0f4de0d25be4a..bb8fe86c928bd 100644 --- a/prow/cmd/tide/BUILD.bazel +++ b/prow/cmd/tide/BUILD.bazel @@ -18,6 +18,7 @@ go_library( "//prow/config:go_default_library", "//prow/config/secret:go_default_library", "//prow/flagutil:go_default_library", + "//prow/git/v2:go_default_library", "//prow/interrupts:go_default_library", "//prow/logrusutil:go_default_library", "//prow/metrics:go_default_library", diff --git a/prow/cmd/tide/main.go b/prow/cmd/tide/main.go index 2c20af3c4e06e..745dbfd17b358 100644 --- a/prow/cmd/tide/main.go +++ b/prow/cmd/tide/main.go @@ -19,6 +19,7 @@ package main import ( "context" "flag" + "k8s.io/test-infra/prow/git/v2" "net/http" "os" "strconv" @@ -170,7 +171,7 @@ func main() { if err != nil { logrus.WithError(err).Fatal("Error constructing mgr.") } - c, err := tide.NewController(githubSync, githubStatus, mgr, cfg, gitClient, o.maxRecordsPerPool, opener, o.historyURI, o.statusURI, nil) + c, err := tide.NewController(githubSync, githubStatus, mgr, cfg, git.ClientFactoryFrom(gitClient), o.maxRecordsPerPool, opener, o.historyURI, o.statusURI, nil) if err != nil { logrus.WithError(err).Fatal("Error creating Tide controller.") } diff --git a/prow/config/BUILD.bazel b/prow/config/BUILD.bazel index 6cc1b330ebd61..f7cf2927ad91d 100644 --- a/prow/config/BUILD.bazel +++ b/prow/config/BUILD.bazel @@ -22,7 +22,6 @@ go_test( deps = [ "//prow/apis/prowjobs/v1:go_default_library", "//prow/config/secret:go_default_library", - "//prow/git:go_default_library", "//prow/github:go_default_library", "//prow/github/fakegithub:go_default_library", "//prow/kube:go_default_library", @@ -49,7 +48,7 @@ go_library( importpath = "k8s.io/test-infra/prow/config", deps = [ "//prow/apis/prowjobs/v1:go_default_library", - "//prow/git:go_default_library", + "//prow/git/v2:go_default_library", "//prow/github:go_default_library", "//prow/kube:go_default_library", "//prow/pod-utils/decorate:go_default_library", diff --git a/prow/config/config.go b/prow/config/config.go index 2a022c7cd72c5..de01aee2f171d 100644 --- a/prow/config/config.go +++ b/prow/config/config.go @@ -46,7 +46,7 @@ import ( pipelinev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" prowapi "k8s.io/test-infra/prow/apis/prowjobs/v1" - "k8s.io/test-infra/prow/git" + "k8s.io/test-infra/prow/git/v2" "k8s.io/test-infra/prow/github" "k8s.io/test-infra/prow/kube" "k8s.io/test-infra/prow/pod-utils/decorate" @@ -272,7 +272,7 @@ func (rg *RefGetterForGitHubPullRequest) BaseSHA() (string, error) { // Consumers that pass in a RefGetter implementation that does a call to GitHub and who // also need the result of that GitHub call just keep a pointer to its result, bust must // nilcheck that pointer before accessing it. -func (c *Config) GetPresubmits(gc *git.Client, identifier string, baseSHAGetter RefGetter, headSHAGetters ...RefGetter) ([]Presubmit, error) { +func (c *Config) GetPresubmits(gc git.ClientFactory, identifier string, baseSHAGetter RefGetter, headSHAGetters ...RefGetter) ([]Presubmit, error) { if identifier == "" { return nil, errors.New("no identifier for repo given") } diff --git a/prow/config/tide.go b/prow/config/tide.go index aa183c6d644f3..be001c83c7a72 100644 --- a/prow/config/tide.go +++ b/prow/config/tide.go @@ -27,7 +27,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/sets" - "k8s.io/test-infra/prow/git" + "k8s.io/test-infra/prow/git/v2" "k8s.io/test-infra/prow/github" ) @@ -489,7 +489,7 @@ func parseTideContextPolicyOptions(org, repo, branch string, options TideContext // GetTideContextPolicy parses the prow config to find context merge options. // If none are set, it will use the prow jobs configured and use the default github combined status. // Otherwise if set it will use the branch protection setting, or the listed jobs. -func (c Config) GetTideContextPolicy(gitClient *git.Client, org, repo, branch string, baseSHAGetter RefGetter, headSHA string) (*TideContextPolicy, error) { +func (c Config) GetTideContextPolicy(gitClient git.ClientFactory, org, repo, branch string, baseSHAGetter RefGetter, headSHA string) (*TideContextPolicy, error) { options := parseTideContextPolicyOptions(org, repo, branch, c.Tide.ContextOptions) // Adding required and optional contexts from options required := sets.NewString(options.RequiredContexts...) diff --git a/prow/config/tide_test.go b/prow/config/tide_test.go index 54a95695d64d6..c3353b3a1e643 100644 --- a/prow/config/tide_test.go +++ b/prow/config/tide_test.go @@ -23,7 +23,6 @@ import ( "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/sets" - "k8s.io/test-infra/prow/git" "k8s.io/test-infra/prow/github" "k8s.io/test-infra/prow/labels" ) @@ -573,7 +572,7 @@ func TestConfigGetTideContextPolicy(t *testing.T) { baseSHAGetter := func() (string, error) { return "baseSHA", nil } - p, err := tc.config.GetTideContextPolicy(&git.Client{}, org, repo, branch, baseSHAGetter, "some-sha") + p, err := tc.config.GetTideContextPolicy(nil, org, repo, branch, baseSHAGetter, "some-sha") if !reflect.DeepEqual(p, &tc.expected) { t.Errorf("%s - did not get expected policy: %s", tc.name, diff.ObjectReflectDiff(&tc.expected, p)) } diff --git a/prow/external-plugins/cherrypicker/BUILD.bazel b/prow/external-plugins/cherrypicker/BUILD.bazel index aa7ee557da5d6..17db9d44e9617 100644 --- a/prow/external-plugins/cherrypicker/BUILD.bazel +++ b/prow/external-plugins/cherrypicker/BUILD.bazel @@ -13,7 +13,7 @@ go_library( "//pkg/flagutil:go_default_library", "//prow/config/secret:go_default_library", "//prow/flagutil:go_default_library", - "//prow/git:go_default_library", + "//prow/git/v2:go_default_library", "//prow/github:go_default_library", "//prow/interrupts:go_default_library", "//prow/pluginhelp:go_default_library", diff --git a/prow/external-plugins/cherrypicker/main.go b/prow/external-plugins/cherrypicker/main.go index 31b6aeaa6add1..d1ff36ad433f0 100644 --- a/prow/external-plugins/cherrypicker/main.go +++ b/prow/external-plugins/cherrypicker/main.go @@ -29,6 +29,7 @@ import ( "k8s.io/test-infra/pkg/flagutil" "k8s.io/test-infra/prow/config/secret" prowflagutil "k8s.io/test-infra/prow/flagutil" + "k8s.io/test-infra/prow/git/v2" "k8s.io/test-infra/prow/pluginhelp/externalplugins" ) @@ -117,7 +118,7 @@ func main() { botName: botName, email: email, - gc: gitClient, + gc: git.ClientFactoryFrom(gitClient), ghc: githubClient, log: log, diff --git a/prow/external-plugins/cherrypicker/server.go b/prow/external-plugins/cherrypicker/server.go index b04aee5be0f36..1bbda12858321 100644 --- a/prow/external-plugins/cherrypicker/server.go +++ b/prow/external-plugins/cherrypicker/server.go @@ -30,7 +30,7 @@ import ( "github.com/sirupsen/logrus" - "k8s.io/test-infra/prow/git" + "k8s.io/test-infra/prow/git/v2" "k8s.io/test-infra/prow/github" "k8s.io/test-infra/prow/pluginhelp" "k8s.io/test-infra/prow/plugins" @@ -79,7 +79,7 @@ type Server struct { botName string email string - gc *git.Client + gc git.ClientFactory // Used for unit testing push func(newBranch string) error ghc githubClient @@ -358,7 +358,7 @@ func (s *Server) handle(l *logrus.Entry, requestor string, comment *github.Issue // Clone the repo, checkout the target branch. startClone := time.Now() - r, err := s.gc.Clone(org, repo) + r, err := s.gc.ClientFor(org, repo) if err != nil { return err } @@ -422,7 +422,7 @@ func (s *Server) handle(l *logrus.Entry, requestor string, comment *github.Issue return s.createComment(org, repo, num, comment, resp) } - push := r.Push + push := r.ForcePush if s.push != nil { push = s.push } diff --git a/prow/git/git_test.go b/prow/git/git_test.go index 5c66da261d6ae..eea61b8fa0ffa 100644 --- a/prow/git/git_test.go +++ b/prow/git/git_test.go @@ -51,7 +51,7 @@ func TestClone(t *testing.T) { } // Fresh clone, will be a cache miss. - r1, err := c.Clone("foo", "bar") + r1, err := c.ClientFor("foo", "bar") if err != nil { t.Fatalf("Cloning the first time: %v", err) } @@ -62,7 +62,7 @@ func TestClone(t *testing.T) { }() // Clone from the same org. - r2, err := c.Clone("foo", "baz") + r2, err := c.ClientFor("foo", "baz") if err != nil { t.Fatalf("Cloning another repo in the same org: %v", err) } @@ -76,7 +76,7 @@ func TestClone(t *testing.T) { if err := lg.AddCommit("foo", "bar", map[string][]byte{"second": {}}); err != nil { t.Fatalf("Adding second commit: %v", err) } - r3, err := c.Clone("foo", "bar") + r3, err := c.ClientFor("foo", "bar") if err != nil { t.Fatalf("Cloning a second time: %v", err) } @@ -113,7 +113,7 @@ func TestCheckoutPR(t *testing.T) { if err := lg.MakeFakeRepo("foo", "bar"); err != nil { t.Fatalf("Making fake repo: %v", err) } - r, err := c.Clone("foo", "bar") + r, err := c.ClientFor("foo", "bar") if err != nil { t.Fatalf("Cloning: %v", err) } @@ -154,7 +154,7 @@ func TestMergeCommitsExistBetween(t *testing.T) { if err := lg.MakeFakeRepo("foo", "bar"); err != nil { t.Fatalf("Making fake repo: %v", err) } - r, err := c.Clone("foo", "bar") + r, err := c.ClientFor("foo", "bar") if err != nil { t.Fatalf("Cloning: %v", err) } @@ -368,7 +368,7 @@ func TestMergeAndCheckout(t *testing.T) { } } - clonedRepo, err := c.Clone(org, repo) + clonedRepo, err := c.ClientFor(org, repo) if err != nil { t.Fatalf("Cloning failed: %v", err) } @@ -382,7 +382,7 @@ func TestMergeAndCheckout(t *testing.T) { t.Fatalf("failed to disable gpg signing for test repo: %v", err) } - err = clonedRepo.MergeAndCheckout(baseSHA, commitsToMerge, tc.mergeStrategy) + err = clonedRepo.MergeAndCheckout(baseSHA, commitsToMerge, string(tc.mergeStrategy)) if err == nil && tc.err == "" { return } diff --git a/prow/git/localgit/BUILD.bazel b/prow/git/localgit/BUILD.bazel index aed3eb6680cdb..87ddadd427d68 100644 --- a/prow/git/localgit/BUILD.bazel +++ b/prow/git/localgit/BUILD.bazel @@ -9,7 +9,10 @@ go_library( name = "go_default_library", srcs = ["localgit.go"], importpath = "k8s.io/test-infra/prow/git/localgit", - deps = ["//prow/git:go_default_library"], + deps = [ + "//prow/git:go_default_library", + "//prow/git/v2:go_default_library", + ], ) filegroup( diff --git a/prow/git/localgit/localgit.go b/prow/git/localgit/localgit.go index 7f72cc798423f..f292cfe5d9fd8 100644 --- a/prow/git/localgit/localgit.go +++ b/prow/git/localgit/localgit.go @@ -27,6 +27,7 @@ import ( "strings" "k8s.io/test-infra/prow/git" + v2 "k8s.io/test-infra/prow/git/v2" ) // LocalGit stores the repos in a temp dir. Create with New and delete with @@ -38,8 +39,8 @@ type LocalGit struct { Git string } -// New creates a LocalGit and a git.Client pointing at it. -func New() (*LocalGit, *git.Client, error) { +// New creates a LocalGit and a client factory from a git.Client pointing at it. +func New() (*LocalGit, v2.ClientFactory, error) { g, err := exec.LookPath("git") if err != nil { return nil, nil, err @@ -64,7 +65,7 @@ func New() (*LocalGit, *git.Client, error) { return &LocalGit{ Dir: t, Git: g, - }, c, nil + }, v2.ClientFactoryFrom(c), nil } // Clean deletes the local git dir. diff --git a/prow/git/v2/adapter.go b/prow/git/v2/adapter.go index 625be83197d8f..05f8a22727a4f 100644 --- a/prow/git/v2/adapter.go +++ b/prow/git/v2/adapter.go @@ -2,11 +2,21 @@ package git import ( "errors" + "fmt" + "strings" "k8s.io/test-infra/prow/git" "k8s.io/test-infra/prow/github" ) +func OrgRepo(full string) (string, string, error) { + if strings.Count(full, "/") != 1 { + return "", "", fmt.Errorf("full repo name %s does not follow the org/repo format", full) + } + parts := strings.Split(full, "/") + return parts[0], parts[1], nil +} + // ClientFactoryFrom adapts the v1 client to a v2 client func ClientFactoryFrom(c *git.Client) ClientFactory { return &clientFactoryAdapter{Client: c} @@ -49,7 +59,7 @@ func (a *repoClientAdapter) Commit(title, body string) error { } func (a *repoClientAdapter) ForcePush(branch string) error { - return errors.New("no ForcePush implementation exists in the v1 repo client") + return a.Repo.Push(branch) } func (a *repoClientAdapter) MirrorClone() error { diff --git a/prow/plugins/BUILD.bazel b/prow/plugins/BUILD.bazel index 80146a4defb94..bed025ff497af 100644 --- a/prow/plugins/BUILD.bazel +++ b/prow/plugins/BUILD.bazel @@ -37,7 +37,7 @@ go_library( "//prow/commentpruner:go_default_library", "//prow/config:go_default_library", "//prow/errorutil:go_default_library", - "//prow/git:go_default_library", + "//prow/git/v2:go_default_library", "//prow/github:go_default_library", "//prow/kube:go_default_library", "//prow/labels:go_default_library", diff --git a/prow/plugins/buildifier/BUILD.bazel b/prow/plugins/buildifier/BUILD.bazel index 02dd05437a13a..4dbd5237600a1 100644 --- a/prow/plugins/buildifier/BUILD.bazel +++ b/prow/plugins/buildifier/BUILD.bazel @@ -12,7 +12,7 @@ go_library( importpath = "k8s.io/test-infra/prow/plugins/buildifier", deps = [ "//prow/genfiles:go_default_library", - "//prow/git:go_default_library", + "//prow/git/v2:go_default_library", "//prow/github:go_default_library", "//prow/pluginhelp:go_default_library", "//prow/plugins:go_default_library", diff --git a/prow/plugins/buildifier/buildifier.go b/prow/plugins/buildifier/buildifier.go index 91ccd4c7ffa1d..bbbb10273e65a 100644 --- a/prow/plugins/buildifier/buildifier.go +++ b/prow/plugins/buildifier/buildifier.go @@ -32,7 +32,7 @@ import ( "github.com/sirupsen/logrus" "k8s.io/test-infra/prow/genfiles" - "k8s.io/test-infra/prow/git" + "k8s.io/test-infra/prow/git/v2" "k8s.io/test-infra/prow/github" "k8s.io/test-infra/prow/pluginhelp" "k8s.io/test-infra/prow/plugins" @@ -124,7 +124,7 @@ func uniqProblems(problems []string) []string { // problemsInFiles runs buildifier on the files. It returns a map from the file to // a list of problems with that file. -func problemsInFiles(r *git.Repo, files map[string]string) (map[string][]string, error) { +func problemsInFiles(r git.RepoClient, files map[string]string) (map[string][]string, error) { problems := make(map[string][]string) for f := range files { src, err := ioutil.ReadFile(filepath.Join(r.Directory(), f)) @@ -149,7 +149,7 @@ func problemsInFiles(r *git.Repo, files map[string]string) (map[string][]string, return problems, nil } -func handle(ghc githubClient, gc *git.Client, log *logrus.Entry, e *github.GenericCommentEvent) error { +func handle(ghc githubClient, gc git.ClientFactory, log *logrus.Entry, e *github.GenericCommentEvent) error { // Only handle open PRs and new requests. if e.IssueState != "open" || !e.IsPR || e.Action != github.GenericCommentActionCreated { return nil @@ -178,7 +178,7 @@ func handle(ghc githubClient, gc *git.Client, log *logrus.Entry, e *github.Gener // Clone the repo, checkout the PR. startClone := time.Now() - r, err := gc.Clone(org, repo) + r, err := gc.ClientFor(org, repo) if err != nil { return err } diff --git a/prow/plugins/golint/BUILD.bazel b/prow/plugins/golint/BUILD.bazel index 5325fabea18af..ab2d3dd8df390 100644 --- a/prow/plugins/golint/BUILD.bazel +++ b/prow/plugins/golint/BUILD.bazel @@ -24,7 +24,7 @@ go_library( importpath = "k8s.io/test-infra/prow/plugins/golint", deps = [ "//prow/genfiles:go_default_library", - "//prow/git:go_default_library", + "//prow/git/v2:go_default_library", "//prow/github:go_default_library", "//prow/pluginhelp:go_default_library", "//prow/plugins:go_default_library", diff --git a/prow/plugins/golint/golint.go b/prow/plugins/golint/golint.go index 6b033344f6327..673e3a73c055d 100644 --- a/prow/plugins/golint/golint.go +++ b/prow/plugins/golint/golint.go @@ -29,7 +29,7 @@ import ( "golang.org/x/lint" "k8s.io/test-infra/prow/genfiles" - "k8s.io/test-infra/prow/git" + "k8s.io/test-infra/prow/git/v2" "k8s.io/test-infra/prow/github" "k8s.io/test-infra/prow/pluginhelp" "k8s.io/test-infra/prow/plugins" @@ -141,7 +141,7 @@ func newProblems(cs []github.ReviewComment, ps map[string]map[int]lint.Problem) // problemsInFiles runs golint on the files. It returns a map from the file to // a map from the line in the patch to the problem. -func problemsInFiles(r *git.Repo, files map[string]string) (map[string]map[int]lint.Problem, []github.DraftReviewComment) { +func problemsInFiles(r git.RepoClient, files map[string]string) (map[string]map[int]lint.Problem, []github.DraftReviewComment) { problems := make(map[string]map[int]lint.Problem) var lintErrorComments []github.DraftReviewComment l := new(lint.Linter) @@ -196,7 +196,7 @@ func problemsInFiles(r *git.Repo, files map[string]string) (map[string]map[int]l return problems, lintErrorComments } -func handle(minimumConfidence float64, ghc githubClient, gc *git.Client, log *logrus.Entry, e *github.GenericCommentEvent) error { +func handle(minimumConfidence float64, ghc githubClient, gc git.ClientFactory, log *logrus.Entry, e *github.GenericCommentEvent) error { // Only handle open PRs and new requests. if e.IssueState != "open" || !e.IsPR || e.Action != github.GenericCommentActionCreated { return nil @@ -225,7 +225,7 @@ func handle(minimumConfidence float64, ghc githubClient, gc *git.Client, log *lo // Clone the repo, checkout the PR. startClone := time.Now() - r, err := gc.Clone(org, repo) + r, err := gc.ClientFor(org, repo) if err != nil { return err } @@ -265,7 +265,7 @@ func handle(minimumConfidence float64, ghc githubClient, gc *git.Client, log *lo } // Make the list of comments. - var comments []github.DraftReviewComment = lintErrorComments + var comments = lintErrorComments for f, ls := range nps { for l, p := range ls { var suggestion = suggestion.SuggestCodeChange(p) diff --git a/prow/plugins/mergecommitblocker/BUILD.bazel b/prow/plugins/mergecommitblocker/BUILD.bazel index 644575acd99b1..62c2f54015ce9 100644 --- a/prow/plugins/mergecommitblocker/BUILD.bazel +++ b/prow/plugins/mergecommitblocker/BUILD.bazel @@ -6,7 +6,7 @@ go_library( importpath = "k8s.io/test-infra/prow/plugins/mergecommitblocker", visibility = ["//visibility:public"], deps = [ - "//prow/git:go_default_library", + "//prow/git/v2:go_default_library", "//prow/github:go_default_library", "//prow/labels:go_default_library", "//prow/pluginhelp:go_default_library", diff --git a/prow/plugins/mergecommitblocker/mergecommitblocker.go b/prow/plugins/mergecommitblocker/mergecommitblocker.go index 0ce5936d4430e..9a9885b1eee3e 100644 --- a/prow/plugins/mergecommitblocker/mergecommitblocker.go +++ b/prow/plugins/mergecommitblocker/mergecommitblocker.go @@ -22,7 +22,7 @@ import ( "github.com/sirupsen/logrus" - "k8s.io/test-infra/prow/git" + "k8s.io/test-infra/prow/git/v2" "k8s.io/test-infra/prow/github" "k8s.io/test-infra/prow/labels" "k8s.io/test-infra/prow/pluginhelp" @@ -75,7 +75,7 @@ func handlePullRequest(pc plugins.Agent, pre github.PullRequestEvent) error { return handle(pc.GitHubClient, pc.GitClient, cp, pc.Logger, &pre) } -func handle(ghc githubClient, gc *git.Client, cp pruneClient, log *logrus.Entry, pre *github.PullRequestEvent) error { +func handle(ghc githubClient, gc git.ClientFactory, cp pruneClient, log *logrus.Entry, pre *github.PullRequestEvent) error { var ( org = pre.PullRequest.Base.Repo.Owner.Login repo = pre.PullRequest.Base.Repo.Name @@ -83,7 +83,7 @@ func handle(ghc githubClient, gc *git.Client, cp pruneClient, log *logrus.Entry, ) // Clone the repo, checkout the PR. - r, err := gc.Clone(org, repo) + r, err := gc.ClientFor(org, repo) if err != nil { return err } diff --git a/prow/plugins/override/BUILD.bazel b/prow/plugins/override/BUILD.bazel index 297c086b6160e..8893d72ffb471 100644 --- a/prow/plugins/override/BUILD.bazel +++ b/prow/plugins/override/BUILD.bazel @@ -8,7 +8,7 @@ go_library( deps = [ "//prow/apis/prowjobs/v1:go_default_library", "//prow/config:go_default_library", - "//prow/git:go_default_library", + "//prow/git/v2:go_default_library", "//prow/github:go_default_library", "//prow/pjutil:go_default_library", "//prow/pluginhelp:go_default_library", diff --git a/prow/plugins/override/override.go b/prow/plugins/override/override.go index a1e676d1b1a66..810defe2e7b22 100644 --- a/prow/plugins/override/override.go +++ b/prow/plugins/override/override.go @@ -28,7 +28,7 @@ import ( prowapi "k8s.io/test-infra/prow/apis/prowjobs/v1" "k8s.io/test-infra/prow/config" - "k8s.io/test-infra/prow/git" + "k8s.io/test-infra/prow/git/v2" "k8s.io/test-infra/prow/github" "k8s.io/test-infra/prow/pjutil" "k8s.io/test-infra/prow/pluginhelp" @@ -70,7 +70,7 @@ type overrideClient interface { type client struct { ghc githubClient - gc *git.Client + gc git.ClientFactory config *config.Config ownersClient ownersClient prowJobClient prowJobClient diff --git a/prow/plugins/plugins.go b/prow/plugins/plugins.go index 519790a607072..4307e0ea50d36 100644 --- a/prow/plugins/plugins.go +++ b/prow/plugins/plugins.go @@ -34,7 +34,7 @@ import ( prowv1 "k8s.io/test-infra/prow/client/clientset/versioned/typed/prowjobs/v1" "k8s.io/test-infra/prow/commentpruner" "k8s.io/test-infra/prow/config" - "k8s.io/test-infra/prow/git" + "k8s.io/test-infra/prow/git/v2" "k8s.io/test-infra/prow/github" "k8s.io/test-infra/prow/pluginhelp" "k8s.io/test-infra/prow/repoowners" @@ -141,7 +141,7 @@ type Agent struct { ProwJobClient prowv1.ProwJobInterface KubernetesClient kubernetes.Interface BuildClusterCoreV1Clients map[string]corev1.CoreV1Interface - GitClient *git.Client + GitClient git.ClientFactory SlackClient *slack.Client BugzillaClient bugzilla.Client @@ -206,7 +206,7 @@ type ClientAgent struct { ProwJobClient prowv1.ProwJobInterface KubernetesClient kubernetes.Interface BuildClusterCoreV1Clients map[string]corev1.CoreV1Interface - GitClient *git.Client + GitClient git.ClientFactory SlackClient *slack.Client OwnersClient *repoowners.Client BugzillaClient bugzilla.Client diff --git a/prow/plugins/skip/BUILD.bazel b/prow/plugins/skip/BUILD.bazel index 1e7b7f07d52dd..7b0c83b064bd4 100644 --- a/prow/plugins/skip/BUILD.bazel +++ b/prow/plugins/skip/BUILD.bazel @@ -7,7 +7,7 @@ go_library( visibility = ["//visibility:public"], deps = [ "//prow/config:go_default_library", - "//prow/git:go_default_library", + "//prow/git/v2:go_default_library", "//prow/github:go_default_library", "//prow/pluginhelp:go_default_library", "//prow/plugins:go_default_library", @@ -36,7 +36,6 @@ go_test( embed = [":go_default_library"], deps = [ "//prow/config:go_default_library", - "//prow/git:go_default_library", "//prow/github:go_default_library", "//prow/github/fakegithub:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", diff --git a/prow/plugins/skip/skip.go b/prow/plugins/skip/skip.go index 24f409ab7d70f..cb7d0e426b10a 100644 --- a/prow/plugins/skip/skip.go +++ b/prow/plugins/skip/skip.go @@ -24,7 +24,7 @@ import ( "github.com/sirupsen/logrus" "k8s.io/test-infra/prow/config" - "k8s.io/test-infra/prow/git" + "k8s.io/test-infra/prow/git/v2" "k8s.io/test-infra/prow/github" "k8s.io/test-infra/prow/pluginhelp" "k8s.io/test-infra/prow/plugins" @@ -69,7 +69,7 @@ func handleGenericComment(pc plugins.Agent, e github.GenericCommentEvent) error return handle(pc.GitHubClient, pc.Logger, &e, pc.Config, pc.GitClient, honorOkToTest) } -func handle(gc githubClient, log *logrus.Entry, e *github.GenericCommentEvent, c *config.Config, gitClient *git.Client, honorOkToTest bool) error { +func handle(gc githubClient, log *logrus.Entry, e *github.GenericCommentEvent, c *config.Config, gitClient git.ClientFactory, honorOkToTest bool) error { if !e.IsPR || e.IssueState != "open" || e.Action != github.GenericCommentActionCreated { return nil } diff --git a/prow/plugins/skip/skip_test.go b/prow/plugins/skip/skip_test.go index f8320cb3553ec..de7be47b3caca 100644 --- a/prow/plugins/skip/skip_test.go +++ b/prow/plugins/skip/skip_test.go @@ -23,7 +23,6 @@ import ( "github.com/sirupsen/logrus" "k8s.io/test-infra/prow/config" - "k8s.io/test-infra/prow/git" "k8s.io/test-infra/prow/github" "k8s.io/test-infra/prow/github/fakegithub" ) @@ -325,7 +324,7 @@ func TestSkipStatus(t *testing.T) { }, } - if err := handle(fghc, l, test.event, c, &git.Client{}, true); err != nil { + if err := handle(fghc, l, test.event, c, nil, true); err != nil { t.Errorf("%s: unexpected error: %v", test.name, err) continue } diff --git a/prow/plugins/trigger/BUILD.bazel b/prow/plugins/trigger/BUILD.bazel index f88f10c32e067..05e0ba01e60fa 100644 --- a/prow/plugins/trigger/BUILD.bazel +++ b/prow/plugins/trigger/BUILD.bazel @@ -19,7 +19,6 @@ go_test( "//prow/apis/prowjobs/v1:go_default_library", "//prow/client/clientset/versioned/fake:go_default_library", "//prow/config:go_default_library", - "//prow/git:go_default_library", "//prow/github:go_default_library", "//prow/github/fakegithub:go_default_library", "//prow/labels:go_default_library", @@ -49,7 +48,7 @@ go_library( "//prow/apis/prowjobs/v1:go_default_library", "//prow/config:go_default_library", "//prow/errorutil:go_default_library", - "//prow/git:go_default_library", + "//prow/git/v2:go_default_library", "//prow/github:go_default_library", "//prow/labels:go_default_library", "//prow/pjutil:go_default_library", diff --git a/prow/plugins/trigger/generic-comment_test.go b/prow/plugins/trigger/generic-comment_test.go index e66e25ecdbd95..5ed07f1c9aa1e 100644 --- a/prow/plugins/trigger/generic-comment_test.go +++ b/prow/plugins/trigger/generic-comment_test.go @@ -29,7 +29,6 @@ import ( prowapi "k8s.io/test-infra/prow/apis/prowjobs/v1" "k8s.io/test-infra/prow/client/clientset/versioned/fake" "k8s.io/test-infra/prow/config" - "k8s.io/test-infra/prow/git" "k8s.io/test-infra/prow/github" "k8s.io/test-infra/prow/github/fakegithub" "k8s.io/test-infra/prow/labels" @@ -858,7 +857,7 @@ func TestHandleGenericComment(t *testing.T) { ProwJobClient: fakeProwJobClient.ProwV1().ProwJobs(fakeConfig.ProwJobNamespace), Config: fakeConfig, Logger: logrus.WithField("plugin", PluginName), - GitClient: &git.Client{}, + GitClient: nil, } presubmits := tc.Presubmits if presubmits == nil { diff --git a/prow/plugins/trigger/pull-request_test.go b/prow/plugins/trigger/pull-request_test.go index 3f4923bb733a5..1bc6f1d96646a 100644 --- a/prow/plugins/trigger/pull-request_test.go +++ b/prow/plugins/trigger/pull-request_test.go @@ -24,7 +24,6 @@ import ( clienttesting "k8s.io/client-go/testing" "k8s.io/test-infra/prow/client/clientset/versioned/fake" "k8s.io/test-infra/prow/config" - "k8s.io/test-infra/prow/git" "k8s.io/test-infra/prow/github" "k8s.io/test-infra/prow/github/fakegithub" "k8s.io/test-infra/prow/labels" @@ -309,7 +308,7 @@ func TestHandlePullRequest(t *testing.T) { ProwJobClient: fakeProwJobClient.ProwV1().ProwJobs("namespace"), Config: &config.Config{}, Logger: logrus.WithField("plugin", PluginName), - GitClient: &git.Client{}, + GitClient: nil, } presubmits := map[string][]config.Presubmit{ diff --git a/prow/plugins/trigger/trigger.go b/prow/plugins/trigger/trigger.go index 86e1a3182ed04..0abe18e549b8f 100644 --- a/prow/plugins/trigger/trigger.go +++ b/prow/plugins/trigger/trigger.go @@ -25,7 +25,7 @@ import ( prowapi "k8s.io/test-infra/prow/apis/prowjobs/v1" "k8s.io/test-infra/prow/config" "k8s.io/test-infra/prow/errorutil" - "k8s.io/test-infra/prow/git" + "k8s.io/test-infra/prow/git/v2" "k8s.io/test-infra/prow/github" "k8s.io/test-infra/prow/pjutil" "k8s.io/test-infra/prow/pluginhelp" @@ -127,7 +127,7 @@ type Client struct { ProwJobClient prowJobClient Config *config.Config Logger *logrus.Entry - GitClient *git.Client + GitClient git.ClientFactory } // trustedUserClient is used to check is user member and repo collaborator diff --git a/prow/plugins/trigger/trigger_test.go b/prow/plugins/trigger/trigger_test.go index bd46fe4504d1d..2837da0e45f70 100644 --- a/prow/plugins/trigger/trigger_test.go +++ b/prow/plugins/trigger/trigger_test.go @@ -31,7 +31,6 @@ import ( prowapi "k8s.io/test-infra/prow/apis/prowjobs/v1" "k8s.io/test-infra/prow/client/clientset/versioned/fake" "k8s.io/test-infra/prow/config" - "k8s.io/test-infra/prow/git" "k8s.io/test-infra/prow/github" "k8s.io/test-infra/prow/github/fakegithub" "k8s.io/test-infra/prow/plugins" @@ -321,7 +320,7 @@ func TestRunAndSkipJobs(t *testing.T) { GitHubClient: &fakeGitHubClient, ProwJobClient: fakeProwJobClient.ProwV1().ProwJobs("prowjobs"), Logger: logrus.WithField("testcase", testCase.name), - GitClient: &git.Client{}, + GitClient: nil, } err := RunAndSkipJobs(client, pr, fakegithub.TestRef, testCase.requestedJobs, testCase.skippedJobs, "event-guid", testCase.elideSkippedContexts) diff --git a/prow/plugins/updateconfig/BUILD.bazel b/prow/plugins/updateconfig/BUILD.bazel index d723c23fd75cf..850e8d27be3fe 100644 --- a/prow/plugins/updateconfig/BUILD.bazel +++ b/prow/plugins/updateconfig/BUILD.bazel @@ -11,8 +11,8 @@ go_test( srcs = ["updateconfig_test.go"], embed = [":go_default_library"], deps = [ - "//prow/git:go_default_library", "//prow/git/localgit:go_default_library", + "//prow/git/v2:go_default_library", "//prow/github:go_default_library", "//prow/github/fakegithub:go_default_library", "//prow/plugins:go_default_library", @@ -35,7 +35,7 @@ go_library( srcs = ["updateconfig.go"], importpath = "k8s.io/test-infra/prow/plugins/updateconfig", deps = [ - "//prow/git:go_default_library", + "//prow/git/v2:go_default_library", "//prow/github:go_default_library", "//prow/kube:go_default_library", "//prow/pluginhelp:go_default_library", diff --git a/prow/plugins/updateconfig/updateconfig.go b/prow/plugins/updateconfig/updateconfig.go index d7a9b26ff5dfb..76d818233a269 100644 --- a/prow/plugins/updateconfig/updateconfig.go +++ b/prow/plugins/updateconfig/updateconfig.go @@ -33,7 +33,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" corev1 "k8s.io/client-go/kubernetes/typed/core/v1" - "k8s.io/test-infra/prow/git" + "k8s.io/test-infra/prow/git/v2" "k8s.io/test-infra/prow/github" "k8s.io/test-infra/prow/kube" "k8s.io/test-infra/prow/pluginhelp" @@ -240,12 +240,7 @@ func FilterChanges(cfg plugins.ConfigUpdater, changes []github.PullRequestChange return toUpdate } -type gitClient interface { - Clone(org, repo string) (*git.Repo, error) - Clean() error -} - -func handle(gc githubClient, gitClient gitClient, kc corev1.ConfigMapsGetter, buildClusterCoreV1Clients map[string]corev1.CoreV1Interface, defaultNamespace string, log *logrus.Entry, pre github.PullRequestEvent, config plugins.ConfigUpdater, metrics *prometheus.GaugeVec) error { +func handle(gc githubClient, gitClient git.ClientFactory, kc corev1.ConfigMapsGetter, buildClusterCoreV1Clients map[string]corev1.CoreV1Interface, defaultNamespace string, log *logrus.Entry, pre github.PullRequestEvent, config plugins.ConfigUpdater, metrics *prometheus.GaugeVec) error { // Only consider newly merged PRs if pre.Action != github.PullRequestActionClosed { return nil @@ -294,7 +289,7 @@ func handle(gc githubClient, gitClient gitClient, kc corev1.ConfigMapsGetter, bu indent = " " // three spaces for sub bullets } - gitRepo, err := gitClient.Clone(org, repo) + gitRepo, err := gitClient.ClientFor(org, repo) if err != nil { return err } diff --git a/prow/plugins/updateconfig/updateconfig_test.go b/prow/plugins/updateconfig/updateconfig_test.go index 1a8fc09ff12c9..698cf58710754 100644 --- a/prow/plugins/updateconfig/updateconfig_test.go +++ b/prow/plugins/updateconfig/updateconfig_test.go @@ -32,8 +32,8 @@ import ( "k8s.io/client-go/kubernetes/fake" clienttesting "k8s.io/client-go/testing" - "k8s.io/test-infra/prow/git" "k8s.io/test-infra/prow/git/localgit" + "k8s.io/test-infra/prow/git/v2" "k8s.io/test-infra/prow/github" "k8s.io/test-infra/prow/github/fakegithub" "k8s.io/test-infra/prow/plugins" @@ -93,7 +93,7 @@ var remoteFiles = map[string]map[string]string{ }, } -func setupLocalGitRepo(t *testing.T, org, repo string) *git.Client { +func setupLocalGitRepo(t *testing.T, org, repo string) git.ClientFactory { lg, c, err := localgit.New() if err != nil { t.Fatalf("Making local git repo: %v", err) diff --git a/prow/plugins/verify-owners/BUILD.bazel b/prow/plugins/verify-owners/BUILD.bazel index 4cb9e5448c9df..0a8d000a9e6e3 100644 --- a/prow/plugins/verify-owners/BUILD.bazel +++ b/prow/plugins/verify-owners/BUILD.bazel @@ -6,7 +6,7 @@ go_library( importpath = "k8s.io/test-infra/prow/plugins/verify-owners", visibility = ["//visibility:public"], deps = [ - "//prow/git:go_default_library", + "//prow/git/v2:go_default_library", "//prow/github:go_default_library", "//prow/labels:go_default_library", "//prow/pluginhelp:go_default_library", diff --git a/prow/plugins/verify-owners/verify-owners.go b/prow/plugins/verify-owners/verify-owners.go index 26d865a74224e..eb76e45b1ad8c 100644 --- a/prow/plugins/verify-owners/verify-owners.go +++ b/prow/plugins/verify-owners/verify-owners.go @@ -28,7 +28,7 @@ import ( "github.com/sirupsen/logrus" "k8s.io/apimachinery/pkg/util/sets" - "k8s.io/test-infra/prow/git" + "k8s.io/test-infra/prow/git/v2" "k8s.io/test-infra/prow/github" "k8s.io/test-infra/prow/labels" "k8s.io/test-infra/prow/pluginhelp" @@ -155,7 +155,7 @@ func handleGenericCommentEvent(pc plugins.Agent, e github.GenericCommentEvent) e return handleGenericComment(pc.GitHubClient, pc.GitClient, pc.OwnersClient, pc.Logger, &e, pc.PluginConfig.Owners.LabelsBlackList, pc.PluginConfig.TriggerFor(e.Repo.Owner.Login, e.Repo.Name), skipTrustedUserCheck, cp) } -func handleGenericComment(ghc githubClient, gc *git.Client, roc repoownersClient, log *logrus.Entry, ce *github.GenericCommentEvent, labelsBlackList []string, triggerConfig plugins.Trigger, skipTrustedUserCheck bool, cp commentPruner) error { +func handleGenericComment(ghc githubClient, gc git.ClientFactory, roc repoownersClient, log *logrus.Entry, ce *github.GenericCommentEvent, labelsBlackList []string, triggerConfig plugins.Trigger, skipTrustedUserCheck bool, cp commentPruner) error { // Only consider open PRs and new comments. if ce.IssueState != "open" || !ce.IsPR || ce.Action != github.GenericCommentActionCreated { return nil @@ -185,7 +185,7 @@ type messageWithLine struct { message string } -func handle(ghc githubClient, gc *git.Client, roc repoownersClient, log *logrus.Entry, pr *github.PullRequest, info info, labelsBlackList []string, triggerConfig plugins.Trigger, skipTrustedUserCheck bool, cp commentPruner) error { +func handle(ghc githubClient, gc git.ClientFactory, roc repoownersClient, log *logrus.Entry, pr *github.PullRequest, info info, labelsBlackList []string, triggerConfig plugins.Trigger, skipTrustedUserCheck bool, cp commentPruner) error { org := info.org repo := info.repo number := info.number @@ -221,7 +221,7 @@ func handle(ghc githubClient, gc *git.Client, roc repoownersClient, log *logrus. } // Clone the repo, checkout the PR. - r, err := gc.Clone(org, repo) + r, err := gc.ClientFor(org, repo) if err != nil { return err } diff --git a/prow/plugins/verify-owners/verify-owners_test.go b/prow/plugins/verify-owners/verify-owners_test.go index fa61ab34c5b9d..d2bea8f47669f 100644 --- a/prow/plugins/verify-owners/verify-owners_test.go +++ b/prow/plugins/verify-owners/verify-owners_test.go @@ -549,7 +549,7 @@ func TestParseOwnersFile(t *testing.T) { Patch: test.patch, } - r, err := c.Clone("org", "repo") + r, err := c.ClientFor("org", "repo") if err != nil { t.Fatalf("error cloning the repo: %v", err) } diff --git a/prow/repoowners/BUILD.bazel b/prow/repoowners/BUILD.bazel index 18236ce41a485..d08cbdff4df30 100644 --- a/prow/repoowners/BUILD.bazel +++ b/prow/repoowners/BUILD.bazel @@ -7,7 +7,7 @@ go_library( visibility = ["//visibility:public"], deps = [ "//prow/config:go_default_library", - "//prow/git:go_default_library", + "//prow/git/v2:go_default_library", "//prow/github:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", "@io_k8s_apimachinery//pkg/util/sets:go_default_library", diff --git a/prow/repoowners/repoowners.go b/prow/repoowners/repoowners.go index 07d2abe3ec383..6fee74736712b 100644 --- a/prow/repoowners/repoowners.go +++ b/prow/repoowners/repoowners.go @@ -29,7 +29,7 @@ import ( "sigs.k8s.io/yaml" "k8s.io/apimachinery/pkg/util/sets" - "k8s.io/test-infra/prow/git" + "k8s.io/test-infra/prow/git/v2" "k8s.io/test-infra/prow/github" prowConf "k8s.io/test-infra/prow/config" @@ -101,7 +101,7 @@ var _ Interface = &Client{} // Client is the repoowners client type Client struct { - git *git.Client + git git.ClientFactory ghc githubClient logger *logrus.Entry @@ -115,7 +115,7 @@ type Client struct { // NewClient is the constructor for Client func NewClient( - gc *git.Client, + gc git.ClientFactory, ghc github.Client, mdYAMLEnabled func(org, repo string) bool, skipCollaborators func(org, repo string) bool, @@ -189,7 +189,7 @@ func (c *Client) LoadRepoAliases(org, repo, base string) (RepoAliases, error) { entry, ok := c.cache[fullName] if !ok || entry.sha != sha { // entry is non-existent or stale. - gitRepo, err := c.git.Clone(org, repo) + gitRepo, err := c.git.ClientFor(org, repo) if err != nil { return nil, fmt.Errorf("failed to clone %s: %v", cloneRef, err) } @@ -223,7 +223,7 @@ func (c *Client) LoadRepoOwners(org, repo, base string) (RepoOwner, error) { defer c.lock.Unlock() entry, ok := c.cache[fullName] if !ok || entry.sha != sha || entry.owners == nil || !entry.matchesMDYAML(mdYaml) { - gitRepo, err := c.git.Clone(org, repo) + gitRepo, err := c.git.ClientFor(org, repo) if err != nil { return nil, fmt.Errorf("failed to clone %s: %v", cloneRef, err) } diff --git a/prow/tide/BUILD.bazel b/prow/tide/BUILD.bazel index 97d5df5d8ef11..fa0d7d0daf1be 100644 --- a/prow/tide/BUILD.bazel +++ b/prow/tide/BUILD.bazel @@ -14,7 +14,7 @@ go_library( "//prow/apis/prowjobs/v1:go_default_library", "//prow/config:go_default_library", "//prow/errorutil:go_default_library", - "//prow/git:go_default_library", + "//prow/git/v2:go_default_library", "//prow/github:go_default_library", "//prow/pjutil:go_default_library", "//prow/tide/blockers:go_default_library", @@ -59,7 +59,6 @@ go_test( deps = [ "//prow/apis/prowjobs/v1:go_default_library", "//prow/config:go_default_library", - "//prow/git:go_default_library", "//prow/git/localgit:go_default_library", "//prow/github:go_default_library", "//prow/tide/blockers:go_default_library", diff --git a/prow/tide/status.go b/prow/tide/status.go index 1a7562e7a84d7..32ff619a71a42 100644 --- a/prow/tide/status.go +++ b/prow/tide/status.go @@ -38,7 +38,7 @@ import ( "k8s.io/test-infra/pkg/io" "k8s.io/test-infra/prow/config" - "k8s.io/test-infra/prow/git" + "k8s.io/test-infra/prow/git/v2" "k8s.io/test-infra/prow/github" "k8s.io/test-infra/prow/tide/blockers" ) @@ -66,7 +66,7 @@ type statusController struct { logger *logrus.Entry config config.Getter ghc githubClient - gc *git.Client + gc git.ClientFactory // newPoolPending is a size 1 chan that signals that the main Tide loop has // updated the 'poolPRs' field with a freshly updated pool. @@ -581,7 +581,7 @@ func indexFuncPassingJobs(obj runtime.Object) []string { return result } -func getContextCheckerWithRequiredContexts(cfg *config.Config, gc *git.Client, org, repo, branch string, baseSHAGetter config.RefGetter, headSHA string, requiredContexts []string) (contextChecker, error) { +func getContextCheckerWithRequiredContexts(cfg *config.Config, gc git.ClientFactory, org, repo, branch string, baseSHAGetter config.RefGetter, headSHA string, requiredContexts []string) (contextChecker, error) { contextPolicy, err := cfg.GetTideContextPolicy(gc, org, repo, branch, baseSHAGetter, headSHA) if err != nil { return nil, err diff --git a/prow/tide/tide.go b/prow/tide/tide.go index 0c612c9abe4ae..c6f6702be7083 100644 --- a/prow/tide/tide.go +++ b/prow/tide/tide.go @@ -41,7 +41,7 @@ import ( prowapi "k8s.io/test-infra/prow/apis/prowjobs/v1" "k8s.io/test-infra/prow/config" "k8s.io/test-infra/prow/errorutil" - "k8s.io/test-infra/prow/git" + "k8s.io/test-infra/prow/git/v2" "k8s.io/test-infra/prow/github" "k8s.io/test-infra/prow/pjutil" "k8s.io/test-infra/prow/tide/blockers" @@ -74,7 +74,7 @@ type Controller struct { config config.Getter ghc githubClient prowJobClient ctrlruntimeclient.Client - gc *git.Client + gc git.ClientFactory sc *statusController @@ -210,7 +210,7 @@ type manager interface { } // NewController makes a Controller out of the given clients. -func NewController(ghcSync, ghcStatus github.Client, mgr manager, cfg config.Getter, gc *git.Client, maxRecordsPerPool int, opener io.Opener, historyURI, statusURI string, logger *logrus.Entry) (*Controller, error) { +func NewController(ghcSync, ghcStatus github.Client, mgr manager, cfg config.Getter, gc git.ClientFactory, maxRecordsPerPool int, opener io.Opener, historyURI, statusURI string, logger *logrus.Entry) (*Controller, error) { if logger == nil { logger = logrus.NewEntry(logrus.StandardLogger()) } @@ -228,7 +228,7 @@ func NewController(ghcSync, ghcStatus github.Client, mgr manager, cfg config.Get return newSyncController(logger, ghcSync, mgr, cfg, gc, sc, hist) } -func newStatusController(logger *logrus.Entry, ghc githubClient, mgr manager, gc *git.Client, cfg config.Getter, opener io.Opener, statusURI string) (*statusController, error) { +func newStatusController(logger *logrus.Entry, ghc githubClient, mgr manager, gc git.ClientFactory, cfg config.Getter, opener io.Opener, statusURI string) (*statusController, error) { if err := mgr.GetFieldIndexer().IndexField(&prowapi.ProwJob{}, indexNamePassingJobs, indexFuncPassingJobs); err != nil { return nil, fmt.Errorf("failed to add index for passing jobs to cache: %v", err) } @@ -250,7 +250,7 @@ func newSyncController( ghcSync githubClient, mgr manager, cfg config.Getter, - gc *git.Client, + gc git.ClientFactory, sc *statusController, hist *history.History, ) (*Controller, error) { @@ -848,7 +848,7 @@ func (c *Controller) pickBatch(sp subpool, cc map[int]contextChecker) ([]PullReq } sp.log.Debugf("of %d possible PRs, %d are passing tests", len(sp.prs), len(candidates)) - r, err := c.gc.Clone(sp.org, sp.repo) + r, err := c.gc.ClientFor(sp.org, sp.repo) if err != nil { return nil, nil, err } diff --git a/prow/tide/tide_test.go b/prow/tide/tide_test.go index 57f6db047570c..8cf59451767aa 100644 --- a/prow/tide/tide_test.go +++ b/prow/tide/tide_test.go @@ -42,7 +42,6 @@ import ( prowapi "k8s.io/test-infra/prow/apis/prowjobs/v1" "k8s.io/test-infra/prow/config" - "k8s.io/test-infra/prow/git" "k8s.io/test-infra/prow/git/localgit" "k8s.io/test-infra/prow/github" "k8s.io/test-infra/prow/tide/history" @@ -692,7 +691,7 @@ func TestDividePool(t *testing.T) { mgr := newFakeManager() c, err := newSyncController( - logrus.NewEntry(logrus.StandardLogger()), fc, mgr, configGetter, &git.Client{}, nil, nil, + logrus.NewEntry(logrus.StandardLogger()), fc, mgr, configGetter, nil, nil, nil, ) if err != nil { t.Fatalf("failed to construct sync controller: %v", err) @@ -1700,7 +1699,7 @@ func TestSync(t *testing.T) { pjClient: fakectrlruntimeclient.NewFakeClient(), logger: logrus.WithField("controller", "status-update"), ghc: fgc, - gc: &git.Client{}, + gc: nil, config: ca.Config, newPoolPending: make(chan bool, 1), shutDown: make(chan bool), @@ -1710,7 +1709,7 @@ func TestSync(t *testing.T) { c := &Controller{ config: ca.Config, ghc: fgc, - gc: &git.Client{}, + gc: nil, prowJobClient: fakectrlruntimeclient.NewFakeClient(), logger: logrus.WithField("controller", "sync"), sc: sc, @@ -2455,7 +2454,7 @@ func TestPresubmitsByPull(t *testing.T) { c := &Controller{ config: cfgAgent.Config, ghc: &fgc{}, - gc: &git.Client{}, + gc: nil, changedFiles: &changedFilesAgent{ ghc: &fgc{}, changeCache: tc.initialChangeCache,