From 9aae1086cb8d7d2e2e7c57d9e28efc64f309242b Mon Sep 17 00:00:00 2001 From: Erik Seliger Date: Fri, 19 Feb 2021 12:07:59 +0100 Subject: [PATCH] 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. --- .../internal/campaigns/reconciler/util.go | 33 ++++--------------- 1 file changed, 6 insertions(+), 27 deletions(-) diff --git a/enterprise/internal/campaigns/reconciler/util.go b/enterprise/internal/campaigns/reconciler/util.go index 1235e7c28af..9af1f76e631 100644 --- a/enterprise/internal/campaigns/reconciler/util.go +++ b/enterprise/internal/campaigns/reconciler/util.go @@ -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) }