Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git: add adapters from v1 types to the v2 interfaces
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
- Loading branch information
1 parent
86558c4
commit 1783a2a
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} |