Skip to content

Commit

Permalink
git: add adapters from v1 types to the v2 interfaces
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
  • Loading branch information
stevekuznetsov committed Dec 3, 2019
1 parent 86558c4 commit 1783a2a
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
5 changes: 5 additions & 0 deletions prow/git/v2/BUILD.bazel
Expand Up @@ -8,11 +8,16 @@ load(
go_library(
name = "go_default_library",
srcs = [
"adapter.go",
"client_factory.go",
"interactor.go",
"publisher.go",
],
importpath = "k8s.io/test-infra/prow/git/v2",
deps = [
"//prow/git:go_default_library",
"//prow/github:go_default_library",
],
)

filegroup(
Expand Down
69 changes: 69 additions & 0 deletions prow/git/v2/adapter.go
@@ -0,0 +1,69 @@
package git

import (
"errors"

"k8s.io/test-infra/prow/git"
"k8s.io/test-infra/prow/github"
)

// ClientFactoryFrom adapts the v1 client to a v2 client
func ClientFactoryFrom(c *git.Client) ClientFactory {
return &clientFactoryAdapter{Client: c}
}

type clientFactoryAdapter struct {
*git.Client
}

// ClientFromDir creates a client that operates on a repo that has already
// been cloned to the given directory.
func (a *clientFactoryAdapter) ClientFromDir(org, repo, dir string) (RepoClient, error) {
return nil, errors.New("no ClientFromDir implementation exists in the v1 git client")
}

// Repo creates a client that operates on a new clone of the repo.
func (a *clientFactoryAdapter) ClientFor(org, repo string) (RepoClient, error) {
r, err := a.Client.Clone(org, repo)
return &repoClientAdapter{Repo: r}, err
}

type repoClientAdapter struct {
*git.Repo
}

func (a *repoClientAdapter) MergeAndCheckout(baseSHA string, mergeStrategy string, headSHAs ...string) error {
return a.Repo.MergeAndCheckout(baseSHA, github.PullRequestMergeType(mergeStrategy), headSHAs...)
}

func (a *repoClientAdapter) MergeWithStrategy(commitlike, mergeStrategy string) (bool, error) {
return a.Repo.MergeWithStrategy(commitlike, github.PullRequestMergeType(mergeStrategy))
}

func (a *repoClientAdapter) Clone(from string) error {
return errors.New("no Clone implementation exists in the v1 repo client")
}

func (a *repoClientAdapter) Commit(title, body string) error {
return errors.New("no Commit implementation exists in the v1 repo client")
}

func (a *repoClientAdapter) ForcePush(branch string) error {
return errors.New("no ForcePush implementation exists in the v1 repo client")
}

func (a *repoClientAdapter) MirrorClone() error {
return errors.New("no MirrorClone implementation exists in the v1 repo client")
}

func (a *repoClientAdapter) Fetch() error {
return errors.New("no Fetch implementation exists in the v1 repo client")
}

func (a *repoClientAdapter) RemoteUpdate() error {
return errors.New("no RemoteUpdate implementation exists in the v1 repo client")
}

func (a *repoClientAdapter) FetchRef(refspec string) error {
return errors.New("no FetchRef implementation exists in the v1 repo client")
}

0 comments on commit 1783a2a

Please sign in to comment.