Refactor reconciler utils a bit (#18450)

After the overhaul of syncer spawning, I realized the loadExternalService helper could be simplified in the reconciler as well. This does that and since we don't mock this out by passing in a mock store, we don't need the interfaces in this package anymore at all.
This commit is contained in:
Erik Seliger 2021-02-19 12:07:59 +01:00 committed by GitHub
parent d2d2d368f3
commit 9aae1086cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,28 +5,14 @@ import (
"github.com/pkg/errors"
"github.com/sourcegraph/sourcegraph/internal/api"
"github.com/sourcegraph/sourcegraph/internal/database"
"github.com/sourcegraph/sourcegraph/internal/types"
"github.com/sourcegraph/sourcegraph/schema"
)
// TODO: copy-pasted
type RepoStore interface {
Get(ctx context.Context, id api.RepoID) (*types.Repo, error)
}
// TODO: copy-pasted
type ExternalServiceStore interface {
List(context.Context, database.ExternalServicesListOptions) ([]*types.ExternalService, error)
}
// TODO: copy-pasted
func loadExternalService(ctx context.Context, esStore ExternalServiceStore, repo *types.Repo) (*types.ExternalService, error) {
var externalService *types.ExternalService
args := database.ExternalServicesListOptions{IDs: repo.ExternalServiceIDs()}
es, err := esStore.List(ctx, args)
func loadExternalService(ctx context.Context, esStore *database.ExternalServiceStore, repo *types.Repo) (*types.ExternalService, error) {
es, err := esStore.List(ctx, database.ExternalServicesListOptions{IDs: repo.ExternalServiceIDs()})
if err != nil {
return nil, err
}
@ -40,25 +26,18 @@ func loadExternalService(ctx context.Context, esStore ExternalServiceStore, repo
switch cfg := cfg.(type) {
case *schema.GitHubConnection:
if cfg.Token != "" {
externalService = e
return e, nil
}
case *schema.BitbucketServerConnection:
if cfg.Token != "" {
externalService = e
return e, nil
}
case *schema.GitLabConnection:
if cfg.Token != "" {
externalService = e
return e, nil
}
}
if externalService != nil {
break
}
}
if externalService == nil {
return nil, errors.Errorf("no external services found for repo %q", repo.Name)
}
return externalService, nil
return nil, errors.Errorf("no external services found for repo %q", repo.Name)
}