mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 15:12:02 +00:00
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:
parent
d2d2d368f3
commit
9aae1086cb
@ -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)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user