From 0118a176e50f01c09139fe2de0760c26a3696bef Mon Sep 17 00:00:00 2001 From: Noam Gal Date: Tue, 11 May 2021 14:05:03 +0300 Subject: [PATCH] removed GetRepository (#57) --- pkg/git/mocks/provider.go | 21 ----------- pkg/git/provider.go | 2 - pkg/git/provider_github.go | 13 ------- pkg/git/provider_github_test.go | 65 --------------------------------- 4 files changed, 101 deletions(-) diff --git a/pkg/git/mocks/provider.go b/pkg/git/mocks/provider.go index 4f8fba29..06f852bb 100644 --- a/pkg/git/mocks/provider.go +++ b/pkg/git/mocks/provider.go @@ -34,24 +34,3 @@ func (_m *Provider) CreateRepository(ctx context.Context, opts *git.CreateRepoOp return r0, r1 } - -// GetRepository provides a mock function with given fields: ctx, opts -func (_m *Provider) GetRepository(ctx context.Context, opts *git.GetRepoOptions) (string, error) { - ret := _m.Called(ctx, opts) - - var r0 string - if rf, ok := ret.Get(0).(func(context.Context, *git.GetRepoOptions) string); ok { - r0 = rf(ctx, opts) - } else { - r0 = ret.Get(0).(string) - } - - var r1 error - if rf, ok := ret.Get(1).(func(context.Context, *git.GetRepoOptions) error); ok { - r1 = rf(ctx, opts) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} diff --git a/pkg/git/provider.go b/pkg/git/provider.go index 7658ab76..c4729749 100644 --- a/pkg/git/provider.go +++ b/pkg/git/provider.go @@ -14,8 +14,6 @@ type ( // CreateRepository creates the repository in the remote provider and returns a // clone url CreateRepository(ctx context.Context, opts *CreateRepoOptions) (string, error) - - GetRepository(ctx context.Context, opts *GetRepoOptions) (string, error) } Auth struct { diff --git a/pkg/git/provider_github.go b/pkg/git/provider_github.go index 0190976b..ac001edd 100644 --- a/pkg/git/provider_github.go +++ b/pkg/git/provider_github.go @@ -49,19 +49,6 @@ func newGithub(opts *ProviderOptions) (Provider, error) { return g, nil } -func (g *github) GetRepository(ctx context.Context, opts *GetRepoOptions) (string, error) { - r, res, err := g.Repositories.Get(ctx, opts.Owner, opts.Name) - if res != nil && res.StatusCode == http.StatusNotFound { - return "", ErrRepoNotFound - } - - if err != nil { - return "", err - } - - return *r.CloneURL, nil -} - func (g *github) CreateRepository(ctx context.Context, opts *CreateRepoOptions) (string, error) { authUser, res, err := g.Users.Get(ctx, "") // get authenticated user details if err != nil { diff --git a/pkg/git/provider_github_test.go b/pkg/git/provider_github_test.go index 71cfdcd7..56bf006e 100644 --- a/pkg/git/provider_github_test.go +++ b/pkg/git/provider_github_test.go @@ -11,71 +11,6 @@ import ( "github.com/stretchr/testify/assert" ) -func Test_github_GetRepository(t *testing.T) { - tests := map[string]struct { - repo *gh.Repository - res *gh.Response - err error - opts *GetRepoOptions - want string - wantErr string - }{ - "No repo": { - res: &gh.Response{ - Response: &http.Response{ - StatusCode: http.StatusNotFound, - }, - }, - opts: &GetRepoOptions{ - Owner: "owner", - Name: "repo", - }, - want: "", - wantErr: "git repository not found", - }, - "Has repo": { - repo: &gh.Repository{ - CloneURL: gh.String("https://github.com/owner/repo"), - }, - opts: &GetRepoOptions{ - Owner: "owner", - Name: "repo", - }, - want: "https://github.com/owner/repo", - wantErr: "", - }, - "Error getting repo": { - err: errors.New("Some error"), - opts: &GetRepoOptions{ - Owner: "owner", - Name: "repo", - }, - want: "", - wantErr: "Some error", - }, - } - - for name, tt := range tests { - t.Run(name, func(t *testing.T) { - mockRepo := new(mocks.Repositories) - ctx := context.Background() - mockRepo.On("Get", ctx, tt.opts.Owner, tt.opts.Name).Return(tt.repo, tt.res, tt.err) - g := &github{ - Repositories: mockRepo, - } - got, err := g.GetRepository(ctx, tt.opts) - if tt.wantErr != "" { - assert.EqualError(t, err, tt.wantErr) - return - } - - if got != tt.want { - t.Errorf("github.GetRepository() = %v, want %v", got, tt.want) - } - }) - } -} - func Test_github_CreateRepository(t *testing.T) { tests := map[string]struct { user *gh.User