mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 17:31:43 +00:00
[code-nav]: Moving graphql transport layer to individual service layers (#41596)
This commit is contained in:
parent
3db1614e7e
commit
9ff8ace27f
@ -153,13 +153,13 @@ function buildMockLocation({
|
||||
content,
|
||||
repository: {
|
||||
name: repo,
|
||||
__typename: 'Repository',
|
||||
__typename: 'CodeIntelRepository',
|
||||
},
|
||||
commit: {
|
||||
oid: commit,
|
||||
__typename: 'GitCommit',
|
||||
__typename: 'CodeIntelCommit',
|
||||
},
|
||||
__typename: 'GitBlob',
|
||||
__typename: 'CodeIntelGitBlob',
|
||||
},
|
||||
range: {
|
||||
start: { ...start, __typename: 'Position' },
|
||||
|
||||
@ -20,7 +20,7 @@ const codeIntelFragments = gql`
|
||||
}
|
||||
}
|
||||
|
||||
fragment GitBlobFields on GitBlob {
|
||||
fragment GitBlobFields on CodeIntelGitBlob {
|
||||
path
|
||||
content
|
||||
repository {
|
||||
|
||||
@ -5,462 +5,58 @@ import (
|
||||
|
||||
"github.com/graph-gophers/graphql-go"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
codenav "github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/transport/graphql"
|
||||
autoindexinggraphql "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/transport/graphql"
|
||||
codenavgraphql "github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/transport/graphql"
|
||||
policiesgraphql "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/transport/graphql"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/sharedresolvers"
|
||||
resolvers "github.com/sourcegraph/sourcegraph/internal/codeintel/sharedresolvers"
|
||||
uploadsgraphql "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/transport/graphql"
|
||||
executor "github.com/sourcegraph/sourcegraph/internal/services/executors/transport/graphql"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
)
|
||||
|
||||
type CodeIntelResolver interface {
|
||||
GitBlobLSIFData(ctx context.Context, args *GitBlobLSIFDataArgs) (GitBlobLSIFDataResolver, error)
|
||||
GitBlobCodeIntelInfo(ctx context.Context, args *GitTreeEntryCodeIntelInfoArgs) (GitBlobCodeIntelSupportResolver, error)
|
||||
GitTreeCodeIntelInfo(ctx context.Context, args *GitTreeEntryCodeIntelInfoArgs) (GitTreeCodeIntelSupportResolver, error)
|
||||
|
||||
RepositorySummary(ctx context.Context, id graphql.ID) (CodeIntelRepositorySummaryResolver, error)
|
||||
NodeResolvers() map[string]NodeByIDFunc
|
||||
|
||||
RequestLanguageSupport(ctx context.Context, args *RequestLanguageSupportArgs) (*EmptyResponse, error)
|
||||
GitBlobLSIFData(ctx context.Context, args *codenavgraphql.GitBlobLSIFDataArgs) (codenavgraphql.GitBlobLSIFDataResolver, error)
|
||||
GitBlobCodeIntelInfo(ctx context.Context, args *autoindexinggraphql.GitTreeEntryCodeIntelInfoArgs) (_ autoindexinggraphql.GitBlobCodeIntelSupportResolver, err error)
|
||||
GitTreeCodeIntelInfo(ctx context.Context, args *autoindexinggraphql.GitTreeEntryCodeIntelInfoArgs) (resolver autoindexinggraphql.GitTreeCodeIntelSupportResolver, err error)
|
||||
RequestLanguageSupport(ctx context.Context, args *autoindexinggraphql.RequestLanguageSupportArgs) (*resolvers.EmptyResponse, error)
|
||||
RequestedLanguageSupport(ctx context.Context) ([]string, error)
|
||||
|
||||
NodeResolvers() map[string]NodeByIDFunc
|
||||
|
||||
AutoindexingServiceResolver
|
||||
ExecutorResolver
|
||||
UploadsServiceResolver
|
||||
PoliciesServiceResolver
|
||||
}
|
||||
|
||||
type AutoindexingServiceResolver interface {
|
||||
DeleteLSIFIndex(ctx context.Context, args *struct{ ID graphql.ID }) (*EmptyResponse, error)
|
||||
IndexConfiguration(ctx context.Context, id graphql.ID) (IndexConfigurationResolver, error) // TODO - rename ...ForRepo
|
||||
LSIFIndexByID(ctx context.Context, id graphql.ID) (LSIFIndexResolver, error)
|
||||
LSIFIndexes(ctx context.Context, args *LSIFIndexesQueryArgs) (LSIFIndexConnectionResolver, error)
|
||||
LSIFIndexesByRepo(ctx context.Context, args *LSIFRepositoryIndexesQueryArgs) (LSIFIndexConnectionResolver, error)
|
||||
QueueAutoIndexJobsForRepo(ctx context.Context, args *QueueAutoIndexJobsForRepoArgs) ([]LSIFIndexResolver, error)
|
||||
UpdateRepositoryIndexConfiguration(ctx context.Context, args *UpdateRepositoryIndexConfigurationArgs) (*EmptyResponse, error)
|
||||
}
|
||||
|
||||
type ExecutorResolver interface {
|
||||
ExecutorResolver() executor.Resolver
|
||||
}
|
||||
|
||||
type CodeNavResolver interface {
|
||||
CodeNavResolver() codenav.Resolver
|
||||
type AutoindexingServiceResolver interface {
|
||||
IndexConfiguration(ctx context.Context, id graphql.ID) (autoindexinggraphql.IndexConfigurationResolver, error) // TODO - rename ...ForRepo
|
||||
DeleteLSIFIndex(ctx context.Context, args *struct{ ID graphql.ID }) (*resolvers.EmptyResponse, error)
|
||||
LSIFIndexByID(ctx context.Context, id graphql.ID) (_ resolvers.LSIFIndexResolver, err error)
|
||||
LSIFIndexes(ctx context.Context, args *autoindexinggraphql.LSIFIndexesQueryArgs) (resolvers.LSIFIndexConnectionResolver, error)
|
||||
LSIFIndexesByRepo(ctx context.Context, args *autoindexinggraphql.LSIFRepositoryIndexesQueryArgs) (resolvers.LSIFIndexConnectionResolver, error)
|
||||
QueueAutoIndexJobsForRepo(ctx context.Context, args *autoindexinggraphql.QueueAutoIndexJobsForRepoArgs) ([]resolvers.LSIFIndexResolver, error)
|
||||
UpdateRepositoryIndexConfiguration(ctx context.Context, args *autoindexinggraphql.UpdateRepositoryIndexConfigurationArgs) (*resolvers.EmptyResponse, error)
|
||||
RepositorySummary(ctx context.Context, id graphql.ID) (resolvers.CodeIntelRepositorySummaryResolver, error)
|
||||
}
|
||||
|
||||
type UploadsServiceResolver interface {
|
||||
CommitGraph(ctx context.Context, id graphql.ID) (CodeIntelligenceCommitGraphResolver, error)
|
||||
LSIFUploadByID(ctx context.Context, id graphql.ID) (LSIFUploadResolver, error)
|
||||
LSIFUploads(ctx context.Context, args *LSIFUploadsQueryArgs) (LSIFUploadConnectionResolver, error)
|
||||
LSIFUploadsByRepo(ctx context.Context, args *LSIFRepositoryUploadsQueryArgs) (LSIFUploadConnectionResolver, error)
|
||||
DeleteLSIFUpload(ctx context.Context, args *struct{ ID graphql.ID }) (*EmptyResponse, error)
|
||||
CommitGraph(ctx context.Context, id graphql.ID) (uploadsgraphql.CodeIntelligenceCommitGraphResolver, error)
|
||||
LSIFUploadByID(ctx context.Context, id graphql.ID) (resolvers.LSIFUploadResolver, error)
|
||||
LSIFUploads(ctx context.Context, args *uploadsgraphql.LSIFUploadsQueryArgs) (resolvers.LSIFUploadConnectionResolver, error)
|
||||
LSIFUploadsByRepo(ctx context.Context, args *uploadsgraphql.LSIFRepositoryUploadsQueryArgs) (resolvers.LSIFUploadConnectionResolver, error)
|
||||
DeleteLSIFUpload(ctx context.Context, args *struct{ ID graphql.ID }) (*resolvers.EmptyResponse, error)
|
||||
}
|
||||
type PoliciesServiceResolver interface {
|
||||
CodeIntelligenceConfigurationPolicies(ctx context.Context, args *CodeIntelligenceConfigurationPoliciesArgs) (CodeIntelligenceConfigurationPolicyConnectionResolver, error)
|
||||
ConfigurationPolicyByID(ctx context.Context, id graphql.ID) (CodeIntelligenceConfigurationPolicyResolver, error)
|
||||
CreateCodeIntelligenceConfigurationPolicy(ctx context.Context, args *CreateCodeIntelligenceConfigurationPolicyArgs) (CodeIntelligenceConfigurationPolicyResolver, error)
|
||||
DeleteCodeIntelligenceConfigurationPolicy(ctx context.Context, args *DeleteCodeIntelligenceConfigurationPolicyArgs) (*EmptyResponse, error)
|
||||
PreviewGitObjectFilter(ctx context.Context, id graphql.ID, args *PreviewGitObjectFilterArgs) ([]GitObjectFilterPreviewResolver, error)
|
||||
PreviewRepositoryFilter(ctx context.Context, args *PreviewRepositoryFilterArgs) (RepositoryFilterPreviewResolver, error)
|
||||
UpdateCodeIntelligenceConfigurationPolicy(ctx context.Context, args *UpdateCodeIntelligenceConfigurationPolicyArgs) (*EmptyResponse, error)
|
||||
}
|
||||
|
||||
type LSIFUploadsQueryArgs struct {
|
||||
graphqlutil.ConnectionArgs
|
||||
Query *string
|
||||
State *string
|
||||
IsLatestForRepo *bool
|
||||
DependencyOf *graphql.ID
|
||||
DependentOf *graphql.ID
|
||||
After *string
|
||||
IncludeDeleted *bool
|
||||
}
|
||||
|
||||
type LSIFRepositoryUploadsQueryArgs struct {
|
||||
*LSIFUploadsQueryArgs
|
||||
RepositoryID graphql.ID
|
||||
}
|
||||
|
||||
type LSIFUploadRetentionPolicyMatchesArgs struct {
|
||||
MatchesOnly bool
|
||||
First *int32
|
||||
After *string
|
||||
Query *string
|
||||
}
|
||||
|
||||
type LSIFUploadResolver interface {
|
||||
ID() graphql.ID
|
||||
InputCommit() string
|
||||
Tags(ctx context.Context) ([]string, error)
|
||||
InputRoot() string
|
||||
IsLatestForRepo() bool
|
||||
UploadedAt() DateTime
|
||||
State() string
|
||||
Failure() *string
|
||||
StartedAt() *DateTime
|
||||
FinishedAt() *DateTime
|
||||
InputIndexer() string
|
||||
Indexer() CodeIntelIndexerResolver
|
||||
PlaceInQueue() *int32
|
||||
AssociatedIndex(ctx context.Context) (LSIFIndexResolver, error)
|
||||
ProjectRoot(ctx context.Context) (*GitTreeEntryResolver, error)
|
||||
RetentionPolicyOverview(ctx context.Context, args *LSIFUploadRetentionPolicyMatchesArgs) (CodeIntelligenceRetentionPolicyMatchesConnectionResolver, error)
|
||||
DocumentPaths(ctx context.Context, args *LSIFUploadDocumentPathsQueryArgs) (LSIFUploadDocumentPathsConnectionResolver, error)
|
||||
AuditLogs(ctx context.Context) (*[]LSIFUploadsAuditLogsResolver, error)
|
||||
}
|
||||
|
||||
type LSIFUploadConnectionResolver interface {
|
||||
Nodes(ctx context.Context) ([]LSIFUploadResolver, error)
|
||||
TotalCount(ctx context.Context) (*int32, error)
|
||||
PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error)
|
||||
}
|
||||
|
||||
type LSIFUploadDocumentPathsQueryArgs struct {
|
||||
Pattern string
|
||||
}
|
||||
|
||||
type LSIFUploadDocumentPathsConnectionResolver interface {
|
||||
Nodes(ctx context.Context) ([]string, error)
|
||||
TotalCount(ctx context.Context) (*int32, error)
|
||||
}
|
||||
|
||||
type LSIFUploadsAuditLogsResolver interface {
|
||||
LogTimestamp() DateTime
|
||||
UploadDeletedAt() *DateTime
|
||||
Reason() *string
|
||||
ChangedColumns() []AuditLogColumnChange
|
||||
UploadID() graphql.ID
|
||||
InputCommit() string
|
||||
InputRoot() string
|
||||
InputIndexer() string
|
||||
UploadedAt() DateTime
|
||||
Operation() string
|
||||
// AssociatedIndex(ctx context.Context) (LSIFIndexResolver, error)
|
||||
}
|
||||
|
||||
type AuditLogColumnChange interface {
|
||||
Column() string
|
||||
Old() *string
|
||||
New() *string
|
||||
}
|
||||
|
||||
type LSIFIndexesQueryArgs struct {
|
||||
graphqlutil.ConnectionArgs
|
||||
Query *string
|
||||
State *string
|
||||
After *string
|
||||
}
|
||||
|
||||
type LSIFRepositoryIndexesQueryArgs struct {
|
||||
*LSIFIndexesQueryArgs
|
||||
RepositoryID graphql.ID
|
||||
}
|
||||
|
||||
type LSIFIndexResolver interface {
|
||||
ID() graphql.ID
|
||||
InputCommit() string
|
||||
Tags(ctx context.Context) ([]string, error)
|
||||
InputRoot() string
|
||||
InputIndexer() string
|
||||
Indexer() CodeIntelIndexerResolver
|
||||
QueuedAt() DateTime
|
||||
State() string
|
||||
Failure() *string
|
||||
StartedAt() *DateTime
|
||||
FinishedAt() *DateTime
|
||||
Steps() IndexStepsResolver
|
||||
PlaceInQueue() *int32
|
||||
AssociatedUpload(ctx context.Context) (LSIFUploadResolver, error)
|
||||
ProjectRoot(ctx context.Context) (*GitTreeEntryResolver, error)
|
||||
}
|
||||
|
||||
type IndexStepsResolver interface {
|
||||
Setup() []ExecutionLogEntryResolver
|
||||
PreIndex() []PreIndexStepResolver
|
||||
Index() IndexStepResolver
|
||||
Upload() ExecutionLogEntryResolver
|
||||
Teardown() []ExecutionLogEntryResolver
|
||||
}
|
||||
|
||||
type PreIndexStepResolver interface {
|
||||
Root() string
|
||||
Image() string
|
||||
Commands() []string
|
||||
LogEntry() ExecutionLogEntryResolver
|
||||
}
|
||||
|
||||
type IndexStepResolver interface {
|
||||
IndexerArgs() []string
|
||||
Outfile() *string
|
||||
LogEntry() ExecutionLogEntryResolver
|
||||
}
|
||||
|
||||
type LSIFIndexConnectionResolver interface {
|
||||
Nodes(ctx context.Context) ([]LSIFIndexResolver, error)
|
||||
TotalCount(ctx context.Context) (*int32, error)
|
||||
PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error)
|
||||
}
|
||||
|
||||
type QueueAutoIndexJobsForRepoArgs struct {
|
||||
Repository graphql.ID
|
||||
Rev *string
|
||||
Configuration *string
|
||||
}
|
||||
|
||||
type GitTreeLSIFDataResolver interface {
|
||||
LSIFUploads(ctx context.Context) ([]LSIFUploadResolver, error)
|
||||
Diagnostics(ctx context.Context, args *LSIFDiagnosticsArgs) (DiagnosticConnectionResolver, error)
|
||||
}
|
||||
|
||||
type CodeIntelligenceCommitGraphResolver interface {
|
||||
Stale(ctx context.Context) (bool, error)
|
||||
UpdatedAt(ctx context.Context) (*DateTime, error)
|
||||
}
|
||||
|
||||
type GitBlobLSIFDataResolver interface {
|
||||
GitTreeLSIFDataResolver
|
||||
ToGitTreeLSIFData() (GitTreeLSIFDataResolver, bool)
|
||||
ToGitBlobLSIFData() (GitBlobLSIFDataResolver, bool)
|
||||
|
||||
Stencil(ctx context.Context) ([]RangeResolver, error)
|
||||
Ranges(ctx context.Context, args *LSIFRangesArgs) (CodeIntelligenceRangeConnectionResolver, error)
|
||||
Definitions(ctx context.Context, args *LSIFQueryPositionArgs) (LocationConnectionResolver, error)
|
||||
References(ctx context.Context, args *LSIFPagedQueryPositionArgs) (LocationConnectionResolver, error)
|
||||
Implementations(ctx context.Context, args *LSIFPagedQueryPositionArgs) (LocationConnectionResolver, error)
|
||||
Hover(ctx context.Context, args *LSIFQueryPositionArgs) (HoverResolver, error)
|
||||
}
|
||||
|
||||
type GitBlobLSIFDataArgs struct {
|
||||
Repo *types.Repo
|
||||
Commit api.CommitID
|
||||
Path string
|
||||
ExactPath bool
|
||||
ToolName string
|
||||
}
|
||||
|
||||
type LSIFRangesArgs struct {
|
||||
StartLine int32
|
||||
EndLine int32
|
||||
}
|
||||
|
||||
type LSIFQueryPositionArgs struct {
|
||||
Line int32
|
||||
Character int32
|
||||
Filter *string
|
||||
}
|
||||
|
||||
type LSIFPagedQueryPositionArgs struct {
|
||||
LSIFQueryPositionArgs
|
||||
graphqlutil.ConnectionArgs
|
||||
After *string
|
||||
Filter *string
|
||||
}
|
||||
|
||||
type LSIFDiagnosticsArgs struct {
|
||||
graphqlutil.ConnectionArgs
|
||||
}
|
||||
|
||||
type CodeIntelligenceRangeConnectionResolver interface {
|
||||
Nodes(ctx context.Context) ([]CodeIntelligenceRangeResolver, error)
|
||||
}
|
||||
|
||||
type CodeIntelligenceRangeResolver interface {
|
||||
Range(ctx context.Context) (RangeResolver, error)
|
||||
Definitions(ctx context.Context) (LocationConnectionResolver, error)
|
||||
References(ctx context.Context) (LocationConnectionResolver, error)
|
||||
Implementations(ctx context.Context) (LocationConnectionResolver, error)
|
||||
Hover(ctx context.Context) (HoverResolver, error)
|
||||
}
|
||||
|
||||
type LocationConnectionResolver interface {
|
||||
Nodes(ctx context.Context) ([]LocationResolver, error)
|
||||
PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error)
|
||||
}
|
||||
|
||||
type HoverResolver interface {
|
||||
Markdown() Markdown
|
||||
Range() RangeResolver
|
||||
}
|
||||
|
||||
type DiagnosticConnectionResolver interface {
|
||||
Nodes(ctx context.Context) ([]DiagnosticResolver, error)
|
||||
TotalCount(ctx context.Context) (int32, error)
|
||||
PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error)
|
||||
}
|
||||
|
||||
type DiagnosticResolver interface {
|
||||
Severity() (*string, error)
|
||||
Code() (*string, error)
|
||||
Source() (*string, error)
|
||||
Message() (*string, error)
|
||||
Location(ctx context.Context) (LocationResolver, error)
|
||||
}
|
||||
|
||||
type CodeIntelConfigurationPolicy struct {
|
||||
Name string
|
||||
RepositoryID *int32
|
||||
RepositoryPatterns *[]string
|
||||
Type GitObjectType
|
||||
Pattern string
|
||||
RetentionEnabled bool
|
||||
RetentionDurationHours *int32
|
||||
RetainIntermediateCommits bool
|
||||
IndexingEnabled bool
|
||||
IndexCommitMaxAgeHours *int32
|
||||
IndexIntermediateCommits bool
|
||||
}
|
||||
|
||||
type CodeIntelligenceConfigurationPoliciesArgs struct {
|
||||
graphqlutil.ConnectionArgs
|
||||
Repository *graphql.ID
|
||||
Query *string
|
||||
ForDataRetention *bool
|
||||
ForIndexing *bool
|
||||
After *string
|
||||
}
|
||||
|
||||
type CreateCodeIntelligenceConfigurationPolicyArgs struct {
|
||||
Repository *graphql.ID
|
||||
CodeIntelConfigurationPolicy
|
||||
}
|
||||
|
||||
type UpdateCodeIntelligenceConfigurationPolicyArgs struct {
|
||||
ID graphql.ID
|
||||
Repository *graphql.ID
|
||||
CodeIntelConfigurationPolicy
|
||||
}
|
||||
|
||||
type DeleteCodeIntelligenceConfigurationPolicyArgs struct {
|
||||
Policy graphql.ID
|
||||
}
|
||||
|
||||
type CodeIntelRepositorySummaryResolver interface {
|
||||
RecentUploads() []LSIFUploadsWithRepositoryNamespaceResolver
|
||||
RecentIndexes() []LSIFIndexesWithRepositoryNamespaceResolver
|
||||
LastUploadRetentionScan() *DateTime
|
||||
LastIndexScan() *DateTime
|
||||
}
|
||||
|
||||
type LSIFUploadsWithRepositoryNamespaceResolver interface {
|
||||
Root() string
|
||||
Indexer() CodeIntelIndexerResolver
|
||||
Uploads() []LSIFUploadResolver
|
||||
}
|
||||
|
||||
type LSIFIndexesWithRepositoryNamespaceResolver interface {
|
||||
Root() string
|
||||
Indexer() CodeIntelIndexerResolver
|
||||
Indexes() []LSIFIndexResolver
|
||||
}
|
||||
|
||||
type IndexConfigurationResolver interface {
|
||||
Configuration(ctx context.Context) (*string, error)
|
||||
InferredConfiguration(ctx context.Context) (*string, error)
|
||||
}
|
||||
|
||||
type UpdateRepositoryIndexConfigurationArgs struct {
|
||||
Repository graphql.ID
|
||||
Configuration string
|
||||
}
|
||||
|
||||
type PreviewRepositoryFilterArgs struct {
|
||||
graphqlutil.ConnectionArgs
|
||||
Patterns []string
|
||||
After *string
|
||||
}
|
||||
|
||||
type RepositoryFilterPreviewResolver interface {
|
||||
Nodes() []*RepositoryResolver
|
||||
TotalCount() int32
|
||||
Limit() *int32
|
||||
TotalMatches() int32
|
||||
PageInfo() *graphqlutil.PageInfo
|
||||
}
|
||||
|
||||
type PreviewGitObjectFilterArgs struct {
|
||||
Type GitObjectType
|
||||
Pattern string
|
||||
}
|
||||
|
||||
type GitObjectFilterPreviewResolver interface {
|
||||
Name() string
|
||||
Rev() string
|
||||
}
|
||||
|
||||
type CodeIntelligenceConfigurationPolicyConnectionResolver interface {
|
||||
Nodes(ctx context.Context) ([]CodeIntelligenceConfigurationPolicyResolver, error)
|
||||
TotalCount(ctx context.Context) (*int32, error)
|
||||
PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error)
|
||||
}
|
||||
|
||||
type CodeIntelligenceConfigurationPolicyResolver interface {
|
||||
ID() graphql.ID
|
||||
Repository(ctx context.Context) (*RepositoryResolver, error)
|
||||
RepositoryPatterns() *[]string
|
||||
Name() string
|
||||
Type() (GitObjectType, error)
|
||||
Pattern() string
|
||||
Protected() bool
|
||||
RetentionEnabled() bool
|
||||
RetentionDurationHours() *int32
|
||||
RetainIntermediateCommits() bool
|
||||
IndexingEnabled() bool
|
||||
IndexCommitMaxAgeHours() *int32
|
||||
IndexIntermediateCommits() bool
|
||||
}
|
||||
|
||||
type CodeIntelligenceRetentionPolicyMatchesConnectionResolver interface {
|
||||
Nodes(ctx context.Context) ([]CodeIntelligenceRetentionPolicyMatchResolver, error)
|
||||
TotalCount(ctx context.Context) (*int32, error)
|
||||
PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error)
|
||||
}
|
||||
|
||||
type CodeIntelligenceRetentionPolicyMatchResolver interface {
|
||||
ConfigurationPolicy() CodeIntelligenceConfigurationPolicyResolver
|
||||
Matches() bool
|
||||
ProtectingCommits() *[]string
|
||||
}
|
||||
|
||||
type GitTreeEntryCodeIntelInfoArgs struct {
|
||||
Repo *types.Repo
|
||||
Path string
|
||||
Commit string
|
||||
}
|
||||
|
||||
type GitTreeCodeIntelSupportResolver interface {
|
||||
SearchBasedSupport(context.Context) (*[]GitTreeSearchBasedCoverage, error)
|
||||
PreciseSupport(context.Context) (*[]GitTreePreciseCoverage, error)
|
||||
}
|
||||
|
||||
type GitTreeSearchBasedCoverage interface {
|
||||
CoveredPaths() []string
|
||||
Support() SearchBasedSupportResolver
|
||||
}
|
||||
|
||||
type GitTreePreciseCoverage interface {
|
||||
Support() PreciseSupportResolver
|
||||
Confidence() string
|
||||
}
|
||||
|
||||
type GitBlobCodeIntelSupportResolver interface {
|
||||
SearchBasedSupport(context.Context) (SearchBasedSupportResolver, error)
|
||||
PreciseSupport(context.Context) (PreciseSupportResolver, error)
|
||||
}
|
||||
|
||||
type PreciseSupportResolver interface {
|
||||
SupportLevel() string
|
||||
Indexers() *[]CodeIntelIndexerResolver
|
||||
}
|
||||
|
||||
type CodeIntelIndexerResolver interface {
|
||||
Name() string
|
||||
URL() string
|
||||
}
|
||||
|
||||
type SearchBasedSupportResolver interface {
|
||||
SupportLevel() string
|
||||
Language() string
|
||||
}
|
||||
|
||||
type RequestLanguageSupportArgs struct {
|
||||
Language string
|
||||
CodeIntelligenceConfigurationPolicies(ctx context.Context, args *policiesgraphql.CodeIntelligenceConfigurationPoliciesArgs) (policiesgraphql.CodeIntelligenceConfigurationPolicyConnectionResolver, error)
|
||||
ConfigurationPolicyByID(ctx context.Context, id graphql.ID) (policiesgraphql.CodeIntelligenceConfigurationPolicyResolver, error)
|
||||
CreateCodeIntelligenceConfigurationPolicy(ctx context.Context, args *policiesgraphql.CreateCodeIntelligenceConfigurationPolicyArgs) (policiesgraphql.CodeIntelligenceConfigurationPolicyResolver, error)
|
||||
DeleteCodeIntelligenceConfigurationPolicy(ctx context.Context, args *policiesgraphql.DeleteCodeIntelligenceConfigurationPolicyArgs) (*sharedresolvers.EmptyResponse, error)
|
||||
PreviewGitObjectFilter(ctx context.Context, id graphql.ID, args *policiesgraphql.PreviewGitObjectFilterArgs) ([]policiesgraphql.GitObjectFilterPreviewResolver, error)
|
||||
PreviewRepositoryFilter(ctx context.Context, args *policiesgraphql.PreviewRepositoryFilterArgs) (policiesgraphql.RepositoryFilterPreviewResolver, error)
|
||||
UpdateCodeIntelligenceConfigurationPolicy(ctx context.Context, args *policiesgraphql.UpdateCodeIntelligenceConfigurationPolicyArgs) (*sharedresolvers.EmptyResponse, error)
|
||||
}
|
||||
|
||||
@ -252,7 +252,7 @@ type RepositoryFilterPreview {
|
||||
"""
|
||||
A list of repositories composing the current page.
|
||||
"""
|
||||
nodes: [Repository!]!
|
||||
nodes: [CodeIntelRepository!]!
|
||||
|
||||
"""
|
||||
The total number of repositories in this result set.
|
||||
@ -315,7 +315,7 @@ type CodeIntelligenceConfigurationPolicy implements Node {
|
||||
"""
|
||||
The repository to which this configuration policy applies.
|
||||
"""
|
||||
repository: Repository
|
||||
repository: CodeIntelRepository
|
||||
|
||||
"""
|
||||
The set of name patterns matching repositories to which this configuration policy applies.
|
||||
@ -973,7 +973,7 @@ type LSIFUpload implements Node {
|
||||
"""
|
||||
The project for which this upload provides code intelligence.
|
||||
"""
|
||||
projectRoot: GitTree
|
||||
projectRoot: CodeIntelGitTree
|
||||
|
||||
"""
|
||||
The original 40-character commit commit supplied at upload time.
|
||||
@ -1244,7 +1244,7 @@ type LSIFIndex implements Node {
|
||||
"""
|
||||
The project for which this upload provides code intelligence.
|
||||
"""
|
||||
projectRoot: GitTree
|
||||
projectRoot: CodeIntelGitTree
|
||||
|
||||
"""
|
||||
The original 40-character commit commit supplied at index time.
|
||||
|
||||
@ -17,10 +17,12 @@ import (
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/globals"
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/externallink"
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/internal/cloneurls"
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/internal/highlight"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/cloneurls"
|
||||
autoindexinggraphql "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/transport/graphql"
|
||||
codenavgraphql "github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/transport/graphql"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain"
|
||||
@ -233,7 +235,7 @@ func (r *GitTreeEntryResolver) IsSingleChild(ctx context.Context, args *gitTreeE
|
||||
return len(entries) == 1, nil
|
||||
}
|
||||
|
||||
func (r *GitTreeEntryResolver) LSIF(ctx context.Context, args *struct{ ToolName *string }) (GitBlobLSIFDataResolver, error) {
|
||||
func (r *GitTreeEntryResolver) LSIF(ctx context.Context, args *struct{ ToolName *string }) (codenavgraphql.GitBlobLSIFDataResolver, error) {
|
||||
codeIntelRequests.WithLabelValues(trace.RequestOrigin(ctx)).Inc()
|
||||
|
||||
var toolName string
|
||||
@ -246,7 +248,7 @@ func (r *GitTreeEntryResolver) LSIF(ctx context.Context, args *struct{ ToolName
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return EnterpriseResolvers.codeIntelResolver.GitBlobLSIFData(ctx, &GitBlobLSIFDataArgs{
|
||||
return EnterpriseResolvers.codeIntelResolver.GitBlobLSIFData(ctx, &codenavgraphql.GitBlobLSIFDataArgs{
|
||||
Repo: repo,
|
||||
Commit: api.CommitID(r.Commit().OID()),
|
||||
Path: r.Path(),
|
||||
@ -255,25 +257,25 @@ func (r *GitTreeEntryResolver) LSIF(ctx context.Context, args *struct{ ToolName
|
||||
})
|
||||
}
|
||||
|
||||
func (r *GitTreeEntryResolver) CodeIntelSupport(ctx context.Context) (GitBlobCodeIntelSupportResolver, error) {
|
||||
func (r *GitTreeEntryResolver) CodeIntelSupport(ctx context.Context) (autoindexinggraphql.GitBlobCodeIntelSupportResolver, error) {
|
||||
repo, err := r.commit.repoResolver.repo(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return EnterpriseResolvers.codeIntelResolver.GitBlobCodeIntelInfo(ctx, &GitTreeEntryCodeIntelInfoArgs{
|
||||
return EnterpriseResolvers.codeIntelResolver.GitBlobCodeIntelInfo(ctx, &autoindexinggraphql.GitTreeEntryCodeIntelInfoArgs{
|
||||
Repo: repo,
|
||||
Path: r.Path(),
|
||||
})
|
||||
}
|
||||
|
||||
func (r *GitTreeEntryResolver) CodeIntelInfo(ctx context.Context) (GitTreeCodeIntelSupportResolver, error) {
|
||||
func (r *GitTreeEntryResolver) CodeIntelInfo(ctx context.Context) (autoindexinggraphql.GitTreeCodeIntelSupportResolver, error) {
|
||||
repo, err := r.commit.repoResolver.repo(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return EnterpriseResolvers.codeIntelResolver.GitTreeCodeIntelInfo(ctx, &GitTreeEntryCodeIntelInfoArgs{
|
||||
return EnterpriseResolvers.codeIntelResolver.GitTreeCodeIntelInfo(ctx, &autoindexinggraphql.GitTreeEntryCodeIntelInfoArgs{
|
||||
Repo: repo,
|
||||
Commit: string(r.Commit().OID()),
|
||||
Path: r.Path(),
|
||||
|
||||
@ -22,9 +22,9 @@ import (
|
||||
sglog "github.com/sourcegraph/log"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/backend"
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/internal/cloneurls"
|
||||
"github.com/sourcegraph/sourcegraph/internal/actor"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/cloneurls"
|
||||
"github.com/sourcegraph/sourcegraph/internal/conf"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/errcode"
|
||||
|
||||
@ -6,6 +6,8 @@ import (
|
||||
"github.com/graph-gophers/graphql-go"
|
||||
"github.com/graph-gophers/graphql-go/relay"
|
||||
|
||||
policiesgraphql "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/transport/graphql"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/sharedresolvers"
|
||||
executor "github.com/sourcegraph/sourcegraph/internal/services/executors/transport/graphql"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
)
|
||||
@ -218,18 +220,18 @@ func (r *NodeResolver) ToSite() (*siteResolver, bool) {
|
||||
return n, ok
|
||||
}
|
||||
|
||||
func (r *NodeResolver) ToLSIFUpload() (LSIFUploadResolver, bool) {
|
||||
n, ok := r.Node.(LSIFUploadResolver)
|
||||
func (r *NodeResolver) ToLSIFUpload() (sharedresolvers.LSIFUploadResolver, bool) {
|
||||
n, ok := r.Node.(sharedresolvers.LSIFUploadResolver)
|
||||
return n, ok
|
||||
}
|
||||
|
||||
func (r *NodeResolver) ToLSIFIndex() (LSIFIndexResolver, bool) {
|
||||
n, ok := r.Node.(LSIFIndexResolver)
|
||||
func (r *NodeResolver) ToLSIFIndex() (sharedresolvers.LSIFIndexResolver, bool) {
|
||||
n, ok := r.Node.(sharedresolvers.LSIFIndexResolver)
|
||||
return n, ok
|
||||
}
|
||||
|
||||
func (r *NodeResolver) ToCodeIntelligenceConfigurationPolicy() (CodeIntelligenceConfigurationPolicyResolver, bool) {
|
||||
n, ok := r.Node.(CodeIntelligenceConfigurationPolicyResolver)
|
||||
func (r *NodeResolver) ToCodeIntelligenceConfigurationPolicy() (policiesgraphql.CodeIntelligenceConfigurationPolicyResolver, bool) {
|
||||
n, ok := r.Node.(policiesgraphql.CodeIntelligenceConfigurationPolicyResolver)
|
||||
return n, ok
|
||||
}
|
||||
|
||||
|
||||
@ -15,6 +15,10 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/backend"
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/externallink"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
autoindex "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/transport/graphql"
|
||||
policies "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/transport/graphql"
|
||||
resolvers "github.com/sourcegraph/sourcegraph/internal/codeintel/sharedresolvers"
|
||||
uploads "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/transport/graphql"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/extsvc"
|
||||
"github.com/sourcegraph/sourcegraph/internal/extsvc/phabricator"
|
||||
@ -356,33 +360,33 @@ func (r *RepositoryResolver) hydrate(ctx context.Context) error {
|
||||
return r.err
|
||||
}
|
||||
|
||||
func (r *RepositoryResolver) LSIFUploads(ctx context.Context, args *LSIFUploadsQueryArgs) (LSIFUploadConnectionResolver, error) {
|
||||
return EnterpriseResolvers.codeIntelResolver.LSIFUploadsByRepo(ctx, &LSIFRepositoryUploadsQueryArgs{
|
||||
func (r *RepositoryResolver) LSIFUploads(ctx context.Context, args *uploads.LSIFUploadsQueryArgs) (resolvers.LSIFUploadConnectionResolver, error) {
|
||||
return EnterpriseResolvers.codeIntelResolver.LSIFUploadsByRepo(ctx, &uploads.LSIFRepositoryUploadsQueryArgs{
|
||||
LSIFUploadsQueryArgs: args,
|
||||
RepositoryID: r.ID(),
|
||||
})
|
||||
}
|
||||
|
||||
func (r *RepositoryResolver) LSIFIndexes(ctx context.Context, args *LSIFIndexesQueryArgs) (LSIFIndexConnectionResolver, error) {
|
||||
return EnterpriseResolvers.codeIntelResolver.LSIFIndexesByRepo(ctx, &LSIFRepositoryIndexesQueryArgs{
|
||||
func (r *RepositoryResolver) LSIFIndexes(ctx context.Context, args *autoindex.LSIFIndexesQueryArgs) (resolvers.LSIFIndexConnectionResolver, error) {
|
||||
return EnterpriseResolvers.codeIntelResolver.LSIFIndexesByRepo(ctx, &autoindex.LSIFRepositoryIndexesQueryArgs{
|
||||
LSIFIndexesQueryArgs: args,
|
||||
RepositoryID: r.ID(),
|
||||
})
|
||||
}
|
||||
|
||||
func (r *RepositoryResolver) IndexConfiguration(ctx context.Context) (IndexConfigurationResolver, error) {
|
||||
func (r *RepositoryResolver) IndexConfiguration(ctx context.Context) (autoindex.IndexConfigurationResolver, error) {
|
||||
return EnterpriseResolvers.codeIntelResolver.IndexConfiguration(ctx, r.ID())
|
||||
}
|
||||
|
||||
func (r *RepositoryResolver) CodeIntelligenceCommitGraph(ctx context.Context) (CodeIntelligenceCommitGraphResolver, error) {
|
||||
func (r *RepositoryResolver) CodeIntelligenceCommitGraph(ctx context.Context) (uploads.CodeIntelligenceCommitGraphResolver, error) {
|
||||
return EnterpriseResolvers.codeIntelResolver.CommitGraph(ctx, r.ID())
|
||||
}
|
||||
|
||||
func (r *RepositoryResolver) CodeIntelSummary(ctx context.Context) (CodeIntelRepositorySummaryResolver, error) {
|
||||
func (r *RepositoryResolver) CodeIntelSummary(ctx context.Context) (resolvers.CodeIntelRepositorySummaryResolver, error) {
|
||||
return EnterpriseResolvers.codeIntelResolver.RepositorySummary(ctx, r.ID())
|
||||
}
|
||||
|
||||
func (r *RepositoryResolver) PreviewGitObjectFilter(ctx context.Context, args *PreviewGitObjectFilterArgs) ([]GitObjectFilterPreviewResolver, error) {
|
||||
func (r *RepositoryResolver) PreviewGitObjectFilter(ctx context.Context, args *policies.PreviewGitObjectFilterArgs) ([]policies.GitObjectFilterPreviewResolver, error) {
|
||||
return EnterpriseResolvers.codeIntelResolver.PreviewGitObjectFilter(ctx, r.ID(), args)
|
||||
}
|
||||
|
||||
@ -415,7 +419,8 @@ func (r *schemaResolver) AddPhabricatorRepo(ctx context.Context, args *struct {
|
||||
// TODO(chris): Remove URI in favor of Name.
|
||||
URI *string
|
||||
URL string
|
||||
}) (*EmptyResponse, error) {
|
||||
},
|
||||
) (*EmptyResponse, error) {
|
||||
if args.Name != nil {
|
||||
args.URI = args.Name
|
||||
}
|
||||
@ -436,7 +441,8 @@ func (r *schemaResolver) ResolvePhabricatorDiff(ctx context.Context, args *struc
|
||||
AuthorEmail *string
|
||||
Description *string
|
||||
Date *string
|
||||
}) (*GitCommitResolver, error) {
|
||||
},
|
||||
) (*GitCommitResolver, error) {
|
||||
db := r.db
|
||||
repo, err := db.Repos().GetByName(ctx, api.RepoName(args.RepoName))
|
||||
if err != nil {
|
||||
@ -609,7 +615,8 @@ func (r *schemaResolver) AddRepoKeyValuePair(ctx context.Context, args struct {
|
||||
Repo graphql.ID
|
||||
Key string
|
||||
Value *string
|
||||
}) (*EmptyResponse, error) {
|
||||
},
|
||||
) (*EmptyResponse, error) {
|
||||
if err := backend.CheckCurrentUserIsSiteAdmin(ctx, r.db); err != nil {
|
||||
return &EmptyResponse{}, err
|
||||
}
|
||||
@ -626,7 +633,8 @@ func (r *schemaResolver) UpdateRepoKeyValuePair(ctx context.Context, args struct
|
||||
Repo graphql.ID
|
||||
Key string
|
||||
Value *string
|
||||
}) (*EmptyResponse, error) {
|
||||
},
|
||||
) (*EmptyResponse, error) {
|
||||
if err := backend.CheckCurrentUserIsSiteAdmin(ctx, r.db); err != nil {
|
||||
return &EmptyResponse{}, err
|
||||
}
|
||||
@ -643,7 +651,8 @@ func (r *schemaResolver) UpdateRepoKeyValuePair(ctx context.Context, args struct
|
||||
func (r *schemaResolver) DeleteRepoKeyValuePair(ctx context.Context, args struct {
|
||||
Repo graphql.ID
|
||||
Key string
|
||||
}) (*EmptyResponse, error) {
|
||||
},
|
||||
) (*EmptyResponse, error) {
|
||||
if err := backend.CheckCurrentUserIsSiteAdmin(ctx, r.db); err != nil {
|
||||
return &EmptyResponse{}, err
|
||||
}
|
||||
|
||||
@ -3648,6 +3648,85 @@ type Symbol {
|
||||
fileLocal: Boolean!
|
||||
}
|
||||
|
||||
"""
|
||||
A gitblob resolver specific to code intel.
|
||||
"""
|
||||
type CodeIntelGitBlob {
|
||||
"""
|
||||
The full path (relative to the root) of this tree.
|
||||
"""
|
||||
path: String!
|
||||
"""
|
||||
The base name (i.e., last path component only) of this tree.
|
||||
"""
|
||||
name: String!
|
||||
"""
|
||||
The Git commit containing this tree.
|
||||
"""
|
||||
commit: CodeIntelCommit!
|
||||
"""
|
||||
The URL to this tree (using the input revision specifier, which may not be immutable).
|
||||
"""
|
||||
url: String!
|
||||
"""
|
||||
The repository containing this tree.
|
||||
"""
|
||||
repository: CodeIntelRepository!
|
||||
"""
|
||||
The content of this blob.
|
||||
"""
|
||||
content: String!
|
||||
}
|
||||
|
||||
"""
|
||||
A codeintel repository is a Git source control repository that is mirrored from some origin code host and it is specific to code intel.
|
||||
"""
|
||||
type CodeIntelRepository {
|
||||
"""
|
||||
The globally addressable ID for this commit.
|
||||
"""
|
||||
id: ID!
|
||||
"""
|
||||
The repository's name, as a path with one or more components. It conventionally consists of
|
||||
the repository's hostname and path (joined by "/"), minus any suffixes (such as ".git").
|
||||
Examples:
|
||||
- github.com/foo/bar
|
||||
- my-code-host.example.com/myrepo
|
||||
- myrepo
|
||||
"""
|
||||
name: String!
|
||||
"""
|
||||
The URL to this repository.
|
||||
"""
|
||||
url: String!
|
||||
}
|
||||
|
||||
"""
|
||||
A Code Intel Commit.
|
||||
"""
|
||||
type CodeIntelCommit {
|
||||
"""
|
||||
The globally addressable ID for this commit.
|
||||
"""
|
||||
id: ID!
|
||||
"""
|
||||
This commit's Git object ID (OID), a 40-character SHA-1 hash.
|
||||
"""
|
||||
oid: GitObjectID!
|
||||
"""
|
||||
The abbreviated form of this commit's OID.
|
||||
"""
|
||||
abbreviatedOID: String!
|
||||
"""
|
||||
The URL to this commit (using the input revision specifier, which may not be immutable).
|
||||
"""
|
||||
url: String!
|
||||
"""
|
||||
The repository that contains this commit.
|
||||
"""
|
||||
repository: CodeIntelRepository!
|
||||
}
|
||||
|
||||
"""
|
||||
A location inside a resource (in a repository at a specific commit).
|
||||
"""
|
||||
@ -3655,7 +3734,7 @@ type Location {
|
||||
"""
|
||||
The file that this location refers to.
|
||||
"""
|
||||
resource: GitBlob!
|
||||
resource: CodeIntelGitBlob!
|
||||
"""
|
||||
The range inside the file that this location refers to.
|
||||
"""
|
||||
@ -4359,6 +4438,36 @@ interface TreeEntry {
|
||||
): Boolean!
|
||||
}
|
||||
|
||||
"""
|
||||
A Code Intel Git Tree.
|
||||
"""
|
||||
type CodeIntelGitTree {
|
||||
"""
|
||||
The full path (relative to the root) of this tree.
|
||||
"""
|
||||
path: String!
|
||||
"""
|
||||
The base name (i.e., last path component only) of this tree.
|
||||
"""
|
||||
name: String!
|
||||
"""
|
||||
The Git commit containing this tree.
|
||||
"""
|
||||
commit: CodeIntelCommit!
|
||||
"""
|
||||
The URL to this tree (using the input revision specifier, which may not be immutable).
|
||||
"""
|
||||
url: String!
|
||||
"""
|
||||
The repository containing this tree.
|
||||
"""
|
||||
repository: CodeIntelRepository!
|
||||
"""
|
||||
The content of this blob.
|
||||
"""
|
||||
content: String!
|
||||
}
|
||||
|
||||
"""
|
||||
A Git tree in a repository.
|
||||
"""
|
||||
|
||||
@ -15,8 +15,8 @@ import (
|
||||
"github.com/sourcegraph/log"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/backend"
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/internal/cloneurls"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/cloneurls"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
)
|
||||
|
||||
@ -16,7 +16,6 @@ import (
|
||||
policiesgraphql "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/transport/graphql"
|
||||
uploadgraphql "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/transport/graphql"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/honey"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
executorgraphql "github.com/sourcegraph/sourcegraph/internal/services/executors/transport/graphql"
|
||||
"github.com/sourcegraph/sourcegraph/internal/trace"
|
||||
@ -32,16 +31,15 @@ func Init(ctx context.Context, db database.DB, config *Config, enterpriseService
|
||||
}
|
||||
|
||||
executorResolver := executorgraphql.New(db)
|
||||
codenavResolver := codenavgraphql.New(services.CodeNavSvc, services.gitserverClient, services.AutoIndexingSvc, config.MaximumIndexesPerMonikerSearch, config.HunkCacheSize, oc("codenav"))
|
||||
policyResolver := policiesgraphql.New(services.PoliciesSvc, oc("policies"))
|
||||
autoindexingResolver := autoindexinggraphql.New(services.AutoIndexingSvc, oc("autoindexing"))
|
||||
uploadResolver := uploadgraphql.New(services.UploadSvc, oc("upload"))
|
||||
|
||||
innerResolver := codeintelresolvers.NewResolver(codenavResolver, executorResolver, policyResolver, autoindexingResolver, uploadResolver)
|
||||
codenavRootResolver := codenavgraphql.NewRootResolver(services.CodeNavSvc, services.AutoIndexingSvc, services.UploadSvc, services.PoliciesSvc, services.gitserverClient, config.MaximumIndexesPerMonikerSearch, config.HunkCacheSize, oc("codenav"))
|
||||
policyRootResolver := policiesgraphql.NewRootResolver(services.PoliciesSvc, oc("policies"))
|
||||
autoindexingRootResolver := autoindexinggraphql.NewRootResolver(services.AutoIndexingSvc, services.UploadSvc, services.PoliciesSvc, oc("autoindexing"))
|
||||
uploadRootResolver := uploadgraphql.NewRootResolver(services.UploadSvc, services.AutoIndexingSvc, services.PoliciesSvc, oc("upload"))
|
||||
|
||||
observationCtx := &observation.Context{Logger: nil, Tracer: &trace.Tracer{}, Registerer: nil, HoneyDataset: &honey.Dataset{}}
|
||||
resolvers := codeintelresolvers.NewResolver(codenavRootResolver, executorResolver, policyRootResolver, autoindexingRootResolver, uploadRootResolver)
|
||||
|
||||
enterpriseServices.CodeIntelResolver = codeintelgqlresolvers.NewResolver(db, services.gitserverClient, innerResolver, observationCtx)
|
||||
enterpriseServices.CodeIntelResolver = codeintelgqlresolvers.NewResolver(resolvers)
|
||||
enterpriseServices.NewCodeIntelUploadHandler = newUploadHandler(services)
|
||||
|
||||
return nil
|
||||
|
||||
@ -1,60 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/graph-gophers/graphql-go"
|
||||
|
||||
gql "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
uploadsShared "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared"
|
||||
)
|
||||
|
||||
type auditLogColumnChangeResolver struct {
|
||||
columnTransition map[string]*string
|
||||
}
|
||||
|
||||
func (r *auditLogColumnChangeResolver) Column() string {
|
||||
return *r.columnTransition["column"]
|
||||
}
|
||||
|
||||
func (r *auditLogColumnChangeResolver) Old() *string {
|
||||
return r.columnTransition["old"]
|
||||
}
|
||||
|
||||
func (r *auditLogColumnChangeResolver) New() *string {
|
||||
return r.columnTransition["new"]
|
||||
}
|
||||
|
||||
type lsifUploadsAuditLogResolver struct {
|
||||
log uploadsShared.UploadLog
|
||||
}
|
||||
|
||||
func (r *lsifUploadsAuditLogResolver) Reason() *string { return r.log.Reason }
|
||||
func (r *lsifUploadsAuditLogResolver) ChangedColumns() (values []gql.AuditLogColumnChange) {
|
||||
for _, transition := range r.log.TransitionColumns {
|
||||
values = append(values, &auditLogColumnChangeResolver{transition})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (r *lsifUploadsAuditLogResolver) LogTimestamp() gql.DateTime {
|
||||
return gql.DateTime{Time: r.log.LogTimestamp}
|
||||
}
|
||||
|
||||
func (r *lsifUploadsAuditLogResolver) UploadDeletedAt() *gql.DateTime {
|
||||
return gql.DateTimeOrNil(r.log.RecordDeletedAt)
|
||||
}
|
||||
|
||||
func (r *lsifUploadsAuditLogResolver) UploadID() graphql.ID {
|
||||
return marshalLSIFUploadGQLID(int64(r.log.UploadID))
|
||||
}
|
||||
func (r *lsifUploadsAuditLogResolver) InputCommit() string { return r.log.Commit }
|
||||
func (r *lsifUploadsAuditLogResolver) InputRoot() string { return r.log.Root }
|
||||
func (r *lsifUploadsAuditLogResolver) InputIndexer() string { return r.log.Indexer }
|
||||
func (r *lsifUploadsAuditLogResolver) UploadedAt() gql.DateTime {
|
||||
return gql.DateTime{Time: r.log.UploadedAt}
|
||||
}
|
||||
|
||||
func (r *lsifUploadsAuditLogResolver) Operation() string {
|
||||
return strings.ToUpper(r.log.Operation)
|
||||
}
|
||||
@ -1,145 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
gql "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
"github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/codeintel/resolvers"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/codeintel/autoindex/config"
|
||||
)
|
||||
|
||||
type preciseSupportInferenceConfidence string
|
||||
|
||||
const (
|
||||
languageSupport preciseSupportInferenceConfidence = "LANGUAGE_SUPPORTED"
|
||||
projectStructureSupported preciseSupportInferenceConfidence = "PROJECT_STRUCTURE_SUPPORTED"
|
||||
indexJobInfered preciseSupportInferenceConfidence = "INDEX_JOB_INFERED"
|
||||
)
|
||||
|
||||
type codeIntelTreeInfoResolver struct {
|
||||
resolver resolvers.Resolver
|
||||
commit string
|
||||
path string
|
||||
files []string
|
||||
repo *types.Repo
|
||||
errTracer *observation.ErrCollector
|
||||
}
|
||||
|
||||
func NewCodeIntelTreeInfoResolver(
|
||||
resolver resolvers.Resolver,
|
||||
repo *types.Repo,
|
||||
commit, path string,
|
||||
files []string,
|
||||
errTracer *observation.ErrCollector,
|
||||
) gql.GitTreeCodeIntelSupportResolver {
|
||||
return &codeIntelTreeInfoResolver{
|
||||
resolver: resolver,
|
||||
repo: repo,
|
||||
commit: commit,
|
||||
path: path,
|
||||
files: files,
|
||||
errTracer: errTracer,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *codeIntelTreeInfoResolver) SearchBasedSupport(ctx context.Context) (*[]gql.GitTreeSearchBasedCoverage, error) {
|
||||
langMapping := make(map[string][]string)
|
||||
codeNavResolver := r.resolver.CodeNavResolver()
|
||||
for _, file := range r.files {
|
||||
ok, lang, err := codeNavResolver.GetSupportedByCtags(ctx, file, r.repo.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if ok {
|
||||
langMapping[lang] = append(langMapping[lang], file)
|
||||
}
|
||||
}
|
||||
|
||||
resolvers := make([]gql.GitTreeSearchBasedCoverage, 0, len(langMapping))
|
||||
|
||||
for lang, files := range langMapping {
|
||||
resolvers = append(resolvers, &codeIntelTreeSearchBasedCoverageResolver{
|
||||
paths: files,
|
||||
language: lang,
|
||||
})
|
||||
}
|
||||
|
||||
return &resolvers, nil
|
||||
}
|
||||
|
||||
func (r *codeIntelTreeInfoResolver) PreciseSupport(ctx context.Context) (*[]gql.GitTreePreciseCoverage, error) {
|
||||
autoIndexingResolver := r.resolver.AutoIndexingResolver()
|
||||
configurations, ok, err := autoIndexingResolver.InferedIndexConfiguration(ctx, int(r.repo.ID), r.commit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resolvers []gql.GitTreePreciseCoverage
|
||||
|
||||
if ok {
|
||||
for _, job := range configurations.IndexJobs {
|
||||
if job.Root == r.path {
|
||||
resolvers = append(resolvers, &codeIntelTreePreciseCoverageResolver{
|
||||
confidence: indexJobInfered,
|
||||
// drop the tag if it exists
|
||||
indexer: imageToIndexer[strings.Split(job.Indexer, ":")[0]],
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hints, err := autoIndexingResolver.InferedIndexConfigurationHints(ctx, int(r.repo.ID), r.commit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, hint := range hints {
|
||||
if hint.Root == r.path {
|
||||
var confidence preciseSupportInferenceConfidence
|
||||
switch hint.HintConfidence {
|
||||
case config.HintConfidenceLanguageSupport:
|
||||
confidence = languageSupport
|
||||
case config.HintConfidenceProjectStructureSupported:
|
||||
confidence = projectStructureSupported
|
||||
default:
|
||||
continue
|
||||
}
|
||||
resolvers = append(resolvers, &codeIntelTreePreciseCoverageResolver{
|
||||
confidence: confidence,
|
||||
// expected that job hints don't include a tag in the indexer name
|
||||
indexer: imageToIndexer[hint.Indexer],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return &resolvers, nil
|
||||
}
|
||||
|
||||
type codeIntelTreePreciseCoverageResolver struct {
|
||||
confidence preciseSupportInferenceConfidence
|
||||
indexer gql.CodeIntelIndexerResolver
|
||||
}
|
||||
|
||||
func (r *codeIntelTreePreciseCoverageResolver) Support() gql.PreciseSupportResolver {
|
||||
return NewPreciseCodeIntelSupportResolverFromIndexers([]gql.CodeIntelIndexerResolver{r.indexer})
|
||||
}
|
||||
|
||||
func (r *codeIntelTreePreciseCoverageResolver) Confidence() string {
|
||||
return string(r.confidence)
|
||||
}
|
||||
|
||||
type codeIntelTreeSearchBasedCoverageResolver struct {
|
||||
paths []string
|
||||
language string
|
||||
}
|
||||
|
||||
func (r *codeIntelTreeSearchBasedCoverageResolver) CoveredPaths() []string {
|
||||
return r.paths
|
||||
}
|
||||
|
||||
func (r *codeIntelTreeSearchBasedCoverageResolver) Support() gql.SearchBasedSupportResolver {
|
||||
return NewSearchBasedCodeIntelResolver(r.language)
|
||||
}
|
||||
@ -1,45 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
gql "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/stores/dbstore"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
)
|
||||
|
||||
type codeIntelligenceConfigurationPolicyConnectionResolver struct {
|
||||
db database.DB
|
||||
policies []dbstore.ConfigurationPolicy
|
||||
totalCount int
|
||||
errTracer *observation.ErrCollector
|
||||
}
|
||||
|
||||
func NewCodeIntelligenceConfigurationPolicyConnectionResolver(db database.DB, policies []dbstore.ConfigurationPolicy, totalCount int, errTracer *observation.ErrCollector) gql.CodeIntelligenceConfigurationPolicyConnectionResolver {
|
||||
return &codeIntelligenceConfigurationPolicyConnectionResolver{
|
||||
db: db,
|
||||
policies: policies,
|
||||
totalCount: totalCount,
|
||||
errTracer: errTracer,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *codeIntelligenceConfigurationPolicyConnectionResolver) Nodes(ctx context.Context) ([]gql.CodeIntelligenceConfigurationPolicyResolver, error) {
|
||||
resolvers := make([]gql.CodeIntelligenceConfigurationPolicyResolver, 0, len(r.policies))
|
||||
for _, policy := range r.policies {
|
||||
resolvers = append(resolvers, NewConfigurationPolicyResolver(r.db, policy, r.errTracer))
|
||||
}
|
||||
|
||||
return resolvers, nil
|
||||
}
|
||||
|
||||
func (r *codeIntelligenceConfigurationPolicyConnectionResolver) TotalCount(ctx context.Context) (*int32, error) {
|
||||
v := int32(r.totalCount)
|
||||
return &v, nil
|
||||
}
|
||||
|
||||
func (r *codeIntelligenceConfigurationPolicyConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) {
|
||||
return graphqlutil.HasNextPage(len(r.policies) < r.totalCount), nil
|
||||
}
|
||||
@ -1,85 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil"
|
||||
)
|
||||
|
||||
func TestCursor(t *testing.T) {
|
||||
expected := "test"
|
||||
pageInfo := graphqlutil.EncodeCursor(&expected)
|
||||
|
||||
if !pageInfo.HasNextPage() {
|
||||
t.Fatalf("expected next page")
|
||||
}
|
||||
if pageInfo.EndCursor() == nil {
|
||||
t.Fatalf("unexpected nil cursor")
|
||||
}
|
||||
|
||||
value, err := graphqlutil.DecodeCursor(pageInfo.EndCursor())
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error decoding cursor: %s", err)
|
||||
}
|
||||
if value != expected {
|
||||
t.Errorf("unexpected decoded cursor. want=%s have=%s", expected, value)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCursorEmpty(t *testing.T) {
|
||||
pageInfo := graphqlutil.EncodeCursor(nil)
|
||||
|
||||
if pageInfo.HasNextPage() {
|
||||
t.Errorf("unexpected next page")
|
||||
}
|
||||
if pageInfo.EndCursor() != nil {
|
||||
t.Errorf("unexpected encoded cursor: %s", *pageInfo.EndCursor())
|
||||
}
|
||||
|
||||
value, err := graphqlutil.DecodeCursor(nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error decoding cursor: %s", err)
|
||||
}
|
||||
if value != "" {
|
||||
t.Errorf("unexpected decoded cursor: %s", value)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntCursor(t *testing.T) {
|
||||
expected := 42
|
||||
pageInfo := graphqlutil.EncodeIntCursor(toInt32(&expected))
|
||||
|
||||
if !pageInfo.HasNextPage() {
|
||||
t.Fatalf("expected next page")
|
||||
}
|
||||
if pageInfo.EndCursor() == nil {
|
||||
t.Fatalf("unexpected nil cursor")
|
||||
}
|
||||
|
||||
value, err := graphqlutil.DecodeIntCursor(pageInfo.EndCursor())
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error decoding cursor: %s", err)
|
||||
}
|
||||
if value != expected {
|
||||
t.Errorf("unexpected decoded cursor. want=%d have=%d", expected, value)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntCursorEmpty(t *testing.T) {
|
||||
pageInfo := graphqlutil.EncodeIntCursor(nil)
|
||||
|
||||
if pageInfo.HasNextPage() {
|
||||
t.Errorf("unexpected next page")
|
||||
}
|
||||
if pageInfo.EndCursor() != nil {
|
||||
t.Errorf("unexpected encoded cursor: %s", *pageInfo.EndCursor())
|
||||
}
|
||||
|
||||
value, err := graphqlutil.DecodeIntCursor(nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error decoding cursor: %s", err)
|
||||
}
|
||||
if value != 0 {
|
||||
t.Errorf("unexpected decoded cursor: %d", value)
|
||||
}
|
||||
}
|
||||
@ -1,54 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
gql "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
)
|
||||
|
||||
type DiagnosticResolver struct {
|
||||
diagnostic AdjustedDiagnostic
|
||||
locationResolver *CachedLocationResolver
|
||||
}
|
||||
|
||||
func NewDiagnosticResolver(diagnostic AdjustedDiagnostic, locationResolver *CachedLocationResolver) gql.DiagnosticResolver {
|
||||
return &DiagnosticResolver{
|
||||
diagnostic: diagnostic,
|
||||
locationResolver: locationResolver,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *DiagnosticResolver) Severity() (*string, error) { return toSeverity(r.diagnostic.Severity) }
|
||||
func (r *DiagnosticResolver) Code() (*string, error) { return strPtr(r.diagnostic.Code), nil }
|
||||
func (r *DiagnosticResolver) Source() (*string, error) { return strPtr(r.diagnostic.Source), nil }
|
||||
func (r *DiagnosticResolver) Message() (*string, error) { return strPtr(r.diagnostic.Message), nil }
|
||||
|
||||
func (r *DiagnosticResolver) Location(ctx context.Context) (gql.LocationResolver, error) {
|
||||
return resolveLocation(
|
||||
ctx,
|
||||
r.locationResolver,
|
||||
AdjustedLocation{
|
||||
Dump: r.diagnostic.Dump,
|
||||
Path: r.diagnostic.Path,
|
||||
AdjustedCommit: r.diagnostic.AdjustedCommit,
|
||||
AdjustedRange: r.diagnostic.AdjustedRange,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
var severities = map[int]string{
|
||||
1: "ERROR",
|
||||
2: "WARNING",
|
||||
3: "INFORMATION",
|
||||
4: "HINT",
|
||||
}
|
||||
|
||||
func toSeverity(val int) (*string, error) {
|
||||
severity, ok := severities[val]
|
||||
if !ok {
|
||||
return nil, errors.Errorf("unknown diagnostic severity %d", val)
|
||||
}
|
||||
|
||||
return &severity, nil
|
||||
}
|
||||
@ -1,38 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
gql "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil"
|
||||
)
|
||||
|
||||
type DiagnosticConnectionResolver struct {
|
||||
diagnostics []AdjustedDiagnostic
|
||||
totalCount int
|
||||
locationResolver *CachedLocationResolver
|
||||
}
|
||||
|
||||
func NewDiagnosticConnectionResolver(diagnostics []AdjustedDiagnostic, totalCount int, locationResolver *CachedLocationResolver) gql.DiagnosticConnectionResolver {
|
||||
return &DiagnosticConnectionResolver{
|
||||
diagnostics: diagnostics,
|
||||
totalCount: totalCount,
|
||||
locationResolver: locationResolver,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *DiagnosticConnectionResolver) Nodes(ctx context.Context) ([]gql.DiagnosticResolver, error) {
|
||||
resolvers := make([]gql.DiagnosticResolver, 0, len(r.diagnostics))
|
||||
for i := range r.diagnostics {
|
||||
resolvers = append(resolvers, NewDiagnosticResolver(r.diagnostics[i], r.locationResolver))
|
||||
}
|
||||
return resolvers, nil
|
||||
}
|
||||
|
||||
func (r *DiagnosticConnectionResolver) TotalCount(ctx context.Context) (int32, error) {
|
||||
return int32(r.totalCount), nil
|
||||
}
|
||||
|
||||
func (r *DiagnosticConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) {
|
||||
return graphqlutil.HasNextPage(len(r.diagnostics) < r.totalCount), nil
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import "context"
|
||||
|
||||
type uploadDocumentPathsConnectionResolver struct {
|
||||
totalCount int
|
||||
documents []string
|
||||
}
|
||||
|
||||
func (r *uploadDocumentPathsConnectionResolver) Nodes(ctx context.Context) ([]string, error) {
|
||||
return r.documents, nil
|
||||
}
|
||||
|
||||
func (r *uploadDocumentPathsConnectionResolver) TotalCount(ctx context.Context) (*int32, error) {
|
||||
count := int32(r.totalCount)
|
||||
return &count, nil
|
||||
}
|
||||
@ -1,110 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/graph-gophers/graphql-go"
|
||||
|
||||
gql "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
)
|
||||
|
||||
type frankenResolver struct {
|
||||
*Resolver
|
||||
gql.AutoindexingServiceResolver
|
||||
gql.UploadsServiceResolver
|
||||
gql.PoliciesServiceResolver
|
||||
}
|
||||
|
||||
func (r *frankenResolver) getAutoindexingServiceResolver() gql.AutoindexingServiceResolver {
|
||||
return r.Resolver
|
||||
}
|
||||
|
||||
func (r *frankenResolver) LSIFIndexByID(ctx context.Context, id graphql.ID) (_ gql.LSIFIndexResolver, err error) {
|
||||
return r.getAutoindexingServiceResolver().LSIFIndexByID(ctx, id)
|
||||
}
|
||||
|
||||
func (r *frankenResolver) LSIFIndexes(ctx context.Context, args *gql.LSIFIndexesQueryArgs) (_ gql.LSIFIndexConnectionResolver, err error) {
|
||||
return r.getAutoindexingServiceResolver().LSIFIndexes(ctx, args)
|
||||
}
|
||||
|
||||
func (r *frankenResolver) LSIFIndexesByRepo(ctx context.Context, args *gql.LSIFRepositoryIndexesQueryArgs) (_ gql.LSIFIndexConnectionResolver, err error) {
|
||||
return r.getAutoindexingServiceResolver().LSIFIndexesByRepo(ctx, args)
|
||||
}
|
||||
|
||||
func (r *frankenResolver) DeleteLSIFIndex(ctx context.Context, args *struct{ ID graphql.ID }) (_ *gql.EmptyResponse, err error) {
|
||||
return r.getAutoindexingServiceResolver().DeleteLSIFIndex(ctx, args)
|
||||
}
|
||||
|
||||
func (r *frankenResolver) QueueAutoIndexJobsForRepo(ctx context.Context, args *gql.QueueAutoIndexJobsForRepoArgs) (_ []gql.LSIFIndexResolver, err error) {
|
||||
return r.getAutoindexingServiceResolver().QueueAutoIndexJobsForRepo(ctx, args)
|
||||
}
|
||||
|
||||
func (r *frankenResolver) IndexConfiguration(ctx context.Context, id graphql.ID) (_ gql.IndexConfigurationResolver, err error) {
|
||||
return r.getAutoindexingServiceResolver().IndexConfiguration(ctx, id)
|
||||
}
|
||||
|
||||
func (r *frankenResolver) UpdateRepositoryIndexConfiguration(ctx context.Context, args *gql.UpdateRepositoryIndexConfigurationArgs) (_ *gql.EmptyResponse, err error) {
|
||||
return r.getAutoindexingServiceResolver().UpdateRepositoryIndexConfiguration(ctx, args)
|
||||
}
|
||||
|
||||
func (r *frankenResolver) getUploadsServiceResolver() gql.UploadsServiceResolver {
|
||||
return r.Resolver
|
||||
|
||||
// Uncomment after https://github.com/sourcegraph/sourcegraph/issues/33375
|
||||
// return r.UploadsServiceResolver
|
||||
}
|
||||
|
||||
func (r *frankenResolver) LSIFUploadByID(ctx context.Context, id graphql.ID) (_ gql.LSIFUploadResolver, err error) {
|
||||
return r.getUploadsServiceResolver().LSIFUploadByID(ctx, id)
|
||||
}
|
||||
|
||||
func (r *frankenResolver) LSIFUploads(ctx context.Context, args *gql.LSIFUploadsQueryArgs) (_ gql.LSIFUploadConnectionResolver, err error) {
|
||||
return r.getUploadsServiceResolver().LSIFUploads(ctx, args)
|
||||
}
|
||||
|
||||
func (r *frankenResolver) LSIFUploadsByRepo(ctx context.Context, args *gql.LSIFRepositoryUploadsQueryArgs) (_ gql.LSIFUploadConnectionResolver, err error) {
|
||||
return r.getUploadsServiceResolver().LSIFUploadsByRepo(ctx, args)
|
||||
}
|
||||
|
||||
func (r *frankenResolver) DeleteLSIFUpload(ctx context.Context, args *struct{ ID graphql.ID }) (_ *gql.EmptyResponse, err error) {
|
||||
return r.getUploadsServiceResolver().DeleteLSIFUpload(ctx, args)
|
||||
}
|
||||
|
||||
func (r *frankenResolver) CommitGraph(ctx context.Context, id graphql.ID) (_ gql.CodeIntelligenceCommitGraphResolver, err error) {
|
||||
return r.getUploadsServiceResolver().CommitGraph(ctx, id)
|
||||
}
|
||||
|
||||
func (r *frankenResolver) getPoliciesServiceResolver() gql.PoliciesServiceResolver {
|
||||
return r.Resolver
|
||||
|
||||
// Uncomment after https://github.com/sourcegraph/sourcegraph/issues/33376
|
||||
// return r.PoliciesServiceResolver
|
||||
}
|
||||
|
||||
func (r *frankenResolver) ConfigurationPolicyByID(ctx context.Context, id graphql.ID) (_ gql.CodeIntelligenceConfigurationPolicyResolver, err error) {
|
||||
return r.getPoliciesServiceResolver().ConfigurationPolicyByID(ctx, id)
|
||||
}
|
||||
|
||||
func (r *frankenResolver) CodeIntelligenceConfigurationPolicies(ctx context.Context, args *gql.CodeIntelligenceConfigurationPoliciesArgs) (_ gql.CodeIntelligenceConfigurationPolicyConnectionResolver, err error) {
|
||||
return r.getPoliciesServiceResolver().CodeIntelligenceConfigurationPolicies(ctx, args)
|
||||
}
|
||||
|
||||
func (r *frankenResolver) CreateCodeIntelligenceConfigurationPolicy(ctx context.Context, args *gql.CreateCodeIntelligenceConfigurationPolicyArgs) (_ gql.CodeIntelligenceConfigurationPolicyResolver, err error) {
|
||||
return r.getPoliciesServiceResolver().CreateCodeIntelligenceConfigurationPolicy(ctx, args)
|
||||
}
|
||||
|
||||
func (r *frankenResolver) UpdateCodeIntelligenceConfigurationPolicy(ctx context.Context, args *gql.UpdateCodeIntelligenceConfigurationPolicyArgs) (_ *gql.EmptyResponse, err error) {
|
||||
return r.getPoliciesServiceResolver().UpdateCodeIntelligenceConfigurationPolicy(ctx, args)
|
||||
}
|
||||
|
||||
func (r *frankenResolver) DeleteCodeIntelligenceConfigurationPolicy(ctx context.Context, args *gql.DeleteCodeIntelligenceConfigurationPolicyArgs) (_ *gql.EmptyResponse, err error) {
|
||||
return r.getPoliciesServiceResolver().DeleteCodeIntelligenceConfigurationPolicy(ctx, args)
|
||||
}
|
||||
|
||||
func (r *frankenResolver) PreviewRepositoryFilter(ctx context.Context, args *gql.PreviewRepositoryFilterArgs) (_ gql.RepositoryFilterPreviewResolver, err error) {
|
||||
return r.getPoliciesServiceResolver().PreviewRepositoryFilter(ctx, args)
|
||||
}
|
||||
|
||||
func (r *frankenResolver) PreviewGitObjectFilter(ctx context.Context, id graphql.ID, args *gql.PreviewGitObjectFilterArgs) (_ []gql.GitObjectFilterPreviewResolver, err error) {
|
||||
return r.getPoliciesServiceResolver().PreviewGitObjectFilter(ctx, id, args)
|
||||
}
|
||||
@ -1,22 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"github.com/sourcegraph/go-lsp"
|
||||
|
||||
gql "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
)
|
||||
|
||||
type HoverResolver struct {
|
||||
text string
|
||||
lspRange lsp.Range
|
||||
}
|
||||
|
||||
func NewHoverResolver(text string, lspRange lsp.Range) gql.HoverResolver {
|
||||
return &HoverResolver{
|
||||
text: text,
|
||||
lspRange: lspRange,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *HoverResolver) Markdown() gql.Markdown { return gql.Markdown(r.text) }
|
||||
func (r *HoverResolver) Range() gql.RangeResolver { return gql.NewRangeResolver(r.lspRange) }
|
||||
@ -1,53 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/graph-gophers/graphql-go"
|
||||
"github.com/graph-gophers/graphql-go/relay"
|
||||
)
|
||||
|
||||
func marshalLSIFUploadGQLID(uploadID int64) graphql.ID {
|
||||
return relay.MarshalID("LSIFUpload", uploadID)
|
||||
}
|
||||
|
||||
func unmarshalLSIFUploadGQLID(id graphql.ID) (uploadID int64, err error) {
|
||||
// First, try to unmarshal the ID as a string and then convert it to an
|
||||
// integer. This is here to maintain backwards compatibility with the
|
||||
// src-cli lsif upload command, which constructs its own relay identifier
|
||||
// from a the string payload returned by the upload proxy.
|
||||
|
||||
var idString string
|
||||
err = relay.UnmarshalSpec(id, &idString)
|
||||
if err == nil {
|
||||
uploadID, err = strconv.ParseInt(idString, 10, 64)
|
||||
return
|
||||
}
|
||||
|
||||
// If it wasn't unmarshal-able as a string, it's a new-style int identifier
|
||||
err = relay.UnmarshalSpec(id, &uploadID)
|
||||
return uploadID, err
|
||||
}
|
||||
|
||||
func marshalLSIFIndexGQLID(indexID int64) graphql.ID {
|
||||
return relay.MarshalID("LSIFIndex", indexID)
|
||||
}
|
||||
|
||||
func unmarshalLSIFIndexGQLID(id graphql.ID) (indexID int64, err error) {
|
||||
err = relay.UnmarshalSpec(id, &indexID)
|
||||
return indexID, err
|
||||
}
|
||||
|
||||
func marshalConfigurationPolicyGQLID(configurationPolicyID int64) graphql.ID {
|
||||
return relay.MarshalID("CodeIntelligenceConfigurationPolicy", configurationPolicyID)
|
||||
}
|
||||
|
||||
func unmarshalConfigurationPolicyGQLID(id graphql.ID) (configurationPolicyID int64, err error) {
|
||||
err = relay.UnmarshalSpec(id, &configurationPolicyID)
|
||||
return configurationPolicyID, err
|
||||
}
|
||||
|
||||
func unmarshalRepositoryID(id graphql.ID) (repositoryID int64, err error) {
|
||||
err = relay.UnmarshalSpec(id, &repositoryID)
|
||||
return repositoryID, err
|
||||
}
|
||||
@ -1,42 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"testing"
|
||||
|
||||
"github.com/graph-gophers/graphql-go"
|
||||
)
|
||||
|
||||
func TestUploadID(t *testing.T) {
|
||||
expected := int64(42)
|
||||
value, err := unmarshalLSIFUploadGQLID(marshalLSIFUploadGQLID(expected))
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error marshalling id: %s", err)
|
||||
}
|
||||
if value != expected {
|
||||
t.Errorf("unexpected id. have=%d want=%d", expected, value)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalUploadIDString(t *testing.T) {
|
||||
expected := int64(42)
|
||||
id := graphql.ID(base64.StdEncoding.EncodeToString([]byte(`LSIFUpload:"42"`)))
|
||||
value, err := unmarshalLSIFUploadGQLID(id)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error marshalling id: %s", err)
|
||||
}
|
||||
if value != expected {
|
||||
t.Errorf("unexpected id. have=%d want=%d", expected, value)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIndexID(t *testing.T) {
|
||||
expected := int64(42)
|
||||
value, err := unmarshalLSIFIndexGQLID(marshalLSIFIndexGQLID(expected))
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error marshalling id: %s", err)
|
||||
}
|
||||
if value != expected {
|
||||
t.Errorf("unexpected id. have=%d want=%d", expected, value)
|
||||
}
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/grafana/regexp"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
policies "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/enterprise"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain"
|
||||
)
|
||||
|
||||
type GitserverClient interface {
|
||||
policies.GitserverClient
|
||||
shared.GitserverClient
|
||||
|
||||
ListFiles(ctx context.Context, repositoryID int, commit string, pattern *regexp.Regexp) ([]string, error)
|
||||
ListTags(ctx context.Context, repo api.RepoName, commitObjs ...string) ([]*gitdomain.Tag, error)
|
||||
}
|
||||
@ -1,112 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/graph-gophers/graphql-go"
|
||||
"github.com/opentracing/opentracing-go/log"
|
||||
|
||||
gql "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
"github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/codeintel/resolvers"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
store "github.com/sourcegraph/sourcegraph/internal/codeintel/stores/dbstore"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
)
|
||||
|
||||
type IndexResolver struct {
|
||||
db database.DB
|
||||
gitserver GitserverClient
|
||||
resolver resolvers.Resolver
|
||||
index store.Index
|
||||
prefetcher *Prefetcher
|
||||
locationResolver *CachedLocationResolver
|
||||
traceErrs *observation.ErrCollector
|
||||
}
|
||||
|
||||
func NewIndexResolver(db database.DB, gitserver GitserverClient, resolver resolvers.Resolver, index store.Index, prefetcher *Prefetcher, locationResolver *CachedLocationResolver, errTrace *observation.ErrCollector) gql.LSIFIndexResolver {
|
||||
if index.AssociatedUploadID != nil {
|
||||
// Request the next batch of upload fetches to contain the record's associated
|
||||
// upload id, if one exists it exists. This allows the prefetcher.GetUploadByID
|
||||
// invocation in the AssociatedUpload method to batch its work with sibling
|
||||
// resolvers, which share the same prefetcher instance.
|
||||
prefetcher.MarkUpload(*index.AssociatedUploadID)
|
||||
}
|
||||
|
||||
return &IndexResolver{
|
||||
db: db,
|
||||
gitserver: gitserver,
|
||||
resolver: resolver,
|
||||
index: index,
|
||||
prefetcher: prefetcher,
|
||||
locationResolver: locationResolver,
|
||||
traceErrs: errTrace,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *IndexResolver) ID() graphql.ID { return marshalLSIFIndexGQLID(int64(r.index.ID)) }
|
||||
func (r *IndexResolver) InputCommit() string { return r.index.Commit }
|
||||
func (r *IndexResolver) InputRoot() string { return r.index.Root }
|
||||
func (r *IndexResolver) InputIndexer() string { return r.index.Indexer }
|
||||
func (r *IndexResolver) QueuedAt() gql.DateTime { return gql.DateTime{Time: r.index.QueuedAt} }
|
||||
func (r *IndexResolver) Failure() *string { return r.index.FailureMessage }
|
||||
func (r *IndexResolver) StartedAt() *gql.DateTime { return gql.DateTimeOrNil(r.index.StartedAt) }
|
||||
func (r *IndexResolver) FinishedAt() *gql.DateTime { return gql.DateTimeOrNil(r.index.FinishedAt) }
|
||||
func (r *IndexResolver) Steps() gql.IndexStepsResolver {
|
||||
return &indexStepsResolver{db: r.db, index: r.index}
|
||||
}
|
||||
func (r *IndexResolver) PlaceInQueue() *int32 { return toInt32(r.index.Rank) }
|
||||
|
||||
func (r *IndexResolver) Tags(ctx context.Context) (tagsNames []string, err error) {
|
||||
tags, err := r.gitserver.ListTags(ctx, api.RepoName(r.index.RepositoryName), r.index.Commit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, tag := range tags {
|
||||
tagsNames = append(tagsNames, tag.Name)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (r *IndexResolver) State() string {
|
||||
state := strings.ToUpper(r.index.State)
|
||||
if state == "FAILED" {
|
||||
state = "ERRORED"
|
||||
}
|
||||
|
||||
return state
|
||||
}
|
||||
|
||||
func (r *IndexResolver) AssociatedUpload(ctx context.Context) (_ gql.LSIFUploadResolver, err error) {
|
||||
if r.index.AssociatedUploadID == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
defer r.traceErrs.Collect(&err,
|
||||
log.String("indexResolver.field", "associatedUpload"),
|
||||
log.Int("associatedUpload", *r.index.AssociatedUploadID),
|
||||
)
|
||||
|
||||
upload, exists, err := r.prefetcher.GetUploadByID(ctx, *r.index.AssociatedUploadID)
|
||||
if err != nil || !exists {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewUploadResolver(r.db, r.gitserver, r.resolver, upload, r.prefetcher, r.locationResolver, r.traceErrs), nil
|
||||
}
|
||||
|
||||
func (r *IndexResolver) ProjectRoot(ctx context.Context) (_ *gql.GitTreeEntryResolver, err error) {
|
||||
defer r.traceErrs.Collect(&err, log.String("indexResolver.field", "projectRoot"))
|
||||
|
||||
return r.locationResolver.Path(ctx, api.RepoID(r.index.RepositoryID), r.index.Commit, r.index.Root)
|
||||
}
|
||||
|
||||
func (r *IndexResolver) Indexer() gql.CodeIntelIndexerResolver {
|
||||
// drop the tag if it exists
|
||||
if idx, ok := imageToIndexer[strings.Split(r.index.Indexer, ":")[0]]; ok {
|
||||
return idx
|
||||
}
|
||||
|
||||
return &codeIntelIndexerResolver{name: r.index.Indexer}
|
||||
}
|
||||
@ -1,67 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/opentracing/opentracing-go/log"
|
||||
|
||||
gql "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil"
|
||||
"github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/codeintel/resolvers"
|
||||
autoindexinggraphql "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/transport/graphql"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
)
|
||||
|
||||
type IndexConnectionResolver struct {
|
||||
db database.DB
|
||||
gitserver GitserverClient
|
||||
resolver resolvers.Resolver
|
||||
indexesResolver *autoindexinggraphql.IndexesResolver
|
||||
prefetcher *Prefetcher
|
||||
locationResolver *CachedLocationResolver
|
||||
errTracer *observation.ErrCollector
|
||||
}
|
||||
|
||||
func NewIndexConnectionResolver(db database.DB, gitserver GitserverClient, resolver resolvers.Resolver, indexesResolver *autoindexinggraphql.IndexesResolver, prefetcher *Prefetcher, locationResolver *CachedLocationResolver, errTracer *observation.ErrCollector) gql.LSIFIndexConnectionResolver {
|
||||
return &IndexConnectionResolver{
|
||||
db: db,
|
||||
gitserver: gitserver,
|
||||
resolver: resolver,
|
||||
indexesResolver: indexesResolver,
|
||||
prefetcher: prefetcher,
|
||||
locationResolver: locationResolver,
|
||||
errTracer: errTracer,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *IndexConnectionResolver) Nodes(ctx context.Context) ([]gql.LSIFIndexResolver, error) {
|
||||
if err := r.indexesResolver.Resolve(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resolvers := make([]gql.LSIFIndexResolver, 0, len(r.indexesResolver.Indexes))
|
||||
for i := range r.indexesResolver.Indexes {
|
||||
index := convertSharedIndexToDBStoreIndex(r.indexesResolver.Indexes[i])
|
||||
resolvers = append(resolvers, NewIndexResolver(r.db, r.gitserver, r.resolver, index, r.prefetcher, r.locationResolver, r.errTracer))
|
||||
}
|
||||
return resolvers, nil
|
||||
}
|
||||
|
||||
func (r *IndexConnectionResolver) TotalCount(ctx context.Context) (_ *int32, err error) {
|
||||
defer r.errTracer.Collect(&err, log.String("indexConnectionResolver.field", "totalCount"))
|
||||
|
||||
if err := r.indexesResolver.Resolve(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return toInt32(&r.indexesResolver.TotalCount), nil
|
||||
}
|
||||
|
||||
func (r *IndexConnectionResolver) PageInfo(ctx context.Context) (_ *graphqlutil.PageInfo, err error) {
|
||||
defer r.errTracer.Collect(&err, log.String("indexConnectionResolver.field", "pageInfo"))
|
||||
|
||||
if err := r.indexesResolver.Resolve(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return graphqlutil.EncodeIntCursor(toInt32(r.indexesResolver.NextOffset)), nil
|
||||
}
|
||||
@ -1,86 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
gql "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
store "github.com/sourcegraph/sourcegraph/internal/codeintel/stores/dbstore"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/workerutil"
|
||||
)
|
||||
|
||||
// indexStepsResolver resolves the steps of an index record.
|
||||
//
|
||||
// Index jobs are broken into three parts:
|
||||
// - pre-index steps; all but the last docker step
|
||||
// - index step; the last docker step
|
||||
// - upload step; the only src-cli step
|
||||
//
|
||||
// The setup and teardown steps match the executor setup and teardown.
|
||||
type indexStepsResolver struct {
|
||||
db database.DB
|
||||
index store.Index
|
||||
}
|
||||
|
||||
var _ gql.IndexStepsResolver = &indexStepsResolver{}
|
||||
|
||||
func (r *indexStepsResolver) Setup() []gql.ExecutionLogEntryResolver {
|
||||
return r.executionLogEntryResolversWithPrefix("setup.")
|
||||
}
|
||||
|
||||
func (r *indexStepsResolver) PreIndex() []gql.PreIndexStepResolver {
|
||||
var resolvers []gql.PreIndexStepResolver
|
||||
for i, step := range r.index.DockerSteps {
|
||||
if entry, ok := r.findExecutionLogEntry(fmt.Sprintf("step.docker.%d", i)); ok {
|
||||
resolvers = append(resolvers, &preIndexStepResolver{db: r.db, step: step, entry: &entry})
|
||||
} else {
|
||||
resolvers = append(resolvers, &preIndexStepResolver{db: r.db, step: step, entry: nil})
|
||||
}
|
||||
}
|
||||
|
||||
return resolvers
|
||||
}
|
||||
|
||||
func (r *indexStepsResolver) Index() gql.IndexStepResolver {
|
||||
if entry, ok := r.findExecutionLogEntry(fmt.Sprintf("step.docker.%d", len(r.index.DockerSteps))); ok {
|
||||
return &indexStepResolver{db: r.db, index: r.index, entry: &entry}
|
||||
}
|
||||
|
||||
return &indexStepResolver{db: r.db, index: r.index, entry: nil}
|
||||
}
|
||||
|
||||
func (r *indexStepsResolver) Upload() gql.ExecutionLogEntryResolver {
|
||||
if entry, ok := r.findExecutionLogEntry("step.src.0"); ok {
|
||||
return gql.NewExecutionLogEntryResolver(r.db, entry)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *indexStepsResolver) Teardown() []gql.ExecutionLogEntryResolver {
|
||||
return r.executionLogEntryResolversWithPrefix("teardown.")
|
||||
}
|
||||
|
||||
func (r *indexStepsResolver) findExecutionLogEntry(key string) (workerutil.ExecutionLogEntry, bool) {
|
||||
for _, entry := range r.index.ExecutionLogs {
|
||||
if entry.Key == key {
|
||||
return entry, true
|
||||
}
|
||||
}
|
||||
|
||||
return workerutil.ExecutionLogEntry{}, false
|
||||
}
|
||||
|
||||
func (r *indexStepsResolver) executionLogEntryResolversWithPrefix(prefix string) []gql.ExecutionLogEntryResolver {
|
||||
var resolvers []gql.ExecutionLogEntryResolver
|
||||
for _, entry := range r.index.ExecutionLogs {
|
||||
if !strings.HasPrefix(entry.Key, prefix) {
|
||||
continue
|
||||
}
|
||||
r := gql.NewExecutionLogEntryResolver(r.db, entry)
|
||||
resolvers = append(resolvers, r)
|
||||
}
|
||||
|
||||
return resolvers
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
gql "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
store "github.com/sourcegraph/sourcegraph/internal/codeintel/stores/dbstore"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/workerutil"
|
||||
)
|
||||
|
||||
type indexStepResolver struct {
|
||||
db database.DB
|
||||
index store.Index
|
||||
entry *workerutil.ExecutionLogEntry
|
||||
}
|
||||
|
||||
var _ gql.IndexStepResolver = &indexStepResolver{}
|
||||
|
||||
func (r *indexStepResolver) IndexerArgs() []string { return r.index.IndexerArgs }
|
||||
func (r *indexStepResolver) Outfile() *string { return strPtr(r.index.Outfile) }
|
||||
|
||||
func (r *indexStepResolver) LogEntry() gql.ExecutionLogEntryResolver {
|
||||
if r.entry != nil {
|
||||
return gql.NewExecutionLogEntryResolver(r.db, *r.entry)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
gql "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
store "github.com/sourcegraph/sourcegraph/internal/codeintel/stores/dbstore"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/workerutil"
|
||||
)
|
||||
|
||||
type preIndexStepResolver struct {
|
||||
db database.DB
|
||||
step store.DockerStep
|
||||
entry *workerutil.ExecutionLogEntry
|
||||
}
|
||||
|
||||
var _ gql.PreIndexStepResolver = &preIndexStepResolver{}
|
||||
|
||||
func (r *preIndexStepResolver) Root() string { return r.step.Root }
|
||||
func (r *preIndexStepResolver) Image() string { return r.step.Image }
|
||||
func (r *preIndexStepResolver) Commands() []string { return r.step.Commands }
|
||||
|
||||
func (r *preIndexStepResolver) LogEntry() gql.ExecutionLogEntryResolver {
|
||||
if r.entry != nil {
|
||||
return gql.NewExecutionLogEntryResolver(r.db, *r.entry)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -1,30 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
gql "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil"
|
||||
)
|
||||
|
||||
type LocationConnectionResolver struct {
|
||||
locations []AdjustedLocation
|
||||
cursor *string
|
||||
locationResolver *CachedLocationResolver
|
||||
}
|
||||
|
||||
func NewLocationConnectionResolver(locations []AdjustedLocation, cursor *string, locationResolver *CachedLocationResolver) gql.LocationConnectionResolver {
|
||||
return &LocationConnectionResolver{
|
||||
locations: locations,
|
||||
cursor: cursor,
|
||||
locationResolver: locationResolver,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *LocationConnectionResolver) Nodes(ctx context.Context) ([]gql.LocationResolver, error) {
|
||||
return resolveLocations(ctx, r.locationResolver, r.locations)
|
||||
}
|
||||
|
||||
func (r *LocationConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) {
|
||||
return graphqlutil.EncodeCursor(r.cursor), nil
|
||||
}
|
||||
@ -1,77 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
)
|
||||
|
||||
type operations struct {
|
||||
commitGraph *observation.Operation
|
||||
configurationPolicies *observation.Operation
|
||||
configurationPolicyByID *observation.Operation
|
||||
createConfigurationPolicy *observation.Operation
|
||||
deleteConfigurationPolicy *observation.Operation
|
||||
deleteLsifIndexes *observation.Operation
|
||||
deleteLsifUpload *observation.Operation
|
||||
gitBlobCodeIntelInfo *observation.Operation
|
||||
gitBlobLsifData *observation.Operation
|
||||
gitTreeCodeIntelInfo *observation.Operation
|
||||
indexConfiguration *observation.Operation
|
||||
lsifIndexByID *observation.Operation
|
||||
lsifIndexes *observation.Operation
|
||||
lsifIndexesByRepo *observation.Operation
|
||||
lsifUploadByID *observation.Operation
|
||||
lsifUploads *observation.Operation
|
||||
lsifUploadsByRepo *observation.Operation
|
||||
previewGitObjectFilter *observation.Operation
|
||||
previewRepoFilter *observation.Operation
|
||||
queueAutoIndexJobsForRepo *observation.Operation
|
||||
repositorySummary *observation.Operation
|
||||
requestedLanguageSupport *observation.Operation
|
||||
requestLanguageSupport *observation.Operation
|
||||
updateConfigurationPolicy *observation.Operation
|
||||
updateIndexConfiguration *observation.Operation
|
||||
}
|
||||
|
||||
func newOperations(observationContext *observation.Context) *operations {
|
||||
op := func(name string) *observation.Operation {
|
||||
return observationContext.Operation(observation.Op{
|
||||
Name: fmt.Sprintf("codeintel.resolver.%s", name),
|
||||
ErrorFilter: func(err error) observation.ErrorFilterBehaviour {
|
||||
if err == ErrIllegalBounds || err == ErrIllegalLimit {
|
||||
return observation.EmitForNone
|
||||
}
|
||||
return observation.EmitForLogs
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return &operations{
|
||||
commitGraph: op("CommitGraph"),
|
||||
configurationPolicies: op("ConfigurationPolicies"),
|
||||
configurationPolicyByID: op("ConfigurationPolicyByID"),
|
||||
createConfigurationPolicy: op("CreateConfigurationPolicy"),
|
||||
deleteConfigurationPolicy: op("DeleteConfigurationPolicy"),
|
||||
deleteLsifIndexes: op("DeleteLSIFIndexes"),
|
||||
deleteLsifUpload: op("DeleteLSIFUpload"),
|
||||
gitBlobCodeIntelInfo: op("GitBlobCodeIntelInfo"),
|
||||
gitBlobLsifData: op("GitBlobLSIFData"),
|
||||
gitTreeCodeIntelInfo: op("GitTreeCodeIntelInfo"),
|
||||
indexConfiguration: op("IndexConfiguration"),
|
||||
lsifIndexByID: op("LSIFIndexByID"),
|
||||
lsifIndexes: op("LSIFIndexes"),
|
||||
lsifIndexesByRepo: op("LSIFIndexesByRepo"),
|
||||
lsifUploadByID: op("LSIFUploadByID"),
|
||||
lsifUploads: op("LSIFUploads"),
|
||||
lsifUploadsByRepo: op("LSIFUploadsByRepo"),
|
||||
previewGitObjectFilter: op("PreviewGitObjectFilter"),
|
||||
previewRepoFilter: op("PreviewRepoFilter"),
|
||||
queueAutoIndexJobsForRepo: op("QueueAutoIndexJobsForRepo"),
|
||||
repositorySummary: op("RepositorySummary"),
|
||||
requestedLanguageSupport: op("RequestedLanguageSupport"),
|
||||
requestLanguageSupport: op("RequestLanguageSupport"),
|
||||
updateConfigurationPolicy: op("UpdateConfigurationPolicy"),
|
||||
updateIndexConfiguration: op("UpdateIndexConfiguration"),
|
||||
}
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
gql "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
)
|
||||
|
||||
type CodeIntelligenceRangeResolver struct {
|
||||
r AdjustedCodeIntelligenceRange
|
||||
locationResolver *CachedLocationResolver
|
||||
}
|
||||
|
||||
func (r *CodeIntelligenceRangeResolver) Range(ctx context.Context) (gql.RangeResolver, error) {
|
||||
return gql.NewRangeResolver(convertRange(r.r.Range)), nil
|
||||
}
|
||||
|
||||
func (r *CodeIntelligenceRangeResolver) Definitions(ctx context.Context) (gql.LocationConnectionResolver, error) {
|
||||
return NewLocationConnectionResolver(r.r.Definitions, nil, r.locationResolver), nil
|
||||
}
|
||||
|
||||
func (r *CodeIntelligenceRangeResolver) References(ctx context.Context) (gql.LocationConnectionResolver, error) {
|
||||
return NewLocationConnectionResolver(r.r.References, nil, r.locationResolver), nil
|
||||
}
|
||||
|
||||
func (r *CodeIntelligenceRangeResolver) Implementations(ctx context.Context) (gql.LocationConnectionResolver, error) {
|
||||
return NewLocationConnectionResolver(r.r.Implementations, nil, r.locationResolver), nil
|
||||
}
|
||||
|
||||
func (r *CodeIntelligenceRangeResolver) Hover(ctx context.Context) (gql.HoverResolver, error) {
|
||||
return NewHoverResolver(r.r.HoverText, convertRange(r.r.Range)), nil
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
gql "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
)
|
||||
|
||||
type CodeIntelligenceRangeConnectionResolver struct {
|
||||
ranges []AdjustedCodeIntelligenceRange
|
||||
locationResolver *CachedLocationResolver
|
||||
}
|
||||
|
||||
func (r *CodeIntelligenceRangeConnectionResolver) Nodes(ctx context.Context) ([]gql.CodeIntelligenceRangeResolver, error) {
|
||||
var resolvers []gql.CodeIntelligenceRangeResolver
|
||||
for _, rn := range r.ranges {
|
||||
resolvers = append(resolvers, &CodeIntelligenceRangeResolver{
|
||||
r: rn,
|
||||
locationResolver: r.locationResolver,
|
||||
})
|
||||
}
|
||||
|
||||
return resolvers, nil
|
||||
}
|
||||
@ -1,41 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
gql "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil"
|
||||
)
|
||||
|
||||
type repositoryFilterPreviewResolver struct {
|
||||
repositoryResolvers []*gql.RepositoryResolver
|
||||
totalCount int
|
||||
offset int
|
||||
totalMatches int
|
||||
limit *int
|
||||
}
|
||||
|
||||
var _ gql.RepositoryFilterPreviewResolver = &repositoryFilterPreviewResolver{}
|
||||
|
||||
func (r *repositoryFilterPreviewResolver) Nodes() []*gql.RepositoryResolver {
|
||||
return r.repositoryResolvers
|
||||
}
|
||||
|
||||
func (r *repositoryFilterPreviewResolver) TotalCount() int32 {
|
||||
return int32(r.totalCount)
|
||||
}
|
||||
|
||||
func (r *repositoryFilterPreviewResolver) TotalMatches() int32 {
|
||||
return int32(r.totalMatches)
|
||||
}
|
||||
|
||||
func (r *repositoryFilterPreviewResolver) Limit() *int32 {
|
||||
if r.limit == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
v := int32(*r.limit)
|
||||
return &v
|
||||
}
|
||||
|
||||
func (r *repositoryFilterPreviewResolver) PageInfo() *graphqlutil.PageInfo {
|
||||
return graphqlutil.EncodeIntCursor(toInt32(graphqlutil.NextOffset(r.offset, len(r.repositoryResolvers), r.totalCount)))
|
||||
}
|
||||
@ -2,67 +2,37 @@ package graphql
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/regexp"
|
||||
"github.com/graph-gophers/graphql-go"
|
||||
"github.com/opentracing/opentracing-go/log"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/backend"
|
||||
gql "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil"
|
||||
"github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/codeintel/resolvers"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
autoindexingShared "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/policies/shared"
|
||||
uploadsShared "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/conf"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
autoindexinggraphql "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/transport/graphql"
|
||||
codenavgraphql "github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/transport/graphql"
|
||||
policiesgraphql "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/transport/graphql"
|
||||
sharedresolvers "github.com/sourcegraph/sourcegraph/internal/codeintel/sharedresolvers"
|
||||
uploadsgraphql "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/transport/graphql"
|
||||
executor "github.com/sourcegraph/sourcegraph/internal/services/executors/transport/graphql"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultUploadPageSize = 50
|
||||
DefaultIndexPageSize = 50
|
||||
DefaultConfigurationPolicyPageSize = 50
|
||||
DefaultRepositoryFilterPreviewPageSize = 50
|
||||
DefaultRetentionPolicyMatchesPageSize = 50
|
||||
)
|
||||
|
||||
var errAutoIndexingNotEnabled = errors.New("precise code intelligence auto-indexing is not enabled")
|
||||
|
||||
// Resolver is the main interface to code intel-related operations exposed to the GraphQL API. This
|
||||
// resolver concerns itself with GraphQL/API-specific behaviors (auth, validation, marshaling, etc.).
|
||||
// All code intel-specific behavior is delegated to the underlying resolver instance, which is defined
|
||||
// in the parent package.
|
||||
type Resolver struct {
|
||||
db database.DB
|
||||
gitserver GitserverClient
|
||||
resolver resolvers.Resolver
|
||||
locationResolver *CachedLocationResolver
|
||||
observationContext *operations
|
||||
resolver resolvers.Resolver
|
||||
}
|
||||
|
||||
// NewResolver creates a new Resolver with the given resolver that defines all code intel-specific behavior.
|
||||
func NewResolver(db database.DB, gitserver GitserverClient, resolver resolvers.Resolver, observationContext *observation.Context) gql.CodeIntelResolver {
|
||||
func NewResolver(resolver resolvers.Resolver) gql.CodeIntelResolver {
|
||||
baseResolver := &Resolver{
|
||||
db: db,
|
||||
gitserver: gitserver,
|
||||
resolver: resolver,
|
||||
locationResolver: NewCachedLocationResolver(db),
|
||||
observationContext: newOperations(observationContext),
|
||||
resolver: resolver,
|
||||
}
|
||||
|
||||
return &frankenResolver{
|
||||
Resolver: baseResolver,
|
||||
}
|
||||
return baseResolver
|
||||
}
|
||||
|
||||
func (r *frankenResolver) NodeResolvers() map[string]gql.NodeByIDFunc {
|
||||
func (r *Resolver) NodeResolvers() map[string]gql.NodeByIDFunc {
|
||||
return map[string]gql.NodeByIDFunc{
|
||||
"LSIFUpload": func(ctx context.Context, id graphql.ID) (gql.Node, error) {
|
||||
return r.LSIFUploadByID(ctx, id)
|
||||
@ -80,794 +50,120 @@ func (r *Resolver) ExecutorResolver() executor.Resolver {
|
||||
return r.resolver.ExecutorResolver()
|
||||
}
|
||||
|
||||
func (r *Resolver) CodeNavResolver() resolvers.CodeNavResolver {
|
||||
return r.resolver.CodeNavResolver()
|
||||
}
|
||||
|
||||
func (r *Resolver) PoliciesResolver() resolvers.PoliciesResolver {
|
||||
return r.resolver.PoliciesResolver()
|
||||
}
|
||||
|
||||
func (r *Resolver) AutoIndexingResolver() resolvers.AutoIndexingResolver {
|
||||
return r.resolver.AutoIndexingResolver()
|
||||
}
|
||||
|
||||
// 🚨 SECURITY: dbstore layer handles authz for GetUploadByID
|
||||
func (r *Resolver) LSIFUploadByID(ctx context.Context, id graphql.ID) (_ gql.LSIFUploadResolver, err error) {
|
||||
ctx, traceErrs, endObservation := r.observationContext.lsifUploadByID.WithErrors(ctx, &err, observation.Args{LogFields: []log.Field{
|
||||
log.String("uploadID", string(id)),
|
||||
}})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
uploadID, err := unmarshalLSIFUploadGQLID(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Create a new prefetcher here as we only want to cache upload and index records in
|
||||
// the same graphQL request, not across different request.
|
||||
prefetcher := NewPrefetcher(r.resolver)
|
||||
|
||||
upload, exists, err := prefetcher.GetUploadByID(ctx, int(uploadID))
|
||||
if err != nil || !exists {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewUploadResolver(r.db, r.gitserver, r.resolver, upload, prefetcher, r.locationResolver, traceErrs), nil
|
||||
func (r *Resolver) LSIFUploadByID(ctx context.Context, id graphql.ID) (_ sharedresolvers.LSIFUploadResolver, err error) {
|
||||
return r.resolver.UploadRootResolver().LSIFUploadByID(ctx, id)
|
||||
}
|
||||
|
||||
// 🚨 SECURITY: dbstore layer handles authz for GetUploads
|
||||
func (r *Resolver) LSIFUploads(ctx context.Context, args *gql.LSIFUploadsQueryArgs) (_ gql.LSIFUploadConnectionResolver, err error) {
|
||||
// ctx, _, endObservation := r.observationContext.lsifUploads.With(ctx, &err, observation.Args{})
|
||||
// endObservation.EndOnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
// Delegate behavior to LSIFUploadsByRepo with no specified repository identifier
|
||||
return r.LSIFUploadsByRepo(ctx, &gql.LSIFRepositoryUploadsQueryArgs{LSIFUploadsQueryArgs: args})
|
||||
func (r *Resolver) LSIFUploads(ctx context.Context, args *uploadsgraphql.LSIFUploadsQueryArgs) (_ sharedresolvers.LSIFUploadConnectionResolver, err error) {
|
||||
return r.resolver.UploadRootResolver().LSIFUploads(ctx, args)
|
||||
}
|
||||
|
||||
// 🚨 SECURITY: dbstore layer handles authz for GetUploads
|
||||
func (r *Resolver) LSIFUploadsByRepo(ctx context.Context, args *gql.LSIFRepositoryUploadsQueryArgs) (_ gql.LSIFUploadConnectionResolver, err error) {
|
||||
ctx, traceErrs, endObservation := r.observationContext.lsifUploadsByRepo.WithErrors(ctx, &err, observation.Args{LogFields: []log.Field{
|
||||
log.String("repoID", string(args.RepositoryID)),
|
||||
}})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
opts, err := makeGetUploadsOptions(args)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Create a new prefetcher here as we only want to cache upload and index records in
|
||||
// the same graphQL request, not across different request.
|
||||
prefetcher := NewPrefetcher(r.resolver)
|
||||
uploadConnectionResolver := r.resolver.UploadsResolver().UploadsConnectionResolverFromFactory(opts)
|
||||
|
||||
return NewUploadConnectionResolver(r.db, r.gitserver, r.resolver, uploadConnectionResolver, prefetcher, r.locationResolver, traceErrs), nil
|
||||
func (r *Resolver) LSIFUploadsByRepo(ctx context.Context, args *uploadsgraphql.LSIFRepositoryUploadsQueryArgs) (_ sharedresolvers.LSIFUploadConnectionResolver, err error) {
|
||||
return r.resolver.UploadRootResolver().LSIFUploadsByRepo(ctx, args)
|
||||
}
|
||||
|
||||
// 🚨 SECURITY: Only site admins may modify code intelligence upload data
|
||||
func (r *Resolver) DeleteLSIFUpload(ctx context.Context, args *struct{ ID graphql.ID }) (_ *gql.EmptyResponse, err error) {
|
||||
ctx, _, endObservation := r.observationContext.deleteLsifUpload.With(ctx, &err, observation.Args{LogFields: []log.Field{
|
||||
log.String("uploadID", string(args.ID)),
|
||||
}})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
if err := backend.CheckCurrentUserIsSiteAdmin(ctx, r.db); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
uploadID, err := unmarshalLSIFUploadGQLID(args.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := r.resolver.UploadsResolver().DeleteUploadByID(ctx, int(uploadID)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &gql.EmptyResponse{}, nil
|
||||
func (r *Resolver) DeleteLSIFUpload(ctx context.Context, args *struct{ ID graphql.ID }) (_ *sharedresolvers.EmptyResponse, err error) {
|
||||
return r.resolver.UploadRootResolver().DeleteLSIFUpload(ctx, args)
|
||||
}
|
||||
|
||||
var autoIndexingEnabled = conf.CodeIntelAutoIndexingEnabled
|
||||
|
||||
// 🚨 SECURITY: dbstore layer handles authz for GetIndexByID
|
||||
func (r *Resolver) LSIFIndexByID(ctx context.Context, id graphql.ID) (_ gql.LSIFIndexResolver, err error) {
|
||||
if !autoIndexingEnabled() {
|
||||
return nil, errAutoIndexingNotEnabled
|
||||
}
|
||||
|
||||
ctx, traceErrs, endObservation := r.observationContext.lsifIndexByID.WithErrors(ctx, &err, observation.Args{LogFields: []log.Field{
|
||||
log.String("indexID", string(id)),
|
||||
}})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
indexID, err := unmarshalLSIFIndexGQLID(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Create a new prefetcher here as we only want to cache upload and index records in
|
||||
// the same graphQL request, not across different request.
|
||||
prefetcher := NewPrefetcher(r.resolver)
|
||||
|
||||
index, exists, err := prefetcher.GetIndexByID(ctx, int(indexID))
|
||||
if err != nil || !exists {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewIndexResolver(r.db, r.gitserver, r.resolver, index, prefetcher, r.locationResolver, traceErrs), nil
|
||||
func (r *Resolver) LSIFIndexByID(ctx context.Context, id graphql.ID) (_ sharedresolvers.LSIFIndexResolver, err error) {
|
||||
return r.resolver.AutoIndexingRootResolver().LSIFIndexByID(ctx, id)
|
||||
}
|
||||
|
||||
// 🚨 SECURITY: dbstore layer handles authz for GetIndexes
|
||||
func (r *Resolver) LSIFIndexes(ctx context.Context, args *gql.LSIFIndexesQueryArgs) (_ gql.LSIFIndexConnectionResolver, err error) {
|
||||
if !autoIndexingEnabled() {
|
||||
return nil, errAutoIndexingNotEnabled
|
||||
}
|
||||
|
||||
ctx, _, endObservation := r.observationContext.lsifIndexes.With(ctx, &err, observation.Args{})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
// Delegate behavior to LSIFIndexesByRepo with no specified repository identifier
|
||||
return r.LSIFIndexesByRepo(ctx, &gql.LSIFRepositoryIndexesQueryArgs{LSIFIndexesQueryArgs: args})
|
||||
func (r *Resolver) LSIFIndexes(ctx context.Context, args *autoindexinggraphql.LSIFIndexesQueryArgs) (_ sharedresolvers.LSIFIndexConnectionResolver, err error) {
|
||||
return r.resolver.AutoIndexingRootResolver().LSIFIndexes(ctx, args)
|
||||
}
|
||||
|
||||
// 🚨 SECURITY: dbstore layer handles authz for GetIndexes
|
||||
func (r *Resolver) LSIFIndexesByRepo(ctx context.Context, args *gql.LSIFRepositoryIndexesQueryArgs) (_ gql.LSIFIndexConnectionResolver, err error) {
|
||||
if !autoIndexingEnabled() {
|
||||
return nil, errAutoIndexingNotEnabled
|
||||
}
|
||||
|
||||
ctx, traceErrs, endObservation := r.observationContext.lsifIndexesByRepo.WithErrors(ctx, &err, observation.Args{LogFields: []log.Field{
|
||||
log.String("repoID", string(args.RepositoryID)),
|
||||
}})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
opts, err := makeGetIndexesOptions(args)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Create a new prefetcher here as we only want to cache upload and index records in
|
||||
// the same graphQL request, not across different request.
|
||||
prefetcher := NewPrefetcher(r.resolver)
|
||||
|
||||
// Create a new indexConnectionResolver here as we only want to index records in
|
||||
// the same graphQL request, not across different request.
|
||||
indexConnectionResolver := r.resolver.AutoIndexingResolver().IndexConnectionResolverFromFactory(opts)
|
||||
|
||||
return NewIndexConnectionResolver(r.db, r.gitserver, r.resolver, indexConnectionResolver, prefetcher, r.locationResolver, traceErrs), nil
|
||||
func (r *Resolver) LSIFIndexesByRepo(ctx context.Context, args *autoindexinggraphql.LSIFRepositoryIndexesQueryArgs) (_ sharedresolvers.LSIFIndexConnectionResolver, err error) {
|
||||
return r.resolver.AutoIndexingRootResolver().LSIFIndexesByRepo(ctx, args)
|
||||
}
|
||||
|
||||
// 🚨 SECURITY: Only site admins may modify code intelligence index data
|
||||
func (r *Resolver) DeleteLSIFIndex(ctx context.Context, args *struct{ ID graphql.ID }) (_ *gql.EmptyResponse, err error) {
|
||||
ctx, _, endObservation := r.observationContext.deleteLsifIndexes.With(ctx, &err, observation.Args{LogFields: []log.Field{
|
||||
log.String("indexID", string(args.ID)),
|
||||
}})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
if err := backend.CheckCurrentUserIsSiteAdmin(ctx, r.db); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !autoIndexingEnabled() {
|
||||
return nil, errAutoIndexingNotEnabled
|
||||
}
|
||||
|
||||
indexID, err := unmarshalLSIFIndexGQLID(args.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
autoIndexingResolver := r.resolver.AutoIndexingResolver()
|
||||
if err := autoIndexingResolver.DeleteIndexByID(ctx, int(indexID)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &gql.EmptyResponse{}, nil
|
||||
func (r *Resolver) DeleteLSIFIndex(ctx context.Context, args *struct{ ID graphql.ID }) (_ *sharedresolvers.EmptyResponse, err error) {
|
||||
return r.resolver.AutoIndexingRootResolver().DeleteLSIFIndex(ctx, args)
|
||||
}
|
||||
|
||||
// 🚨 SECURITY: Only entrypoint is within the repository resolver so the user is already authenticated
|
||||
func (r *Resolver) CommitGraph(ctx context.Context, id graphql.ID) (_ gql.CodeIntelligenceCommitGraphResolver, err error) {
|
||||
ctx, _, endObservation := r.observationContext.commitGraph.With(ctx, &err, observation.Args{LogFields: []log.Field{
|
||||
log.String("repoID", string(id)),
|
||||
}})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
repositoryID, err := gql.UnmarshalRepositoryID(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
commitGraphResolver := r.resolver.UploadsResolver().CommitGraphResolverFromFactory(ctx, int(repositoryID))
|
||||
|
||||
return commitGraphResolver, nil
|
||||
func (r *Resolver) CommitGraph(ctx context.Context, id graphql.ID) (_ uploadsgraphql.CodeIntelligenceCommitGraphResolver, err error) {
|
||||
return r.resolver.UploadRootResolver().CommitGraph(ctx, id)
|
||||
}
|
||||
|
||||
// 🚨 SECURITY: Only site admins may queue auto-index jobs
|
||||
func (r *Resolver) QueueAutoIndexJobsForRepo(ctx context.Context, args *gql.QueueAutoIndexJobsForRepoArgs) (_ []gql.LSIFIndexResolver, err error) {
|
||||
ctx, traceErrs, endObservation := r.observationContext.queueAutoIndexJobsForRepo.WithErrors(ctx, &err, observation.Args{LogFields: []log.Field{
|
||||
log.String("repoID", string(args.Repository)),
|
||||
}})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
func (r *Resolver) QueueAutoIndexJobsForRepo(ctx context.Context, args *autoindexinggraphql.QueueAutoIndexJobsForRepoArgs) (_ []sharedresolvers.LSIFIndexResolver, err error) {
|
||||
return r.resolver.AutoIndexingRootResolver().QueueAutoIndexJobsForRepo(ctx, args)
|
||||
}
|
||||
|
||||
if err := backend.CheckCurrentUserIsSiteAdmin(ctx, r.db); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !autoIndexingEnabled() {
|
||||
return nil, errAutoIndexingNotEnabled
|
||||
}
|
||||
func (r *Resolver) RequestLanguageSupport(ctx context.Context, args *autoindexinggraphql.RequestLanguageSupportArgs) (_ *sharedresolvers.EmptyResponse, err error) {
|
||||
return r.resolver.AutoIndexingRootResolver().RequestLanguageSupport(ctx, args)
|
||||
}
|
||||
|
||||
repositoryID, err := gql.UnmarshalRepositoryID(args.Repository)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rev := "HEAD"
|
||||
if args.Rev != nil {
|
||||
rev = *args.Rev
|
||||
}
|
||||
|
||||
configuration := ""
|
||||
if args.Configuration != nil {
|
||||
configuration = *args.Configuration
|
||||
}
|
||||
|
||||
autoindexingResolver := r.resolver.AutoIndexingResolver()
|
||||
indexes, err := autoindexingResolver.QueueAutoIndexJobsForRepo(ctx, int(repositoryID), rev, configuration)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Create a new prefetcher here as we only want to cache upload and index records in
|
||||
// the same graphQL request, not across different request.
|
||||
prefetcher := NewPrefetcher(r.resolver)
|
||||
|
||||
resolvers := make([]gql.LSIFIndexResolver, 0, len(indexes))
|
||||
for i := range indexes {
|
||||
index := convertSharedIndexToDBStoreIndex(indexes[i])
|
||||
resolvers = append(resolvers, NewIndexResolver(r.db, r.gitserver, r.resolver, index, prefetcher, r.locationResolver, traceErrs))
|
||||
}
|
||||
return resolvers, nil
|
||||
func (r *Resolver) RequestedLanguageSupport(ctx context.Context) (_ []string, err error) {
|
||||
return r.resolver.AutoIndexingRootResolver().RequestedLanguageSupport(ctx)
|
||||
}
|
||||
|
||||
// 🚨 SECURITY: dbstore layer handles authz for query resolution
|
||||
func (r *Resolver) GitBlobLSIFData(ctx context.Context, args *gql.GitBlobLSIFDataArgs) (_ gql.GitBlobLSIFDataResolver, err error) {
|
||||
ctx, errTracer, endObservation := r.observationContext.gitBlobLsifData.WithErrors(ctx, &err, observation.Args{})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
codenav := r.resolver.CodeNavResolver()
|
||||
gitBlobResolver, err := codenav.GitBlobLSIFDataResolverFactory(ctx, args.Repo, string(args.Commit), args.Path, args.ToolName, args.ExactPath)
|
||||
if err != nil || gitBlobResolver == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewQueryResolver(r.gitserver, gitBlobResolver, r.resolver, r.locationResolver, errTracer), nil
|
||||
func (r *Resolver) GitBlobLSIFData(ctx context.Context, args *codenavgraphql.GitBlobLSIFDataArgs) (_ codenavgraphql.GitBlobLSIFDataResolver, err error) {
|
||||
return r.resolver.CodeNavResolver().GitBlobLSIFData(ctx, args)
|
||||
}
|
||||
|
||||
func (r *Resolver) GitBlobCodeIntelInfo(ctx context.Context, args *gql.GitTreeEntryCodeIntelInfoArgs) (_ gql.GitBlobCodeIntelSupportResolver, err error) {
|
||||
ctx, errTracer, endObservation := r.observationContext.gitBlobCodeIntelInfo.WithErrors(ctx, &err, observation.Args{})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
return NewCodeIntelSupportResolver(r.resolver, args.Repo.Name, args.Path, errTracer), nil
|
||||
func (r *Resolver) GitBlobCodeIntelInfo(ctx context.Context, args *autoindexinggraphql.GitTreeEntryCodeIntelInfoArgs) (_ autoindexinggraphql.GitBlobCodeIntelSupportResolver, err error) {
|
||||
return r.resolver.AutoIndexingRootResolver().GitBlobCodeIntelInfo(ctx, args)
|
||||
}
|
||||
|
||||
func (r *Resolver) GitTreeCodeIntelInfo(ctx context.Context, args *gql.GitTreeEntryCodeIntelInfoArgs) (resolver gql.GitTreeCodeIntelSupportResolver, err error) {
|
||||
ctx, errTracer, endObservation := r.observationContext.gitBlobCodeIntelInfo.WithErrors(ctx, &err, observation.Args{LogFields: []log.Field{
|
||||
log.Int("repoID", int(args.Repo.ID)),
|
||||
log.String("path", args.Path),
|
||||
log.String("commit", args.Commit),
|
||||
}})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
filesRegex, err := regexp.Compile("^" + regexp.QuoteMeta(args.Path) + "[^.]{1}[^/]*$")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "path '%s' caused invalid regex", args.Path)
|
||||
}
|
||||
|
||||
files, err := r.gitserver.ListFiles(ctx, int(args.Repo.ID), args.Commit, filesRegex)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "gitserver.ListFiles: error listing files at %s for repo %d", args.Path, args.Repo.ID)
|
||||
}
|
||||
|
||||
return NewCodeIntelTreeInfoResolver(r.resolver, args.Repo, args.Commit, args.Path, files, errTracer), nil
|
||||
func (r *Resolver) GitTreeCodeIntelInfo(ctx context.Context, args *autoindexinggraphql.GitTreeEntryCodeIntelInfoArgs) (resolver autoindexinggraphql.GitTreeCodeIntelSupportResolver, err error) {
|
||||
return r.resolver.AutoIndexingRootResolver().GitTreeCodeIntelInfo(ctx, args)
|
||||
}
|
||||
|
||||
// 🚨 SECURITY: dbstore layer handles authz for GetConfigurationPolicyByID
|
||||
func (r *Resolver) ConfigurationPolicyByID(ctx context.Context, id graphql.ID) (_ gql.CodeIntelligenceConfigurationPolicyResolver, err error) {
|
||||
ctx, traceErrs, endObservation := r.observationContext.configurationPolicyByID.WithErrors(ctx, &err, observation.Args{LogFields: []log.Field{
|
||||
log.String("configPolicyID", string(id)),
|
||||
}})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
configurationPolicyID, err := unmarshalConfigurationPolicyGQLID(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
policyResolver, err := r.resolver.PoliciesResolver().PolicyResolverFactory(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
configurationPolicy, exists, err := policyResolver.GetConfigurationPolicyByID(ctx, int(configurationPolicyID))
|
||||
if err != nil || !exists {
|
||||
return nil, err
|
||||
}
|
||||
cp := sharedConfigurationPoliciesToStoreConfigurationPolicies(configurationPolicy)
|
||||
|
||||
return NewConfigurationPolicyResolver(r.db, cp, traceErrs), nil
|
||||
func (r *Resolver) ConfigurationPolicyByID(ctx context.Context, id graphql.ID) (_ policiesgraphql.CodeIntelligenceConfigurationPolicyResolver, err error) {
|
||||
return r.resolver.PoliciesRootResolver().ConfigurationPolicyByID(ctx, id)
|
||||
}
|
||||
|
||||
// 🚨 SECURITY: dbstore layer handles authz for GetConfigurationPolicies
|
||||
func (r *Resolver) CodeIntelligenceConfigurationPolicies(ctx context.Context, args *gql.CodeIntelligenceConfigurationPoliciesArgs) (_ gql.CodeIntelligenceConfigurationPolicyConnectionResolver, err error) {
|
||||
fields := []log.Field{}
|
||||
if args.Repository != nil {
|
||||
fields = append(fields, log.String("repoID", string(*args.Repository)))
|
||||
}
|
||||
ctx, traceErrs, endObservation := r.observationContext.configurationPolicies.WithErrors(ctx, &err, observation.Args{LogFields: fields})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
offset, err := graphqlutil.DecodeIntCursor(args.After)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pageSize := DefaultConfigurationPolicyPageSize
|
||||
if args.First != nil {
|
||||
pageSize = int(*args.First)
|
||||
}
|
||||
|
||||
opts := shared.GetConfigurationPoliciesOptions{
|
||||
Limit: pageSize,
|
||||
Offset: offset,
|
||||
}
|
||||
if args.Repository != nil {
|
||||
id64, err := unmarshalRepositoryID(*args.Repository)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
opts.RepositoryID = int(id64)
|
||||
}
|
||||
if args.Query != nil {
|
||||
opts.Term = *args.Query
|
||||
}
|
||||
if args.ForDataRetention != nil {
|
||||
opts.ForDataRetention = *args.ForDataRetention
|
||||
}
|
||||
if args.ForIndexing != nil {
|
||||
opts.ForIndexing = *args.ForIndexing
|
||||
}
|
||||
|
||||
policyResolver, err := r.resolver.PoliciesResolver().PolicyResolverFactory(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
policies, totalCount, err := policyResolver.GetConfigurationPolicies(ctx, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
p := sharedConfigurationPoliciesListToStoreConfigurationPoliciesList(policies)
|
||||
return NewCodeIntelligenceConfigurationPolicyConnectionResolver(r.db, p, totalCount, traceErrs), nil
|
||||
func (r *Resolver) CodeIntelligenceConfigurationPolicies(ctx context.Context, args *policiesgraphql.CodeIntelligenceConfigurationPoliciesArgs) (_ policiesgraphql.CodeIntelligenceConfigurationPolicyConnectionResolver, err error) {
|
||||
return r.resolver.PoliciesRootResolver().CodeIntelligenceConfigurationPolicies(ctx, args)
|
||||
}
|
||||
|
||||
// 🚨 SECURITY: Only site admins may modify code intelligence configuration policies
|
||||
func (r *Resolver) CreateCodeIntelligenceConfigurationPolicy(ctx context.Context, args *gql.CreateCodeIntelligenceConfigurationPolicyArgs) (_ gql.CodeIntelligenceConfigurationPolicyResolver, err error) {
|
||||
ctx, traceErrs, endObservation := r.observationContext.createConfigurationPolicy.WithErrors(ctx, &err, observation.Args{LogFields: []log.Field{}})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
if err := backend.CheckCurrentUserIsSiteAdmin(ctx, r.db); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := validateConfigurationPolicy(args.CodeIntelConfigurationPolicy); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var repositoryID *int
|
||||
if args.Repository != nil {
|
||||
id64, err := unmarshalRepositoryID(*args.Repository)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id := int(id64)
|
||||
repositoryID = &id
|
||||
}
|
||||
|
||||
policyResolver, err := r.resolver.PoliciesResolver().PolicyResolverFactory(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
opts := shared.ConfigurationPolicy{
|
||||
RepositoryID: repositoryID,
|
||||
Name: args.Name,
|
||||
RepositoryPatterns: args.RepositoryPatterns,
|
||||
Type: shared.GitObjectType(args.Type),
|
||||
Pattern: args.Pattern,
|
||||
RetentionEnabled: args.RetentionEnabled,
|
||||
RetentionDuration: toDuration(args.RetentionDurationHours),
|
||||
RetainIntermediateCommits: args.RetainIntermediateCommits,
|
||||
IndexingEnabled: args.IndexingEnabled,
|
||||
IndexCommitMaxAge: toDuration(args.IndexCommitMaxAgeHours),
|
||||
IndexIntermediateCommits: args.IndexIntermediateCommits,
|
||||
}
|
||||
configurationPolicy, err := policyResolver.CreateConfigurationPolicy(ctx, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cp := sharedConfigurationPoliciesToStoreConfigurationPolicies(configurationPolicy)
|
||||
return NewConfigurationPolicyResolver(r.db, cp, traceErrs), nil
|
||||
func (r *Resolver) CreateCodeIntelligenceConfigurationPolicy(ctx context.Context, args *policiesgraphql.CreateCodeIntelligenceConfigurationPolicyArgs) (_ policiesgraphql.CodeIntelligenceConfigurationPolicyResolver, err error) {
|
||||
return r.resolver.PoliciesRootResolver().CreateCodeIntelligenceConfigurationPolicy(ctx, args)
|
||||
}
|
||||
|
||||
// 🚨 SECURITY: Only site admins may modify code intelligence configuration policies
|
||||
func (r *Resolver) UpdateCodeIntelligenceConfigurationPolicy(ctx context.Context, args *gql.UpdateCodeIntelligenceConfigurationPolicyArgs) (_ *gql.EmptyResponse, err error) {
|
||||
ctx, _, endObservation := r.observationContext.updateConfigurationPolicy.With(ctx, &err, observation.Args{LogFields: []log.Field{
|
||||
log.String("configPolicyID", string(args.ID)),
|
||||
}})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
if err := backend.CheckCurrentUserIsSiteAdmin(ctx, r.db); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := validateConfigurationPolicy(args.CodeIntelConfigurationPolicy); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id, err := unmarshalConfigurationPolicyGQLID(args.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
policyResolver, err := r.resolver.PoliciesResolver().PolicyResolverFactory(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
opts := shared.ConfigurationPolicy{
|
||||
ID: int(id),
|
||||
Name: args.Name,
|
||||
RepositoryPatterns: args.RepositoryPatterns,
|
||||
Type: shared.GitObjectType(args.Type),
|
||||
Pattern: args.Pattern,
|
||||
RetentionEnabled: args.RetentionEnabled,
|
||||
RetentionDuration: toDuration(args.RetentionDurationHours),
|
||||
RetainIntermediateCommits: args.RetainIntermediateCommits,
|
||||
IndexingEnabled: args.IndexingEnabled,
|
||||
IndexCommitMaxAge: toDuration(args.IndexCommitMaxAgeHours),
|
||||
IndexIntermediateCommits: args.IndexIntermediateCommits,
|
||||
}
|
||||
if err := policyResolver.UpdateConfigurationPolicy(ctx, opts); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &gql.EmptyResponse{}, nil
|
||||
func (r *Resolver) UpdateCodeIntelligenceConfigurationPolicy(ctx context.Context, args *policiesgraphql.UpdateCodeIntelligenceConfigurationPolicyArgs) (_ *sharedresolvers.EmptyResponse, err error) {
|
||||
return r.resolver.PoliciesRootResolver().UpdateCodeIntelligenceConfigurationPolicy(ctx, args)
|
||||
}
|
||||
|
||||
// 🚨 SECURITY: Only site admins may modify code intelligence configuration policies
|
||||
func (r *Resolver) DeleteCodeIntelligenceConfigurationPolicy(ctx context.Context, args *gql.DeleteCodeIntelligenceConfigurationPolicyArgs) (_ *gql.EmptyResponse, err error) {
|
||||
ctx, _, endObservation := r.observationContext.deleteConfigurationPolicy.With(ctx, &err, observation.Args{LogFields: []log.Field{
|
||||
log.String("configPolicyID", string(args.Policy)),
|
||||
}})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
if err := backend.CheckCurrentUserIsSiteAdmin(ctx, r.db); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id, err := unmarshalConfigurationPolicyGQLID(args.Policy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
policyResolver, err := r.resolver.PoliciesResolver().PolicyResolverFactory(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := policyResolver.DeleteConfigurationPolicyByID(ctx, int(id)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &gql.EmptyResponse{}, nil
|
||||
func (r *Resolver) DeleteCodeIntelligenceConfigurationPolicy(ctx context.Context, args *policiesgraphql.DeleteCodeIntelligenceConfigurationPolicyArgs) (_ *sharedresolvers.EmptyResponse, err error) {
|
||||
return r.resolver.PoliciesRootResolver().DeleteCodeIntelligenceConfigurationPolicy(ctx, args)
|
||||
}
|
||||
|
||||
func (r *Resolver) RepositorySummary(ctx context.Context, id graphql.ID) (_ gql.CodeIntelRepositorySummaryResolver, err error) {
|
||||
ctx, errTracer, endObservation := r.observationContext.repositorySummary.WithErrors(ctx, &err, observation.Args{LogFields: []log.Field{
|
||||
log.String("repoID", string(id)),
|
||||
}})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
repositoryID, err := gql.UnmarshalRepositoryID(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
repoID := int(repositoryID)
|
||||
|
||||
uploadResolver := r.resolver.UploadsResolver()
|
||||
recentUploads, err := uploadResolver.GetRecentUploadsSummary(ctx, repoID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
lastUploadRetentionScan, err := uploadResolver.GetLastUploadRetentionScanForRepository(ctx, repoID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
autoindexingResolver := r.resolver.AutoIndexingResolver()
|
||||
recentIndexes, err := autoindexingResolver.GetRecentIndexesSummary(ctx, repoID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
lastIndexScan, err := autoindexingResolver.GetLastIndexScanForRepository(ctx, repoID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
summary := RepositorySummary{
|
||||
RecentUploads: recentUploads,
|
||||
RecentIndexes: recentIndexes,
|
||||
LastUploadRetentionScan: lastUploadRetentionScan,
|
||||
LastIndexScan: lastIndexScan,
|
||||
}
|
||||
|
||||
// Create a new prefetcher here as we only want to cache upload and index records in
|
||||
// the same graphQL request, not across different request.
|
||||
prefetcher := NewPrefetcher(r.resolver)
|
||||
|
||||
return NewRepositorySummaryResolver(
|
||||
r.db,
|
||||
r.resolver,
|
||||
r.gitserver,
|
||||
summary,
|
||||
prefetcher,
|
||||
r.locationResolver,
|
||||
errTracer,
|
||||
), nil
|
||||
func (r *Resolver) RepositorySummary(ctx context.Context, id graphql.ID) (_ sharedresolvers.CodeIntelRepositorySummaryResolver, err error) {
|
||||
return r.resolver.AutoIndexingRootResolver().RepositorySummary(ctx, id)
|
||||
}
|
||||
|
||||
// 🚨 SECURITY: Only entrypoint is within the repository resolver so the user is already authenticated
|
||||
func (r *Resolver) IndexConfiguration(ctx context.Context, id graphql.ID) (_ gql.IndexConfigurationResolver, err error) {
|
||||
_, traceErrs, endObservation := r.observationContext.indexConfiguration.WithErrors(ctx, &err, observation.Args{LogFields: []log.Field{
|
||||
log.String("repoID", string(id)),
|
||||
}})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
if !autoIndexingEnabled() {
|
||||
return nil, errAutoIndexingNotEnabled
|
||||
}
|
||||
|
||||
repositoryID, err := gql.UnmarshalRepositoryID(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewIndexConfigurationResolver(r.resolver, int(repositoryID), traceErrs), nil
|
||||
func (r *Resolver) IndexConfiguration(ctx context.Context, id graphql.ID) (_ autoindexinggraphql.IndexConfigurationResolver, err error) {
|
||||
return r.resolver.AutoIndexingRootResolver().IndexConfiguration(ctx, id)
|
||||
}
|
||||
|
||||
// 🚨 SECURITY: Only site admins may modify code intelligence indexing configuration
|
||||
func (r *Resolver) UpdateRepositoryIndexConfiguration(ctx context.Context, args *gql.UpdateRepositoryIndexConfigurationArgs) (_ *gql.EmptyResponse, err error) {
|
||||
ctx, _, endObservation := r.observationContext.updateIndexConfiguration.With(ctx, &err, observation.Args{LogFields: []log.Field{
|
||||
log.String("repoID", string(args.Repository)),
|
||||
}})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
if err := backend.CheckCurrentUserIsSiteAdmin(ctx, r.db); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !autoIndexingEnabled() {
|
||||
return nil, errAutoIndexingNotEnabled
|
||||
}
|
||||
|
||||
repositoryID, err := unmarshalLSIFIndexGQLID(args.Repository)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
autoIndexingResolver := r.resolver.AutoIndexingResolver()
|
||||
if err := autoIndexingResolver.UpdateIndexConfigurationByRepositoryID(ctx, int(repositoryID), args.Configuration); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &gql.EmptyResponse{}, nil
|
||||
func (r *Resolver) UpdateRepositoryIndexConfiguration(ctx context.Context, args *autoindexinggraphql.UpdateRepositoryIndexConfigurationArgs) (_ *sharedresolvers.EmptyResponse, err error) {
|
||||
return r.resolver.AutoIndexingRootResolver().UpdateRepositoryIndexConfiguration(ctx, args)
|
||||
}
|
||||
|
||||
func (r *Resolver) PreviewRepositoryFilter(ctx context.Context, args *gql.PreviewRepositoryFilterArgs) (_ gql.RepositoryFilterPreviewResolver, err error) {
|
||||
ctx, _, endObservation := r.observationContext.previewRepoFilter.With(ctx, &err, observation.Args{})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
offset, err := graphqlutil.DecodeIntCursor(args.After)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pageSize := DefaultRepositoryFilterPreviewPageSize
|
||||
if args.First != nil {
|
||||
pageSize = int(*args.First)
|
||||
}
|
||||
|
||||
policyResolver, err := r.resolver.PoliciesResolver().PolicyResolverFactory(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ids, totalCount, repositoryMatchLimit, err := policyResolver.GetPreviewRepositoryFilter(ctx, args.Patterns, pageSize, offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resv := make([]*gql.RepositoryResolver, 0, len(ids))
|
||||
for _, id := range ids {
|
||||
repo, err := backend.NewRepos(r.locationResolver.logger, r.db).Get(ctx, api.RepoID(id))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resv = append(resv, gql.NewRepositoryResolver(r.db, repo))
|
||||
}
|
||||
|
||||
limitedCount := totalCount
|
||||
if repositoryMatchLimit != nil && *repositoryMatchLimit < limitedCount {
|
||||
limitedCount = *repositoryMatchLimit
|
||||
}
|
||||
|
||||
return &repositoryFilterPreviewResolver{
|
||||
repositoryResolvers: resv,
|
||||
totalCount: limitedCount,
|
||||
offset: offset,
|
||||
totalMatches: totalCount,
|
||||
limit: repositoryMatchLimit,
|
||||
}, nil
|
||||
func (r *Resolver) PreviewRepositoryFilter(ctx context.Context, args *policiesgraphql.PreviewRepositoryFilterArgs) (_ policiesgraphql.RepositoryFilterPreviewResolver, err error) {
|
||||
return r.resolver.PoliciesRootResolver().PreviewRepositoryFilter(ctx, args)
|
||||
}
|
||||
|
||||
func (r *Resolver) PreviewGitObjectFilter(ctx context.Context, id graphql.ID, args *gql.PreviewGitObjectFilterArgs) (_ []gql.GitObjectFilterPreviewResolver, err error) {
|
||||
ctx, _, endObservation := r.observationContext.previewGitObjectFilter.With(ctx, &err, observation.Args{})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
repositoryID, err := unmarshalLSIFIndexGQLID(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
policyResolver, err := r.resolver.PoliciesResolver().PolicyResolverFactory(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
namesByRev, err := policyResolver.GetPreviewGitObjectFilter(ctx, int(repositoryID), shared.GitObjectType(args.Type), args.Pattern)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var previews []gql.GitObjectFilterPreviewResolver
|
||||
for rev, names := range namesByRev {
|
||||
for _, name := range names {
|
||||
previews = append(previews, &gitObjectFilterPreviewResolver{
|
||||
name: name,
|
||||
rev: rev,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
sort.Slice(previews, func(i, j int) bool {
|
||||
return previews[i].Name() < previews[j].Name() || (previews[i].Name() == previews[j].Name() && previews[i].Rev() < previews[j].Rev())
|
||||
})
|
||||
|
||||
return previews, nil
|
||||
}
|
||||
|
||||
// makeGetUploadsOptions translates the given GraphQL arguments into options defined by the
|
||||
// store.GetUploads operations.
|
||||
func makeGetUploadsOptions(args *gql.LSIFRepositoryUploadsQueryArgs) (uploadsShared.GetUploadsOptions, error) {
|
||||
repositoryID, err := resolveRepositoryID(args.RepositoryID)
|
||||
if err != nil {
|
||||
return uploadsShared.GetUploadsOptions{}, err
|
||||
}
|
||||
|
||||
var dependencyOf int64
|
||||
if args.DependencyOf != nil {
|
||||
dependencyOf, err = unmarshalLSIFUploadGQLID(*args.DependencyOf)
|
||||
if err != nil {
|
||||
return uploadsShared.GetUploadsOptions{}, err
|
||||
}
|
||||
}
|
||||
|
||||
var dependentOf int64
|
||||
if args.DependentOf != nil {
|
||||
dependentOf, err = unmarshalLSIFUploadGQLID(*args.DependentOf)
|
||||
if err != nil {
|
||||
return uploadsShared.GetUploadsOptions{}, err
|
||||
}
|
||||
}
|
||||
|
||||
offset, err := graphqlutil.DecodeIntCursor(args.After)
|
||||
if err != nil {
|
||||
return uploadsShared.GetUploadsOptions{}, err
|
||||
}
|
||||
|
||||
return uploadsShared.GetUploadsOptions{
|
||||
RepositoryID: repositoryID,
|
||||
State: strings.ToLower(derefString(args.State, "")),
|
||||
Term: derefString(args.Query, ""),
|
||||
VisibleAtTip: derefBool(args.IsLatestForRepo, false),
|
||||
DependencyOf: int(dependencyOf),
|
||||
DependentOf: int(dependentOf),
|
||||
Limit: derefInt32(args.First, DefaultUploadPageSize),
|
||||
Offset: offset,
|
||||
AllowExpired: true,
|
||||
AllowDeletedUpload: derefBool(args.IncludeDeleted, false),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// makeGetIndexesOptions translates the given GraphQL arguments into options defined by the
|
||||
// store.GetIndexes operations.
|
||||
func makeGetIndexesOptions(args *gql.LSIFRepositoryIndexesQueryArgs) (autoindexingShared.GetIndexesOptions, error) {
|
||||
repositoryID, err := resolveRepositoryID(args.RepositoryID)
|
||||
if err != nil {
|
||||
return autoindexingShared.GetIndexesOptions{}, err
|
||||
}
|
||||
|
||||
offset, err := graphqlutil.DecodeIntCursor(args.After)
|
||||
if err != nil {
|
||||
return autoindexingShared.GetIndexesOptions{}, err
|
||||
}
|
||||
|
||||
return autoindexingShared.GetIndexesOptions{
|
||||
RepositoryID: repositoryID,
|
||||
State: strings.ToLower(derefString(args.State, "")),
|
||||
Term: derefString(args.Query, ""),
|
||||
Limit: derefInt32(args.First, DefaultIndexPageSize),
|
||||
Offset: offset,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// resolveRepositoryByID gets a repository's internal identifier from a GraphQL identifier.
|
||||
func resolveRepositoryID(id graphql.ID) (int, error) {
|
||||
if id == "" {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
repoID, err := gql.UnmarshalRepositoryID(id)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return int(repoID), nil
|
||||
}
|
||||
|
||||
func validateConfigurationPolicy(policy gql.CodeIntelConfigurationPolicy) error {
|
||||
switch policy.Type {
|
||||
case gql.GitObjectTypeCommit:
|
||||
case gql.GitObjectTypeTag:
|
||||
case gql.GitObjectTypeTree:
|
||||
default:
|
||||
return errors.Errorf("illegal git object type '%s', expected 'GIT_COMMIT', 'GIT_TAG', or 'GIT_TREE'", policy.Type)
|
||||
}
|
||||
|
||||
if policy.Name == "" {
|
||||
return errors.Errorf("no name supplied")
|
||||
}
|
||||
if policy.Pattern == "" {
|
||||
return errors.Errorf("no pattern supplied")
|
||||
}
|
||||
if policy.Type == gql.GitObjectTypeCommit && policy.Pattern != "HEAD" {
|
||||
return errors.Errorf("pattern must be HEAD for policy type 'GIT_COMMIT'")
|
||||
}
|
||||
if policy.RetentionDurationHours != nil && *policy.RetentionDurationHours <= 0 {
|
||||
return errors.Errorf("illegal retention duration '%d'", *policy.RetentionDurationHours)
|
||||
}
|
||||
if policy.IndexCommitMaxAgeHours != nil && *policy.IndexCommitMaxAgeHours <= 0 {
|
||||
return errors.Errorf("illegal index commit max age '%d'", *policy.IndexCommitMaxAgeHours)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func toDuration(hours *int32) *time.Duration {
|
||||
if hours == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
v := time.Duration(*hours) * time.Hour
|
||||
return &v
|
||||
func (r *Resolver) PreviewGitObjectFilter(ctx context.Context, id graphql.ID, args *policiesgraphql.PreviewGitObjectFilterArgs) (_ []policiesgraphql.GitObjectFilterPreviewResolver, err error) {
|
||||
return r.resolver.PoliciesRootResolver().PreviewGitObjectFilter(ctx, id, args)
|
||||
}
|
||||
|
||||
@ -1,201 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/graph-gophers/graphql-go"
|
||||
|
||||
"github.com/sourcegraph/log/logtest"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/backend"
|
||||
gql "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil"
|
||||
resolvermocks "github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/codeintel/resolvers/mocks"
|
||||
transportmocks "github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/codeintel/resolvers/mocks/transport"
|
||||
uploadmocks "github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/codeintel/resolvers/mocks/transport/uploads"
|
||||
autoindexingShared "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared"
|
||||
uploadsShared "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
)
|
||||
|
||||
func init() {
|
||||
autoIndexingEnabled = func() bool { return true }
|
||||
}
|
||||
|
||||
func TestDeleteLSIFUpload(t *testing.T) {
|
||||
users := database.NewStrictMockUserStore()
|
||||
users.GetByCurrentAuthUserFunc.SetDefaultReturn(&types.User{SiteAdmin: true}, nil)
|
||||
|
||||
db := database.NewMockDB()
|
||||
db.UsersFunc.SetDefaultReturn(users)
|
||||
|
||||
id := graphql.ID(base64.StdEncoding.EncodeToString([]byte("LSIFUpload:42")))
|
||||
mockUploadResolver := uploadmocks.NewMockResolver()
|
||||
mockResolver := resolvermocks.NewMockResolver()
|
||||
mockResolver.UploadsResolverFunc.SetDefaultReturn(mockUploadResolver)
|
||||
|
||||
if _, err := NewResolver(db, nil, mockResolver, &observation.TestContext).DeleteLSIFUpload(context.Background(), &struct{ ID graphql.ID }{id}); err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
|
||||
if len(mockUploadResolver.DeleteUploadByIDFunc.History()) != 1 {
|
||||
t.Fatalf("unexpected call count. want=%d have=%d", 1, len(mockUploadResolver.DeleteUploadByIDFunc.History()))
|
||||
}
|
||||
if val := mockUploadResolver.DeleteUploadByIDFunc.History()[0].Arg1; val != 42 {
|
||||
t.Fatalf("unexpected upload id. want=%d have=%d", 42, val)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteLSIFUploadUnauthenticated(t *testing.T) {
|
||||
logger := logtest.Scoped(t)
|
||||
db := database.NewDB(logger, nil)
|
||||
|
||||
id := graphql.ID(base64.StdEncoding.EncodeToString([]byte("LSIFUpload:42")))
|
||||
mockResolver := resolvermocks.NewMockResolver()
|
||||
|
||||
if _, err := NewResolver(db, nil, mockResolver, &observation.TestContext).DeleteLSIFUpload(context.Background(), &struct{ ID graphql.ID }{id}); err != backend.ErrNotAuthenticated {
|
||||
t.Errorf("unexpected error. want=%q have=%q", backend.ErrNotAuthenticated, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteLSIFIndex(t *testing.T) {
|
||||
users := database.NewStrictMockUserStore()
|
||||
users.GetByCurrentAuthUserFunc.SetDefaultReturn(&types.User{SiteAdmin: true}, nil)
|
||||
|
||||
db := database.NewStrictMockDB()
|
||||
db.UsersFunc.SetDefaultReturn(users)
|
||||
|
||||
id := graphql.ID(base64.StdEncoding.EncodeToString([]byte("LSIFIndex:42")))
|
||||
mockResolver := resolvermocks.NewMockResolver()
|
||||
mockAutoIndexingResolver := transportmocks.NewMockResolver()
|
||||
mockResolver.AutoIndexingResolverFunc.PushReturn(mockAutoIndexingResolver)
|
||||
|
||||
if _, err := NewResolver(db, nil, mockResolver, &observation.TestContext).DeleteLSIFIndex(context.Background(), &struct{ ID graphql.ID }{id}); err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
|
||||
if len(mockAutoIndexingResolver.DeleteIndexByIDFunc.History()) != 1 {
|
||||
t.Fatalf("unexpected call count. want=%d have=%d", 1, len(mockAutoIndexingResolver.DeleteIndexByIDFunc.History()))
|
||||
}
|
||||
if val := mockAutoIndexingResolver.DeleteIndexByIDFunc.History()[0].Arg1; val != 42 {
|
||||
t.Fatalf("unexpected index id. want=%d have=%d", 42, val)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteLSIFIndexUnauthenticated(t *testing.T) {
|
||||
logger := logtest.Scoped(t)
|
||||
db := database.NewDB(logger, nil)
|
||||
|
||||
id := graphql.ID(base64.StdEncoding.EncodeToString([]byte("LSIFIndex:42")))
|
||||
mockResolver := resolvermocks.NewMockResolver()
|
||||
|
||||
if _, err := NewResolver(db, nil, mockResolver, &observation.TestContext).DeleteLSIFIndex(context.Background(), &struct{ ID graphql.ID }{id}); err != backend.ErrNotAuthenticated {
|
||||
t.Errorf("unexpected error. want=%q have=%q", backend.ErrNotAuthenticated, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMakeGetUploadsOptions(t *testing.T) {
|
||||
opts, err := makeGetUploadsOptions(&gql.LSIFRepositoryUploadsQueryArgs{
|
||||
LSIFUploadsQueryArgs: &gql.LSIFUploadsQueryArgs{
|
||||
ConnectionArgs: graphqlutil.ConnectionArgs{
|
||||
First: intPtr(5),
|
||||
},
|
||||
Query: strPtr("q"),
|
||||
State: strPtr("s"),
|
||||
IsLatestForRepo: boolPtr(true),
|
||||
After: graphqlutil.EncodeIntCursor(intPtr(25)).EndCursor(),
|
||||
},
|
||||
RepositoryID: graphql.ID(base64.StdEncoding.EncodeToString([]byte("Repo:50"))),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error making options: %s", err)
|
||||
}
|
||||
|
||||
expected := uploadsShared.GetUploadsOptions{
|
||||
RepositoryID: 50,
|
||||
State: "s",
|
||||
Term: "q",
|
||||
VisibleAtTip: true,
|
||||
Limit: 5,
|
||||
Offset: 25,
|
||||
AllowExpired: true,
|
||||
}
|
||||
if diff := cmp.Diff(expected, opts); diff != "" {
|
||||
t.Errorf("unexpected opts (-want +got):\n%s", diff)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMakeGetUploadsOptionsDefaults(t *testing.T) {
|
||||
opts, err := makeGetUploadsOptions(&gql.LSIFRepositoryUploadsQueryArgs{
|
||||
LSIFUploadsQueryArgs: &gql.LSIFUploadsQueryArgs{},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error making options: %s", err)
|
||||
}
|
||||
|
||||
expected := uploadsShared.GetUploadsOptions{
|
||||
RepositoryID: 0,
|
||||
State: "",
|
||||
Term: "",
|
||||
VisibleAtTip: false,
|
||||
Limit: DefaultUploadPageSize,
|
||||
Offset: 0,
|
||||
AllowExpired: true,
|
||||
}
|
||||
if diff := cmp.Diff(expected, opts); diff != "" {
|
||||
t.Errorf("unexpected opts (-want +got):\n%s", diff)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMakeGetIndexesOptions(t *testing.T) {
|
||||
opts, err := makeGetIndexesOptions(&gql.LSIFRepositoryIndexesQueryArgs{
|
||||
LSIFIndexesQueryArgs: &gql.LSIFIndexesQueryArgs{
|
||||
ConnectionArgs: graphqlutil.ConnectionArgs{
|
||||
First: intPtr(5),
|
||||
},
|
||||
Query: strPtr("q"),
|
||||
State: strPtr("s"),
|
||||
After: graphqlutil.EncodeIntCursor(intPtr(25)).EndCursor(),
|
||||
},
|
||||
RepositoryID: graphql.ID(base64.StdEncoding.EncodeToString([]byte("Repo:50"))),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error making options: %s", err)
|
||||
}
|
||||
|
||||
expected := autoindexingShared.GetIndexesOptions{
|
||||
RepositoryID: 50,
|
||||
State: "s",
|
||||
Term: "q",
|
||||
Limit: 5,
|
||||
Offset: 25,
|
||||
}
|
||||
if diff := cmp.Diff(expected, opts); diff != "" {
|
||||
t.Errorf("unexpected opts (-want +got):\n%s", diff)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMakeGetIndexesOptionsDefaults(t *testing.T) {
|
||||
opts, err := makeGetIndexesOptions(&gql.LSIFRepositoryIndexesQueryArgs{
|
||||
LSIFIndexesQueryArgs: &gql.LSIFIndexesQueryArgs{},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error making options: %s", err)
|
||||
}
|
||||
|
||||
expected := autoindexingShared.GetIndexesOptions{
|
||||
RepositoryID: 0,
|
||||
State: "",
|
||||
Term: "",
|
||||
Limit: DefaultIndexPageSize,
|
||||
Offset: 0,
|
||||
}
|
||||
if diff := cmp.Diff(expected, opts); diff != "" {
|
||||
t.Errorf("unexpected opts (-want +got):\n%s", diff)
|
||||
}
|
||||
}
|
||||
@ -1,47 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
gql "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil"
|
||||
"github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/codeintel/resolvers"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
)
|
||||
|
||||
type codeIntelligenceRetentionPolicyMatcherConnectionResolver struct {
|
||||
db database.DB
|
||||
resolver resolvers.Resolver
|
||||
policies []RetentionPolicyMatchCandidate
|
||||
totalCount int
|
||||
errTracer *observation.ErrCollector
|
||||
}
|
||||
|
||||
func NewCodeIntelligenceRetentionPolicyMatcherConnectionResolver(db database.DB, resolver resolvers.Resolver, policies []RetentionPolicyMatchCandidate, totalCount int, errTracer *observation.ErrCollector) *codeIntelligenceRetentionPolicyMatcherConnectionResolver {
|
||||
return &codeIntelligenceRetentionPolicyMatcherConnectionResolver{
|
||||
db: db,
|
||||
resolver: resolver,
|
||||
policies: policies,
|
||||
totalCount: totalCount,
|
||||
errTracer: errTracer,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *codeIntelligenceRetentionPolicyMatcherConnectionResolver) Nodes(ctx context.Context) ([]gql.CodeIntelligenceRetentionPolicyMatchResolver, error) {
|
||||
resolvers := make([]gql.CodeIntelligenceRetentionPolicyMatchResolver, 0, len(r.policies))
|
||||
for _, policy := range r.policies {
|
||||
resolvers = append(resolvers, NewRetentionPolicyMatcherResolver(r.db, policy))
|
||||
}
|
||||
|
||||
return resolvers, nil
|
||||
}
|
||||
|
||||
func (r *codeIntelligenceRetentionPolicyMatcherConnectionResolver) TotalCount(ctx context.Context) (*int32, error) {
|
||||
v := int32(r.totalCount)
|
||||
return &v, nil
|
||||
}
|
||||
|
||||
func (r *codeIntelligenceRetentionPolicyMatcherConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) {
|
||||
return graphqlutil.HasNextPage(len(r.policies) < r.totalCount), nil
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
gql "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
)
|
||||
|
||||
type RetentionPolicyMatcherResolver struct {
|
||||
db database.DB
|
||||
policy RetentionPolicyMatchCandidate
|
||||
errCollector *observation.ErrCollector
|
||||
}
|
||||
|
||||
func NewRetentionPolicyMatcherResolver(db database.DB, policy RetentionPolicyMatchCandidate) *RetentionPolicyMatcherResolver {
|
||||
return &RetentionPolicyMatcherResolver{db: db, policy: policy}
|
||||
}
|
||||
|
||||
func (r *RetentionPolicyMatcherResolver) ConfigurationPolicy() gql.CodeIntelligenceConfigurationPolicyResolver {
|
||||
if r.policy.ConfigurationPolicy == nil {
|
||||
return nil
|
||||
}
|
||||
return NewConfigurationPolicyResolver(r.db, *r.policy.ConfigurationPolicy, r.errCollector)
|
||||
}
|
||||
|
||||
func (r *RetentionPolicyMatcherResolver) Matches() bool {
|
||||
return r.policy.Matched
|
||||
}
|
||||
|
||||
func (r *RetentionPolicyMatcherResolver) ProtectingCommits() *[]string {
|
||||
return &r.policy.ProtectingCommits
|
||||
}
|
||||
@ -1,145 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
gql "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
"github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/codeintel/resolvers"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/stores/dbstore"
|
||||
uploadsShared "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
)
|
||||
|
||||
type repositorySummaryResolver struct {
|
||||
db database.DB
|
||||
resolver resolvers.Resolver
|
||||
gitserver GitserverClient
|
||||
summary RepositorySummary
|
||||
prefetcher *Prefetcher
|
||||
locationResolver *CachedLocationResolver
|
||||
errTracer *observation.ErrCollector
|
||||
}
|
||||
|
||||
func NewRepositorySummaryResolver(
|
||||
db database.DB,
|
||||
resolver resolvers.Resolver,
|
||||
gitserver GitserverClient,
|
||||
summary RepositorySummary,
|
||||
prefetcher *Prefetcher,
|
||||
locationResolver *CachedLocationResolver,
|
||||
errTracer *observation.ErrCollector,
|
||||
) gql.CodeIntelRepositorySummaryResolver {
|
||||
return &repositorySummaryResolver{
|
||||
db: db,
|
||||
resolver: resolver,
|
||||
gitserver: gitserver,
|
||||
summary: summary,
|
||||
prefetcher: prefetcher,
|
||||
locationResolver: locationResolver,
|
||||
errTracer: errTracer,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *repositorySummaryResolver) RecentUploads() []gql.LSIFUploadsWithRepositoryNamespaceResolver {
|
||||
resolvers := make([]gql.LSIFUploadsWithRepositoryNamespaceResolver, 0, len(r.summary.RecentUploads))
|
||||
for _, upload := range r.summary.RecentUploads {
|
||||
uploadResolvers := make([]gql.LSIFUploadResolver, 0, len(upload.Uploads))
|
||||
for _, u := range upload.Uploads {
|
||||
upload := convertSharedUploadsToDBStoreUploads(u)
|
||||
uploadResolvers = append(uploadResolvers, NewUploadResolver(r.db, r.gitserver, r.resolver, upload, r.prefetcher, r.locationResolver, r.errTracer))
|
||||
}
|
||||
|
||||
resolvers = append(resolvers, NewLSIFUploadsWithRepositoryNamespaceResolver(upload, uploadResolvers))
|
||||
}
|
||||
|
||||
return resolvers
|
||||
}
|
||||
|
||||
func (r *repositorySummaryResolver) RecentIndexes() []gql.LSIFIndexesWithRepositoryNamespaceResolver {
|
||||
resolvers := make([]gql.LSIFIndexesWithRepositoryNamespaceResolver, 0, len(r.summary.RecentIndexes))
|
||||
for _, index := range r.summary.RecentIndexes {
|
||||
indexResolvers := make([]gql.LSIFIndexResolver, 0, len(index.Indexes))
|
||||
for _, u := range index.Indexes {
|
||||
upload := convertSharedIndexToDBStoreIndex(u)
|
||||
indexResolvers = append(indexResolvers, NewIndexResolver(r.db, r.gitserver, r.resolver, upload, r.prefetcher, r.locationResolver, r.errTracer))
|
||||
}
|
||||
dbstoreIndex := convertSharedIndexesWithRepositoryNamespaceToDBStoreIndexesWithRepositoryNamespace(index)
|
||||
resolvers = append(resolvers, NewLSIFIndexesWithRepositoryNamespaceResolver(dbstoreIndex, indexResolvers))
|
||||
}
|
||||
|
||||
return resolvers
|
||||
}
|
||||
|
||||
func (r *repositorySummaryResolver) LastUploadRetentionScan() *gql.DateTime {
|
||||
return gql.DateTimeOrNil(r.summary.LastUploadRetentionScan)
|
||||
}
|
||||
|
||||
func (r *repositorySummaryResolver) LastIndexScan() *gql.DateTime {
|
||||
return gql.DateTimeOrNil(r.summary.LastIndexScan)
|
||||
}
|
||||
|
||||
type LSIFUploadsWithRepositoryNamespaceResolver struct {
|
||||
uploadsSummary uploadsShared.UploadsWithRepositoryNamespace
|
||||
uploadResolvers []gql.LSIFUploadResolver
|
||||
}
|
||||
|
||||
func NewLSIFUploadsWithRepositoryNamespaceResolver(
|
||||
uploadsSummary uploadsShared.UploadsWithRepositoryNamespace,
|
||||
uploadResolvers []gql.LSIFUploadResolver,
|
||||
) gql.LSIFUploadsWithRepositoryNamespaceResolver {
|
||||
return &LSIFUploadsWithRepositoryNamespaceResolver{
|
||||
uploadsSummary: uploadsSummary,
|
||||
uploadResolvers: uploadResolvers,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *LSIFUploadsWithRepositoryNamespaceResolver) Root() string {
|
||||
return r.uploadsSummary.Root
|
||||
}
|
||||
|
||||
func (r *LSIFUploadsWithRepositoryNamespaceResolver) Indexer() gql.CodeIntelIndexerResolver {
|
||||
for _, indexer := range allIndexers {
|
||||
if indexer.Name() == r.uploadsSummary.Indexer {
|
||||
return indexer
|
||||
}
|
||||
}
|
||||
|
||||
return &codeIntelIndexerResolver{name: r.uploadsSummary.Indexer}
|
||||
}
|
||||
|
||||
func (r *LSIFUploadsWithRepositoryNamespaceResolver) Uploads() []gql.LSIFUploadResolver {
|
||||
return r.uploadResolvers
|
||||
}
|
||||
|
||||
type LSIFIndexesWithRepositoryNamespaceResolver struct {
|
||||
indexesSummary dbstore.IndexesWithRepositoryNamespace
|
||||
indexResolvers []gql.LSIFIndexResolver
|
||||
}
|
||||
|
||||
func NewLSIFIndexesWithRepositoryNamespaceResolver(
|
||||
indexesSummary dbstore.IndexesWithRepositoryNamespace,
|
||||
indexResolvers []gql.LSIFIndexResolver,
|
||||
) gql.LSIFIndexesWithRepositoryNamespaceResolver {
|
||||
return &LSIFIndexesWithRepositoryNamespaceResolver{
|
||||
indexesSummary: indexesSummary,
|
||||
indexResolvers: indexResolvers,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *LSIFIndexesWithRepositoryNamespaceResolver) Root() string {
|
||||
return r.indexesSummary.Root
|
||||
}
|
||||
|
||||
func (r *LSIFIndexesWithRepositoryNamespaceResolver) Indexer() gql.CodeIntelIndexerResolver {
|
||||
// drop the tag if it exists
|
||||
if idx, ok := imageToIndexer[strings.Split(r.indexesSummary.Indexer, ":")[0]]; ok {
|
||||
return idx
|
||||
}
|
||||
|
||||
return &codeIntelIndexerResolver{name: r.indexesSummary.Indexer}
|
||||
}
|
||||
|
||||
func (r *LSIFIndexesWithRepositoryNamespaceResolver) Indexes() []gql.LSIFIndexResolver {
|
||||
return r.indexResolvers
|
||||
}
|
||||
@ -1,113 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
gql "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
"github.com/sourcegraph/sourcegraph/internal/actor"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
)
|
||||
|
||||
type searchBasedCodeIntelSupportType string
|
||||
|
||||
const (
|
||||
unsupported searchBasedCodeIntelSupportType = "UNSUPPORTED"
|
||||
basic searchBasedCodeIntelSupportType = "BASIC"
|
||||
)
|
||||
|
||||
type preciseCodeIntelSupportType string
|
||||
|
||||
const (
|
||||
native preciseCodeIntelSupportType = "NATIVE"
|
||||
thirdParty preciseCodeIntelSupportType = "THIRD_PARTY"
|
||||
unknown preciseCodeIntelSupportType = "UNKNOWN"
|
||||
)
|
||||
|
||||
type searchBasedSupportResolver struct {
|
||||
language string
|
||||
}
|
||||
|
||||
func NewSearchBasedCodeIntelResolver(language string) gql.SearchBasedSupportResolver {
|
||||
return &searchBasedSupportResolver{language}
|
||||
}
|
||||
|
||||
func (r *searchBasedSupportResolver) SupportLevel() string {
|
||||
if r.language != "" {
|
||||
return string(basic)
|
||||
}
|
||||
return string(unsupported)
|
||||
}
|
||||
|
||||
func (r *searchBasedSupportResolver) Language() string {
|
||||
return r.language
|
||||
}
|
||||
|
||||
type preciseCodeIntelSupportResolver struct {
|
||||
indexers []gql.CodeIntelIndexerResolver
|
||||
}
|
||||
|
||||
func NewPreciseCodeIntelSupportResolver(filepath string) gql.PreciseSupportResolver {
|
||||
return &preciseCodeIntelSupportResolver{
|
||||
indexers: languageToIndexer[path.Ext(filepath)],
|
||||
}
|
||||
}
|
||||
|
||||
func NewPreciseCodeIntelSupportResolverFromIndexers(indexers []gql.CodeIntelIndexerResolver) gql.PreciseSupportResolver {
|
||||
return &preciseCodeIntelSupportResolver{
|
||||
indexers: indexers,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *preciseCodeIntelSupportResolver) SupportLevel() string {
|
||||
// if the first indexer in a list is from us, consider native support
|
||||
nativeRecommendation := len(r.indexers) > 0 &&
|
||||
strings.HasPrefix(r.indexers[0].URL(), "https://github.com/sourcegraph")
|
||||
|
||||
if nativeRecommendation {
|
||||
return string(native)
|
||||
} else if len(r.indexers) > 0 {
|
||||
return string(thirdParty)
|
||||
} else {
|
||||
return string(unknown)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *preciseCodeIntelSupportResolver) Indexers() *[]gql.CodeIntelIndexerResolver {
|
||||
if len(r.indexers) == 0 {
|
||||
return nil
|
||||
}
|
||||
return &r.indexers
|
||||
}
|
||||
|
||||
func (r *Resolver) RequestLanguageSupport(ctx context.Context, args *gql.RequestLanguageSupportArgs) (_ *gql.EmptyResponse, err error) {
|
||||
ctx, _, endObservation := r.observationContext.requestLanguageSupport.With(ctx, &err, observation.Args{})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
userID := int(actor.FromContext(ctx).UID)
|
||||
if userID == 0 {
|
||||
return nil, errors.Newf("language support requests only logged for authenticated users")
|
||||
}
|
||||
|
||||
codeNavResolver := r.resolver.CodeNavResolver()
|
||||
if err := codeNavResolver.SetRequestLanguageSupport(ctx, userID, args.Language); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &gql.EmptyResponse{}, nil
|
||||
}
|
||||
|
||||
func (r *Resolver) RequestedLanguageSupport(ctx context.Context) (_ []string, err error) {
|
||||
ctx, _, endObservation := r.observationContext.requestedLanguageSupport.With(ctx, &err, observation.Args{})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
userID := int(actor.FromContext(ctx).UID)
|
||||
if userID == 0 {
|
||||
return nil, errors.Newf("language support requests only logged for authenticated users")
|
||||
}
|
||||
|
||||
codeNavResolver := r.resolver.CodeNavResolver()
|
||||
return codeNavResolver.GetLanguagesRequestedBy(ctx, userID)
|
||||
}
|
||||
@ -1,176 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/graph-gophers/graphql-go"
|
||||
"github.com/opentracing/opentracing-go/log"
|
||||
|
||||
gql "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
"github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/codeintel/resolvers"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/stores/dbstore"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
)
|
||||
|
||||
type UploadResolver struct {
|
||||
db database.DB
|
||||
gitserver GitserverClient
|
||||
resolver resolvers.Resolver
|
||||
upload dbstore.Upload
|
||||
prefetcher *Prefetcher
|
||||
locationResolver *CachedLocationResolver
|
||||
traceErrs *observation.ErrCollector
|
||||
}
|
||||
|
||||
func NewUploadResolver(db database.DB, gitserver GitserverClient, resolver resolvers.Resolver, upload dbstore.Upload, prefetcher *Prefetcher, locationResolver *CachedLocationResolver, traceErrs *observation.ErrCollector) gql.LSIFUploadResolver {
|
||||
if upload.AssociatedIndexID != nil {
|
||||
// Request the next batch of index fetches to contain the record's associated
|
||||
// index id, if one exists it exists. This allows the prefetcher.GetIndexByID
|
||||
// invocation in the AssociatedIndex method to batch its work with sibling
|
||||
// resolvers, which share the same prefetcher instance.
|
||||
prefetcher.MarkIndex(*upload.AssociatedIndexID)
|
||||
}
|
||||
|
||||
return &UploadResolver{
|
||||
db: db,
|
||||
gitserver: gitserver,
|
||||
resolver: resolver,
|
||||
upload: upload,
|
||||
prefetcher: prefetcher,
|
||||
locationResolver: locationResolver,
|
||||
traceErrs: traceErrs,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *UploadResolver) ID() graphql.ID { return marshalLSIFUploadGQLID(int64(r.upload.ID)) }
|
||||
func (r *UploadResolver) InputCommit() string { return r.upload.Commit }
|
||||
func (r *UploadResolver) InputRoot() string { return r.upload.Root }
|
||||
func (r *UploadResolver) IsLatestForRepo() bool { return r.upload.VisibleAtTip }
|
||||
func (r *UploadResolver) UploadedAt() gql.DateTime { return gql.DateTime{Time: r.upload.UploadedAt} }
|
||||
func (r *UploadResolver) Failure() *string { return r.upload.FailureMessage }
|
||||
func (r *UploadResolver) StartedAt() *gql.DateTime { return gql.DateTimeOrNil(r.upload.StartedAt) }
|
||||
func (r *UploadResolver) FinishedAt() *gql.DateTime { return gql.DateTimeOrNil(r.upload.FinishedAt) }
|
||||
func (r *UploadResolver) InputIndexer() string { return r.upload.Indexer }
|
||||
func (r *UploadResolver) PlaceInQueue() *int32 { return toInt32(r.upload.Rank) }
|
||||
|
||||
func (r *UploadResolver) Tags(ctx context.Context) (tagsNames []string, err error) {
|
||||
tags, err := r.gitserver.ListTags(ctx, api.RepoName(r.upload.RepositoryName), r.upload.Commit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, tag := range tags {
|
||||
tagsNames = append(tagsNames, tag.Name)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (r *UploadResolver) State() string {
|
||||
state := strings.ToUpper(r.upload.State)
|
||||
if state == "FAILED" {
|
||||
state = "ERRORED"
|
||||
}
|
||||
|
||||
return state
|
||||
}
|
||||
|
||||
func (r *UploadResolver) AssociatedIndex(ctx context.Context) (_ gql.LSIFIndexResolver, err error) {
|
||||
// TODO - why are a bunch of them zero?
|
||||
if r.upload.AssociatedIndexID == nil || *r.upload.AssociatedIndexID == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
defer r.traceErrs.Collect(&err,
|
||||
log.String("uploadResolver.field", "associatedIndex"),
|
||||
log.Int("associatedIndex", *r.upload.AssociatedIndexID),
|
||||
)
|
||||
|
||||
index, exists, err := r.prefetcher.GetIndexByID(ctx, *r.upload.AssociatedIndexID)
|
||||
if err != nil || !exists {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewIndexResolver(r.db, r.gitserver, r.resolver, index, r.prefetcher, r.locationResolver, r.traceErrs), nil
|
||||
}
|
||||
|
||||
func (r *UploadResolver) ProjectRoot(ctx context.Context) (*gql.GitTreeEntryResolver, error) {
|
||||
return r.locationResolver.Path(ctx, api.RepoID(r.upload.RepositoryID), r.upload.Commit, r.upload.Root)
|
||||
}
|
||||
|
||||
func (r *UploadResolver) RetentionPolicyOverview(ctx context.Context, args *gql.LSIFUploadRetentionPolicyMatchesArgs) (_ gql.CodeIntelligenceRetentionPolicyMatchesConnectionResolver, err error) {
|
||||
var afterID int64
|
||||
if args.After != nil {
|
||||
afterID, err = unmarshalConfigurationPolicyGQLID(graphql.ID(*args.After))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
pageSize := DefaultRetentionPolicyMatchesPageSize
|
||||
if args.First != nil {
|
||||
pageSize = int(*args.First)
|
||||
}
|
||||
|
||||
var term string
|
||||
if args.Query != nil {
|
||||
term = *args.Query
|
||||
}
|
||||
|
||||
policyResolver, err := r.resolver.PoliciesResolver().PolicyResolverFactory(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
upload := sharedPoliciesUploadsToStoreUpload(r.upload)
|
||||
m, totalCount, err := policyResolver.GetRetentionPolicyOverview(ctx, upload, args.MatchesOnly, pageSize, afterID, term, time.Now())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
matches := sharedRetentionPolicyToStoreRetentionPolicy(m)
|
||||
|
||||
return NewCodeIntelligenceRetentionPolicyMatcherConnectionResolver(r.db, r.resolver, matches, totalCount, r.traceErrs), nil
|
||||
}
|
||||
|
||||
func (r *UploadResolver) Indexer() gql.CodeIntelIndexerResolver {
|
||||
for _, indexer := range allIndexers {
|
||||
if indexer.Name() == r.upload.Indexer {
|
||||
return indexer
|
||||
}
|
||||
}
|
||||
|
||||
return &codeIntelIndexerResolver{name: r.upload.Indexer}
|
||||
}
|
||||
|
||||
func (r *UploadResolver) DocumentPaths(ctx context.Context, args *gql.LSIFUploadDocumentPathsQueryArgs) (gql.LSIFUploadDocumentPathsConnectionResolver, error) {
|
||||
pattern := "%%"
|
||||
if args.Pattern != "" {
|
||||
pattern = args.Pattern
|
||||
}
|
||||
|
||||
documents, totalCount, err := r.resolver.UploadsResolver().GetUploadDocumentsForPath(ctx, r.upload.ID, pattern)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &uploadDocumentPathsConnectionResolver{
|
||||
totalCount: totalCount,
|
||||
documents: documents,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *UploadResolver) AuditLogs(ctx context.Context) (*[]gql.LSIFUploadsAuditLogsResolver, error) {
|
||||
logs, err := r.resolver.UploadsResolver().GetAuditLogsForUpload(ctx, r.upload.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resolvers := make([]gql.LSIFUploadsAuditLogsResolver, 0, len(logs))
|
||||
for _, log := range logs {
|
||||
resolvers = append(resolvers, &lsifUploadsAuditLogResolver{log})
|
||||
}
|
||||
|
||||
return &resolvers, nil
|
||||
}
|
||||
@ -1,69 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/opentracing/opentracing-go/log"
|
||||
|
||||
gql "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil"
|
||||
"github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/codeintel/resolvers"
|
||||
uploadsgraphql "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/transport/graphql"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
)
|
||||
|
||||
type UploadConnectionResolver struct {
|
||||
db database.DB
|
||||
gitserver GitserverClient
|
||||
resolver resolvers.Resolver
|
||||
uploadsResolver *uploadsgraphql.UploadsResolver
|
||||
prefetcher *Prefetcher
|
||||
locationResolver *CachedLocationResolver
|
||||
errTracer *observation.ErrCollector
|
||||
}
|
||||
|
||||
func NewUploadConnectionResolver(db database.DB, gitserver GitserverClient, resolver resolvers.Resolver, uploadsResolver *uploadsgraphql.UploadsResolver, prefetcher *Prefetcher, locationResolver *CachedLocationResolver, errTracer *observation.ErrCollector) gql.LSIFUploadConnectionResolver {
|
||||
return &UploadConnectionResolver{
|
||||
resolver: resolver,
|
||||
db: db,
|
||||
gitserver: gitserver,
|
||||
uploadsResolver: uploadsResolver,
|
||||
prefetcher: prefetcher,
|
||||
locationResolver: locationResolver,
|
||||
errTracer: errTracer,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *UploadConnectionResolver) Nodes(ctx context.Context) (_ []gql.LSIFUploadResolver, err error) {
|
||||
defer r.errTracer.Collect(&err, log.String("uploadConnectionResolver.field", "nodes"))
|
||||
|
||||
if err := r.uploadsResolver.Resolve(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resolvers := make([]gql.LSIFUploadResolver, 0, len(r.uploadsResolver.Uploads))
|
||||
for i := range r.uploadsResolver.Uploads {
|
||||
upload := convertSharedUploadsToDBStoreUploads(r.uploadsResolver.Uploads[i])
|
||||
resolvers = append(resolvers, NewUploadResolver(r.db, r.gitserver, r.resolver, upload, r.prefetcher, r.locationResolver, r.errTracer))
|
||||
}
|
||||
return resolvers, nil
|
||||
}
|
||||
|
||||
func (r *UploadConnectionResolver) TotalCount(ctx context.Context) (_ *int32, err error) {
|
||||
defer r.errTracer.Collect(&err, log.String("uploadConnectionResolver.field", "totalCount"))
|
||||
|
||||
if err := r.uploadsResolver.Resolve(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return toInt32(&r.uploadsResolver.TotalCount), nil
|
||||
}
|
||||
|
||||
func (r *UploadConnectionResolver) PageInfo(ctx context.Context) (_ *graphqlutil.PageInfo, err error) {
|
||||
defer r.errTracer.Collect(&err, log.String("uploadConnectionResolver.field", "pageInfo"))
|
||||
|
||||
if err := r.uploadsResolver.Resolve(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return graphqlutil.EncodeIntCursor(toInt32(r.uploadsResolver.NextOffset)), nil
|
||||
}
|
||||
@ -1,407 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"github.com/sourcegraph/go-lsp"
|
||||
|
||||
autoindexingShared "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/shared"
|
||||
policiesShared "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/stores/dbstore"
|
||||
store "github.com/sourcegraph/sourcegraph/internal/codeintel/stores/dbstore"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/stores/lsifstore"
|
||||
uploadsShared "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/workerutil"
|
||||
"github.com/sourcegraph/sourcegraph/lib/codeintel/precise"
|
||||
)
|
||||
|
||||
// strPtr creates a pointer to the given value. If the value is an
|
||||
// empty string, a nil pointer is returned.
|
||||
func strPtr(val string) *string {
|
||||
if val == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &val
|
||||
}
|
||||
|
||||
// intPtr creates a pointer to the given value.
|
||||
func intPtr(val int32) *int32 {
|
||||
return &val
|
||||
}
|
||||
|
||||
// intPtr creates a pointer to the given value.
|
||||
func boolPtr(val bool) *bool {
|
||||
return &val
|
||||
}
|
||||
|
||||
// toInt32 translates the given int pointer into an int32 pointer.
|
||||
func toInt32(val *int) *int32 {
|
||||
if val == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
v := int32(*val)
|
||||
return &v
|
||||
}
|
||||
|
||||
// derefString returns the underlying value in the given pointer.
|
||||
// If the pointer is nil, the default value is returned.
|
||||
func derefString(val *string, defaultValue string) string {
|
||||
if val != nil {
|
||||
return *val
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
// derefInt32 returns the underlying value in the given pointer.
|
||||
// If the pointer is nil, the default value is returned.
|
||||
func derefInt32(val *int32, defaultValue int) int {
|
||||
if val != nil {
|
||||
return int(*val)
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
// derefBool returns the underlying value in the given pointer.
|
||||
// If the pointer is nil, the default value is returned.
|
||||
func derefBool(val *bool, defaultValue bool) bool {
|
||||
if val != nil {
|
||||
return *val
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
// convertRange creates an LSP range from a bundle range.
|
||||
func convertRange(r lsifstore.Range) lsp.Range {
|
||||
return lsp.Range{Start: convertPosition(r.Start.Line, r.Start.Character), End: convertPosition(r.End.Line, r.End.Character)}
|
||||
}
|
||||
|
||||
// convertPosition creates an LSP position from a line and character pair.
|
||||
func convertPosition(line, character int) lsp.Position {
|
||||
return lsp.Position{Line: line, Character: character}
|
||||
}
|
||||
|
||||
func sharedConfigurationPoliciesListToStoreConfigurationPoliciesList(policies []policiesShared.ConfigurationPolicy) []store.ConfigurationPolicy {
|
||||
storePolicies := make([]store.ConfigurationPolicy, 0, len(policies))
|
||||
for _, p := range policies {
|
||||
storePolicies = append(storePolicies, sharedConfigurationPoliciesToStoreConfigurationPolicies(p))
|
||||
}
|
||||
return storePolicies
|
||||
}
|
||||
|
||||
func sharedConfigurationPoliciesToStoreConfigurationPolicies(p policiesShared.ConfigurationPolicy) store.ConfigurationPolicy {
|
||||
return store.ConfigurationPolicy{
|
||||
ID: p.ID,
|
||||
RepositoryID: p.RepositoryID,
|
||||
RepositoryPatterns: p.RepositoryPatterns,
|
||||
Name: p.Name,
|
||||
Type: store.GitObjectType(p.Type),
|
||||
Pattern: p.Pattern,
|
||||
Protected: p.Protected,
|
||||
RetentionEnabled: p.RetentionEnabled,
|
||||
RetentionDuration: p.RetentionDuration,
|
||||
RetainIntermediateCommits: p.RetainIntermediateCommits,
|
||||
IndexingEnabled: p.IndexingEnabled,
|
||||
IndexCommitMaxAge: p.IndexCommitMaxAge,
|
||||
IndexIntermediateCommits: p.IndexIntermediateCommits,
|
||||
}
|
||||
}
|
||||
|
||||
func sharedRangeTolsifstoreRange(r shared.Range) lsifstore.Range {
|
||||
return lsifstore.Range{
|
||||
Start: lsifstore.Position(r.Start),
|
||||
End: lsifstore.Position(r.End),
|
||||
}
|
||||
}
|
||||
|
||||
func sharedRangeTolspRange(r shared.Range) lsp.Range {
|
||||
return lsp.Range{Start: convertPosition(r.Start.Line, r.Start.Character), End: convertPosition(r.End.Line, r.End.Character)}
|
||||
}
|
||||
|
||||
func sharedRangeToAdjustedRange(rng []shared.AdjustedCodeIntelligenceRange) []AdjustedCodeIntelligenceRange {
|
||||
adjustedRange := make([]AdjustedCodeIntelligenceRange, 0, len(rng))
|
||||
for _, r := range rng {
|
||||
|
||||
definitions := make([]AdjustedLocation, 0, len(r.Definitions))
|
||||
for _, d := range r.Definitions {
|
||||
def := AdjustedLocation{
|
||||
Dump: store.Dump(d.Dump),
|
||||
Path: d.Path,
|
||||
AdjustedCommit: d.TargetCommit,
|
||||
AdjustedRange: lsifstore.Range{
|
||||
Start: lsifstore.Position(d.TargetRange.Start),
|
||||
End: lsifstore.Position(d.TargetRange.End),
|
||||
},
|
||||
}
|
||||
definitions = append(definitions, def)
|
||||
}
|
||||
|
||||
references := make([]AdjustedLocation, 0, len(r.References))
|
||||
for _, d := range r.References {
|
||||
ref := AdjustedLocation{
|
||||
Dump: store.Dump(d.Dump),
|
||||
Path: d.Path,
|
||||
AdjustedCommit: d.TargetCommit,
|
||||
AdjustedRange: lsifstore.Range{
|
||||
Start: lsifstore.Position(d.TargetRange.Start),
|
||||
End: lsifstore.Position(d.TargetRange.End),
|
||||
},
|
||||
}
|
||||
references = append(references, ref)
|
||||
}
|
||||
|
||||
implementations := make([]AdjustedLocation, 0, len(r.Implementations))
|
||||
for _, d := range r.Implementations {
|
||||
impl := AdjustedLocation{
|
||||
Dump: store.Dump(d.Dump),
|
||||
Path: d.Path,
|
||||
AdjustedCommit: d.TargetCommit,
|
||||
AdjustedRange: lsifstore.Range{
|
||||
Start: lsifstore.Position(d.TargetRange.Start),
|
||||
End: lsifstore.Position(d.TargetRange.End),
|
||||
},
|
||||
}
|
||||
implementations = append(implementations, impl)
|
||||
}
|
||||
|
||||
adj := AdjustedCodeIntelligenceRange{
|
||||
Range: lsifstore.Range{
|
||||
Start: lsifstore.Position(r.Range.Start),
|
||||
End: lsifstore.Position(r.Range.End),
|
||||
},
|
||||
Definitions: definitions,
|
||||
References: references,
|
||||
Implementations: implementations,
|
||||
HoverText: r.HoverText,
|
||||
}
|
||||
|
||||
adjustedRange = append(adjustedRange, adj)
|
||||
}
|
||||
|
||||
return adjustedRange
|
||||
}
|
||||
|
||||
func uploadLocationToAdjustedLocations(location []shared.UploadLocation) []AdjustedLocation {
|
||||
uploadLocation := make([]AdjustedLocation, 0, len(location))
|
||||
for _, loc := range location {
|
||||
dump := store.Dump(loc.Dump)
|
||||
adjustedRange := lsifstore.Range{
|
||||
Start: lsifstore.Position{
|
||||
Line: loc.TargetRange.Start.Line,
|
||||
Character: loc.TargetRange.Start.Character,
|
||||
},
|
||||
End: lsifstore.Position{
|
||||
Line: loc.TargetRange.End.Line,
|
||||
Character: loc.TargetRange.End.Character,
|
||||
},
|
||||
}
|
||||
|
||||
uploadLocation = append(uploadLocation, AdjustedLocation{
|
||||
Dump: dump,
|
||||
Path: loc.Path,
|
||||
AdjustedCommit: loc.TargetCommit,
|
||||
AdjustedRange: adjustedRange,
|
||||
})
|
||||
}
|
||||
|
||||
return uploadLocation
|
||||
}
|
||||
|
||||
func sharedPoliciesUploadsToStoreUpload(dump store.Upload) policiesShared.Upload {
|
||||
return policiesShared.Upload{
|
||||
ID: dump.ID,
|
||||
Commit: dump.Commit,
|
||||
Root: dump.Root,
|
||||
VisibleAtTip: dump.VisibleAtTip,
|
||||
UploadedAt: dump.UploadedAt,
|
||||
State: dump.State,
|
||||
FailureMessage: dump.FailureMessage,
|
||||
StartedAt: dump.StartedAt,
|
||||
FinishedAt: dump.FinishedAt,
|
||||
ProcessAfter: dump.ProcessAfter,
|
||||
NumResets: dump.NumResets,
|
||||
NumFailures: dump.NumFailures,
|
||||
RepositoryID: dump.RepositoryID,
|
||||
RepositoryName: dump.RepositoryName,
|
||||
Indexer: dump.Indexer,
|
||||
IndexerVersion: dump.IndexerVersion,
|
||||
NumParts: 0,
|
||||
UploadedParts: []int{},
|
||||
UploadSize: nil,
|
||||
Rank: nil,
|
||||
AssociatedIndexID: dump.AssociatedIndexID,
|
||||
}
|
||||
}
|
||||
|
||||
func sharedRetentionPolicyToStoreRetentionPolicy(policy []policiesShared.RetentionPolicyMatchCandidate) []RetentionPolicyMatchCandidate {
|
||||
retentionPolicy := make([]RetentionPolicyMatchCandidate, 0, len(policy))
|
||||
for _, p := range policy {
|
||||
r := RetentionPolicyMatchCandidate{
|
||||
Matched: p.Matched,
|
||||
ProtectingCommits: p.ProtectingCommits,
|
||||
}
|
||||
if p.ConfigurationPolicy != nil {
|
||||
r.ConfigurationPolicy = &store.ConfigurationPolicy{
|
||||
ID: p.ID,
|
||||
RepositoryID: p.RepositoryID,
|
||||
RepositoryPatterns: p.RepositoryPatterns,
|
||||
Name: p.Name,
|
||||
Type: store.GitObjectType(p.Type),
|
||||
Pattern: p.Pattern,
|
||||
Protected: p.Protected,
|
||||
RetentionEnabled: p.RetentionEnabled,
|
||||
RetentionDuration: p.RetentionDuration,
|
||||
RetainIntermediateCommits: p.RetainIntermediateCommits,
|
||||
IndexingEnabled: p.IndexingEnabled,
|
||||
IndexCommitMaxAge: p.IndexCommitMaxAge,
|
||||
IndexIntermediateCommits: p.IndexIntermediateCommits,
|
||||
}
|
||||
}
|
||||
retentionPolicy = append(retentionPolicy, r)
|
||||
}
|
||||
|
||||
return retentionPolicy
|
||||
}
|
||||
|
||||
func sharedDumpToDbstoreUpload(dump shared.Dump) store.Upload {
|
||||
return store.Upload{
|
||||
ID: dump.ID,
|
||||
Commit: dump.Commit,
|
||||
Root: dump.Root,
|
||||
VisibleAtTip: dump.VisibleAtTip,
|
||||
UploadedAt: dump.UploadedAt,
|
||||
State: dump.State,
|
||||
FailureMessage: dump.FailureMessage,
|
||||
StartedAt: dump.StartedAt,
|
||||
FinishedAt: dump.FinishedAt,
|
||||
ProcessAfter: dump.ProcessAfter,
|
||||
NumResets: dump.NumResets,
|
||||
NumFailures: dump.NumFailures,
|
||||
RepositoryID: dump.RepositoryID,
|
||||
RepositoryName: dump.RepositoryName,
|
||||
Indexer: dump.Indexer,
|
||||
IndexerVersion: dump.IndexerVersion,
|
||||
NumParts: 0,
|
||||
UploadedParts: []int{},
|
||||
UploadSize: nil,
|
||||
Rank: nil,
|
||||
AssociatedIndexID: dump.AssociatedIndexID,
|
||||
}
|
||||
}
|
||||
|
||||
func sharedDiagnosticAtUploadToAdjustedDiagnostic(shared []shared.DiagnosticAtUpload) []AdjustedDiagnostic {
|
||||
adjustedDiagnostics := make([]AdjustedDiagnostic, 0, len(shared))
|
||||
for _, diag := range shared {
|
||||
diagnosticData := precise.DiagnosticData{
|
||||
Severity: diag.Severity,
|
||||
Code: diag.Code,
|
||||
Message: diag.Message,
|
||||
Source: diag.Source,
|
||||
StartLine: diag.StartLine,
|
||||
StartCharacter: diag.StartCharacter,
|
||||
EndLine: diag.EndLine,
|
||||
EndCharacter: diag.EndCharacter,
|
||||
}
|
||||
lsifDiag := lsifstore.Diagnostic{
|
||||
DiagnosticData: diagnosticData,
|
||||
DumpID: diag.DumpID,
|
||||
Path: diag.Path,
|
||||
}
|
||||
|
||||
adjusted := AdjustedDiagnostic{
|
||||
Diagnostic: lsifDiag,
|
||||
Dump: store.Dump(diag.Dump),
|
||||
AdjustedCommit: diag.AdjustedCommit,
|
||||
AdjustedRange: lsifstore.Range{
|
||||
Start: lsifstore.Position(diag.AdjustedRange.Start),
|
||||
End: lsifstore.Position(diag.AdjustedRange.End),
|
||||
},
|
||||
}
|
||||
adjustedDiagnostics = append(adjustedDiagnostics, adjusted)
|
||||
}
|
||||
return adjustedDiagnostics
|
||||
}
|
||||
|
||||
func convertSharedIndexToDBStoreIndex(index autoindexingShared.Index) store.Index {
|
||||
dockerSteps := make([]store.DockerStep, 0, len(index.DockerSteps))
|
||||
for _, step := range index.DockerSteps {
|
||||
dockerSteps = append(dockerSteps, store.DockerStep(step))
|
||||
}
|
||||
|
||||
executionLogs := make([]workerutil.ExecutionLogEntry, 0, len(index.ExecutionLogs))
|
||||
for _, log := range index.ExecutionLogs {
|
||||
executionLogs = append(executionLogs, workerutil.ExecutionLogEntry(log))
|
||||
}
|
||||
|
||||
return store.Index{
|
||||
ID: index.ID,
|
||||
Commit: index.Commit,
|
||||
QueuedAt: index.QueuedAt,
|
||||
State: index.State,
|
||||
FailureMessage: index.FailureMessage,
|
||||
StartedAt: index.StartedAt,
|
||||
FinishedAt: index.FinishedAt,
|
||||
ProcessAfter: index.ProcessAfter,
|
||||
NumResets: index.NumResets,
|
||||
NumFailures: index.NumFailures,
|
||||
RepositoryID: index.RepositoryID,
|
||||
LocalSteps: index.LocalSteps,
|
||||
RepositoryName: index.RepositoryName,
|
||||
DockerSteps: dockerSteps,
|
||||
Root: index.Root,
|
||||
Indexer: index.Indexer,
|
||||
IndexerArgs: index.IndexerArgs,
|
||||
Outfile: index.Outfile,
|
||||
ExecutionLogs: executionLogs,
|
||||
Rank: index.Rank,
|
||||
AssociatedUploadID: index.AssociatedUploadID,
|
||||
}
|
||||
}
|
||||
|
||||
func convertSharedIndexesWithRepositoryNamespaceToDBStoreIndexesWithRepositoryNamespace(shared autoindexingShared.IndexesWithRepositoryNamespace) dbstore.IndexesWithRepositoryNamespace {
|
||||
indexes := make([]dbstore.Index, 0, len(shared.Indexes))
|
||||
for _, index := range shared.Indexes {
|
||||
indexes = append(indexes, convertSharedIndexToDBStoreIndex(index))
|
||||
}
|
||||
|
||||
return dbstore.IndexesWithRepositoryNamespace{
|
||||
Root: shared.Root,
|
||||
Indexer: shared.Indexer,
|
||||
Indexes: indexes,
|
||||
}
|
||||
}
|
||||
|
||||
func convertSharedUploadsToDBStoreUploads(u uploadsShared.Upload) store.Upload {
|
||||
return store.Upload{
|
||||
ID: u.ID,
|
||||
Commit: u.Commit,
|
||||
Root: u.Root,
|
||||
VisibleAtTip: u.VisibleAtTip,
|
||||
UploadedAt: u.UploadedAt,
|
||||
State: u.State,
|
||||
FailureMessage: u.FailureMessage,
|
||||
StartedAt: u.StartedAt,
|
||||
FinishedAt: u.FinishedAt,
|
||||
ProcessAfter: u.ProcessAfter,
|
||||
NumResets: u.NumResets,
|
||||
NumFailures: u.NumFailures,
|
||||
RepositoryID: u.RepositoryID,
|
||||
RepositoryName: u.RepositoryName,
|
||||
Indexer: u.Indexer,
|
||||
IndexerVersion: u.IndexerVersion,
|
||||
NumParts: u.NumParts,
|
||||
UploadedParts: u.UploadedParts,
|
||||
UploadSize: u.UploadSize,
|
||||
UncompressedSize: u.UncompressedSize,
|
||||
Rank: u.Rank,
|
||||
AssociatedIndexID: u.AssociatedIndexID,
|
||||
}
|
||||
}
|
||||
|
||||
func convertSharedUploadsListToDBStoreUploadsList(u []uploadsShared.Upload) []store.Upload {
|
||||
uploads := make([]store.Upload, 0, len(u))
|
||||
for _, upload := range u {
|
||||
uploads = append(uploads, convertSharedUploadsToDBStoreUploads(upload))
|
||||
}
|
||||
return uploads
|
||||
}
|
||||
@ -1,54 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestDerefString(t *testing.T) {
|
||||
expected := "foo"
|
||||
|
||||
if val := derefString(nil, expected); val != expected {
|
||||
t.Errorf("unexpected value. want=%s have=%s", expected, val)
|
||||
}
|
||||
if val := derefString(&expected, ""); val != expected {
|
||||
t.Errorf("unexpected value. want=%s have=%s", expected, val)
|
||||
}
|
||||
if val := derefString(&expected, expected); val != expected {
|
||||
t.Errorf("unexpected value. want=%s have=%s", expected, val)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDerefInt32(t *testing.T) {
|
||||
expected := 42
|
||||
expected32 := int32(expected)
|
||||
|
||||
if val := derefInt32(nil, expected); val != expected {
|
||||
t.Errorf("unexpected value. want=%d have=%d", expected, val)
|
||||
}
|
||||
if val := derefInt32(&expected32, expected); val != expected {
|
||||
t.Errorf("unexpected value. want=%d have=%d", expected, val)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDerefBool(t *testing.T) {
|
||||
if val := derefBool(nil, true); !val {
|
||||
t.Errorf("unexpected value. want=%v have=%v", true, val)
|
||||
}
|
||||
if val := derefBool(nil, false); val {
|
||||
t.Errorf("unexpected value. want=%v have=%v", false, val)
|
||||
}
|
||||
|
||||
pVal := true
|
||||
if val := derefBool(&pVal, true); !val {
|
||||
t.Errorf("unexpected value. want=%v have=%v", true, val)
|
||||
}
|
||||
if val := derefBool(&pVal, false); !val {
|
||||
t.Errorf("unexpected value. want=%v have=%v", false, val)
|
||||
}
|
||||
|
||||
pVal = false
|
||||
if val := derefBool(&pVal, true); val {
|
||||
t.Errorf("unexpected value. want=%v have=%v", true, val)
|
||||
}
|
||||
if val := derefBool(&pVal, false); val {
|
||||
t.Errorf("unexpected value. want=%v have=%v", false, val)
|
||||
}
|
||||
}
|
||||
@ -1,59 +0,0 @@
|
||||
package resolvers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
autoindexingShared "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared"
|
||||
autoindexinggraphql "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/transport/graphql"
|
||||
codenavgraphql "github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/transport/graphql"
|
||||
policiesgraphql "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/transport/graphql"
|
||||
uploadsShared "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared"
|
||||
uploadsgraphql "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/transport/graphql"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/codeintel/autoindex/config"
|
||||
)
|
||||
|
||||
type DBStore interface {
|
||||
RequestLanguageSupport(ctx context.Context, userID int, language string) error
|
||||
LanguagesRequestedBy(ctx context.Context, userID int) ([]string, error)
|
||||
}
|
||||
|
||||
type CodeNavResolver interface {
|
||||
GetSupportedByCtags(ctx context.Context, filepath string, repoName api.RepoName) (bool, string, error)
|
||||
SetRequestLanguageSupport(ctx context.Context, userID int, language string) (err error)
|
||||
GetLanguagesRequestedBy(ctx context.Context, userID int) (_ []string, err error)
|
||||
GitBlobLSIFDataResolverFactory(ctx context.Context, repo *types.Repo, commit, path, toolName string, exactPath bool) (_ codenavgraphql.GitBlobLSIFDataResolver, err error)
|
||||
}
|
||||
|
||||
type PoliciesResolver interface {
|
||||
PolicyResolverFactory(ctx context.Context) (_ policiesgraphql.PolicyResolver, err error)
|
||||
}
|
||||
|
||||
type AutoIndexingResolver interface {
|
||||
GetIndexByID(ctx context.Context, id int) (_ autoindexingShared.Index, _ bool, err error)
|
||||
GetIndexesByIDs(ctx context.Context, ids ...int) (_ []autoindexingShared.Index, err error)
|
||||
GetRecentIndexesSummary(ctx context.Context, repositoryID int) (summaries []autoindexingShared.IndexesWithRepositoryNamespace, err error)
|
||||
GetLastIndexScanForRepository(ctx context.Context, repositoryID int) (_ *time.Time, err error)
|
||||
DeleteIndexByID(ctx context.Context, id int) (err error)
|
||||
QueueAutoIndexJobsForRepo(ctx context.Context, repositoryID int, rev, configuration string) ([]autoindexingShared.Index, error)
|
||||
|
||||
GetIndexConfiguration(ctx context.Context, repositoryID int) ([]byte, bool, error) // GetIndexConfigurationByRepositoryID
|
||||
InferedIndexConfiguration(ctx context.Context, repositoryID int, commit string) (*config.IndexConfiguration, bool, error) // in the service InferIndexConfiguration first return
|
||||
InferedIndexConfigurationHints(ctx context.Context, repositoryID int, commit string) ([]config.IndexJobHint, error) // in the service InferIndexConfiguration second return
|
||||
UpdateIndexConfigurationByRepositoryID(ctx context.Context, repositoryID int, configuration string) error // simple dbstore
|
||||
|
||||
IndexConnectionResolverFromFactory(opts autoindexingShared.GetIndexesOptions) *autoindexinggraphql.IndexesResolver
|
||||
}
|
||||
|
||||
type UploadsResolver interface {
|
||||
GetUploadsByIDs(ctx context.Context, ids ...int) (_ []uploadsShared.Upload, err error)
|
||||
GetUploadDocumentsForPath(ctx context.Context, bundleID int, pathPattern string) ([]string, int, error)
|
||||
GetRecentUploadsSummary(ctx context.Context, repositoryID int) (upload []uploadsShared.UploadsWithRepositoryNamespace, err error)
|
||||
GetLastUploadRetentionScanForRepository(ctx context.Context, repositoryID int) (_ *time.Time, err error)
|
||||
DeleteUploadByID(ctx context.Context, id int) (_ bool, err error)
|
||||
GetAuditLogsForUpload(ctx context.Context, uploadID int) (_ []uploadsShared.UploadLog, err error)
|
||||
UploadsConnectionResolverFromFactory(opts uploadsShared.GetUploadsOptions) *uploadsgraphql.UploadsResolver
|
||||
CommitGraphResolverFromFactory(ctx context.Context, repositoryID int) *uploadsgraphql.CommitGraphResolver
|
||||
}
|
||||
@ -1,618 +0,0 @@
|
||||
// Code generated by go-mockgen 1.3.4; DO NOT EDIT.
|
||||
//
|
||||
// This file was generated by running `sg generate` (or `go-mockgen`) at the root of
|
||||
// this repository. To add additional mocks to this or another package, add a new entry
|
||||
// to the mockgen.yaml file in the root of this repository.
|
||||
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
resolvers "github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/codeintel/resolvers"
|
||||
graphql "github.com/sourcegraph/sourcegraph/internal/services/executors/transport/graphql"
|
||||
)
|
||||
|
||||
// MockResolver is a mock implementation of the Resolver interface (from the
|
||||
// package
|
||||
// github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/codeintel/resolvers)
|
||||
// used for unit testing.
|
||||
type MockResolver struct {
|
||||
// AutoIndexingResolverFunc is an instance of a mock function object
|
||||
// controlling the behavior of the method AutoIndexingResolver.
|
||||
AutoIndexingResolverFunc *ResolverAutoIndexingResolverFunc
|
||||
// CodeNavResolverFunc is an instance of a mock function object
|
||||
// controlling the behavior of the method CodeNavResolver.
|
||||
CodeNavResolverFunc *ResolverCodeNavResolverFunc
|
||||
// ExecutorResolverFunc is an instance of a mock function object
|
||||
// controlling the behavior of the method ExecutorResolver.
|
||||
ExecutorResolverFunc *ResolverExecutorResolverFunc
|
||||
// PoliciesResolverFunc is an instance of a mock function object
|
||||
// controlling the behavior of the method PoliciesResolver.
|
||||
PoliciesResolverFunc *ResolverPoliciesResolverFunc
|
||||
// UploadsResolverFunc is an instance of a mock function object
|
||||
// controlling the behavior of the method UploadsResolver.
|
||||
UploadsResolverFunc *ResolverUploadsResolverFunc
|
||||
}
|
||||
|
||||
// NewMockResolver creates a new mock of the Resolver interface. All methods
|
||||
// return zero values for all results, unless overwritten.
|
||||
func NewMockResolver() *MockResolver {
|
||||
return &MockResolver{
|
||||
AutoIndexingResolverFunc: &ResolverAutoIndexingResolverFunc{
|
||||
defaultHook: func() (r0 resolvers.AutoIndexingResolver) {
|
||||
return
|
||||
},
|
||||
},
|
||||
CodeNavResolverFunc: &ResolverCodeNavResolverFunc{
|
||||
defaultHook: func() (r0 resolvers.CodeNavResolver) {
|
||||
return
|
||||
},
|
||||
},
|
||||
ExecutorResolverFunc: &ResolverExecutorResolverFunc{
|
||||
defaultHook: func() (r0 graphql.Resolver) {
|
||||
return
|
||||
},
|
||||
},
|
||||
PoliciesResolverFunc: &ResolverPoliciesResolverFunc{
|
||||
defaultHook: func() (r0 resolvers.PoliciesResolver) {
|
||||
return
|
||||
},
|
||||
},
|
||||
UploadsResolverFunc: &ResolverUploadsResolverFunc{
|
||||
defaultHook: func() (r0 resolvers.UploadsResolver) {
|
||||
return
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// NewStrictMockResolver creates a new mock of the Resolver interface. All
|
||||
// methods panic on invocation, unless overwritten.
|
||||
func NewStrictMockResolver() *MockResolver {
|
||||
return &MockResolver{
|
||||
AutoIndexingResolverFunc: &ResolverAutoIndexingResolverFunc{
|
||||
defaultHook: func() resolvers.AutoIndexingResolver {
|
||||
panic("unexpected invocation of MockResolver.AutoIndexingResolver")
|
||||
},
|
||||
},
|
||||
CodeNavResolverFunc: &ResolverCodeNavResolverFunc{
|
||||
defaultHook: func() resolvers.CodeNavResolver {
|
||||
panic("unexpected invocation of MockResolver.CodeNavResolver")
|
||||
},
|
||||
},
|
||||
ExecutorResolverFunc: &ResolverExecutorResolverFunc{
|
||||
defaultHook: func() graphql.Resolver {
|
||||
panic("unexpected invocation of MockResolver.ExecutorResolver")
|
||||
},
|
||||
},
|
||||
PoliciesResolverFunc: &ResolverPoliciesResolverFunc{
|
||||
defaultHook: func() resolvers.PoliciesResolver {
|
||||
panic("unexpected invocation of MockResolver.PoliciesResolver")
|
||||
},
|
||||
},
|
||||
UploadsResolverFunc: &ResolverUploadsResolverFunc{
|
||||
defaultHook: func() resolvers.UploadsResolver {
|
||||
panic("unexpected invocation of MockResolver.UploadsResolver")
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// NewMockResolverFrom creates a new mock of the MockResolver interface. All
|
||||
// methods delegate to the given implementation, unless overwritten.
|
||||
func NewMockResolverFrom(i resolvers.Resolver) *MockResolver {
|
||||
return &MockResolver{
|
||||
AutoIndexingResolverFunc: &ResolverAutoIndexingResolverFunc{
|
||||
defaultHook: i.AutoIndexingResolver,
|
||||
},
|
||||
CodeNavResolverFunc: &ResolverCodeNavResolverFunc{
|
||||
defaultHook: i.CodeNavResolver,
|
||||
},
|
||||
ExecutorResolverFunc: &ResolverExecutorResolverFunc{
|
||||
defaultHook: i.ExecutorResolver,
|
||||
},
|
||||
PoliciesResolverFunc: &ResolverPoliciesResolverFunc{
|
||||
defaultHook: i.PoliciesResolver,
|
||||
},
|
||||
UploadsResolverFunc: &ResolverUploadsResolverFunc{
|
||||
defaultHook: i.UploadsResolver,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// ResolverAutoIndexingResolverFunc describes the behavior when the
|
||||
// AutoIndexingResolver method of the parent MockResolver instance is
|
||||
// invoked.
|
||||
type ResolverAutoIndexingResolverFunc struct {
|
||||
defaultHook func() resolvers.AutoIndexingResolver
|
||||
hooks []func() resolvers.AutoIndexingResolver
|
||||
history []ResolverAutoIndexingResolverFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// AutoIndexingResolver delegates to the next hook function in the queue and
|
||||
// stores the parameter and result values of this invocation.
|
||||
func (m *MockResolver) AutoIndexingResolver() resolvers.AutoIndexingResolver {
|
||||
r0 := m.AutoIndexingResolverFunc.nextHook()()
|
||||
m.AutoIndexingResolverFunc.appendCall(ResolverAutoIndexingResolverFuncCall{r0})
|
||||
return r0
|
||||
}
|
||||
|
||||
// SetDefaultHook sets function that is called when the AutoIndexingResolver
|
||||
// method of the parent MockResolver instance is invoked and the hook queue
|
||||
// is empty.
|
||||
func (f *ResolverAutoIndexingResolverFunc) SetDefaultHook(hook func() resolvers.AutoIndexingResolver) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
// PushHook adds a function to the end of hook queue. Each invocation of the
|
||||
// AutoIndexingResolver method of the parent MockResolver instance invokes
|
||||
// the hook at the front of the queue and discards it. After the queue is
|
||||
// empty, the default hook function is invoked for any future action.
|
||||
func (f *ResolverAutoIndexingResolverFunc) PushHook(hook func() resolvers.AutoIndexingResolver) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
}
|
||||
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *ResolverAutoIndexingResolverFunc) SetDefaultReturn(r0 resolvers.AutoIndexingResolver) {
|
||||
f.SetDefaultHook(func() resolvers.AutoIndexingResolver {
|
||||
return r0
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *ResolverAutoIndexingResolverFunc) PushReturn(r0 resolvers.AutoIndexingResolver) {
|
||||
f.PushHook(func() resolvers.AutoIndexingResolver {
|
||||
return r0
|
||||
})
|
||||
}
|
||||
|
||||
func (f *ResolverAutoIndexingResolverFunc) nextHook() func() resolvers.AutoIndexingResolver {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
if len(f.hooks) == 0 {
|
||||
return f.defaultHook
|
||||
}
|
||||
|
||||
hook := f.hooks[0]
|
||||
f.hooks = f.hooks[1:]
|
||||
return hook
|
||||
}
|
||||
|
||||
func (f *ResolverAutoIndexingResolverFunc) appendCall(r0 ResolverAutoIndexingResolverFuncCall) {
|
||||
f.mutex.Lock()
|
||||
f.history = append(f.history, r0)
|
||||
f.mutex.Unlock()
|
||||
}
|
||||
|
||||
// History returns a sequence of ResolverAutoIndexingResolverFuncCall
|
||||
// objects describing the invocations of this function.
|
||||
func (f *ResolverAutoIndexingResolverFunc) History() []ResolverAutoIndexingResolverFuncCall {
|
||||
f.mutex.Lock()
|
||||
history := make([]ResolverAutoIndexingResolverFuncCall, len(f.history))
|
||||
copy(history, f.history)
|
||||
f.mutex.Unlock()
|
||||
|
||||
return history
|
||||
}
|
||||
|
||||
// ResolverAutoIndexingResolverFuncCall is an object that describes an
|
||||
// invocation of method AutoIndexingResolver on an instance of MockResolver.
|
||||
type ResolverAutoIndexingResolverFuncCall struct {
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// invocation.
|
||||
Result0 resolvers.AutoIndexingResolver
|
||||
}
|
||||
|
||||
// Args returns an interface slice containing the arguments of this
|
||||
// invocation.
|
||||
func (c ResolverAutoIndexingResolverFuncCall) Args() []interface{} {
|
||||
return []interface{}{}
|
||||
}
|
||||
|
||||
// Results returns an interface slice containing the results of this
|
||||
// invocation.
|
||||
func (c ResolverAutoIndexingResolverFuncCall) Results() []interface{} {
|
||||
return []interface{}{c.Result0}
|
||||
}
|
||||
|
||||
// ResolverCodeNavResolverFunc describes the behavior when the
|
||||
// CodeNavResolver method of the parent MockResolver instance is invoked.
|
||||
type ResolverCodeNavResolverFunc struct {
|
||||
defaultHook func() resolvers.CodeNavResolver
|
||||
hooks []func() resolvers.CodeNavResolver
|
||||
history []ResolverCodeNavResolverFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// CodeNavResolver delegates to the next hook function in the queue and
|
||||
// stores the parameter and result values of this invocation.
|
||||
func (m *MockResolver) CodeNavResolver() resolvers.CodeNavResolver {
|
||||
r0 := m.CodeNavResolverFunc.nextHook()()
|
||||
m.CodeNavResolverFunc.appendCall(ResolverCodeNavResolverFuncCall{r0})
|
||||
return r0
|
||||
}
|
||||
|
||||
// SetDefaultHook sets function that is called when the CodeNavResolver
|
||||
// method of the parent MockResolver instance is invoked and the hook queue
|
||||
// is empty.
|
||||
func (f *ResolverCodeNavResolverFunc) SetDefaultHook(hook func() resolvers.CodeNavResolver) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
// PushHook adds a function to the end of hook queue. Each invocation of the
|
||||
// CodeNavResolver method of the parent MockResolver instance invokes the
|
||||
// hook at the front of the queue and discards it. After the queue is empty,
|
||||
// the default hook function is invoked for any future action.
|
||||
func (f *ResolverCodeNavResolverFunc) PushHook(hook func() resolvers.CodeNavResolver) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
}
|
||||
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *ResolverCodeNavResolverFunc) SetDefaultReturn(r0 resolvers.CodeNavResolver) {
|
||||
f.SetDefaultHook(func() resolvers.CodeNavResolver {
|
||||
return r0
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *ResolverCodeNavResolverFunc) PushReturn(r0 resolvers.CodeNavResolver) {
|
||||
f.PushHook(func() resolvers.CodeNavResolver {
|
||||
return r0
|
||||
})
|
||||
}
|
||||
|
||||
func (f *ResolverCodeNavResolverFunc) nextHook() func() resolvers.CodeNavResolver {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
if len(f.hooks) == 0 {
|
||||
return f.defaultHook
|
||||
}
|
||||
|
||||
hook := f.hooks[0]
|
||||
f.hooks = f.hooks[1:]
|
||||
return hook
|
||||
}
|
||||
|
||||
func (f *ResolverCodeNavResolverFunc) appendCall(r0 ResolverCodeNavResolverFuncCall) {
|
||||
f.mutex.Lock()
|
||||
f.history = append(f.history, r0)
|
||||
f.mutex.Unlock()
|
||||
}
|
||||
|
||||
// History returns a sequence of ResolverCodeNavResolverFuncCall objects
|
||||
// describing the invocations of this function.
|
||||
func (f *ResolverCodeNavResolverFunc) History() []ResolverCodeNavResolverFuncCall {
|
||||
f.mutex.Lock()
|
||||
history := make([]ResolverCodeNavResolverFuncCall, len(f.history))
|
||||
copy(history, f.history)
|
||||
f.mutex.Unlock()
|
||||
|
||||
return history
|
||||
}
|
||||
|
||||
// ResolverCodeNavResolverFuncCall is an object that describes an invocation
|
||||
// of method CodeNavResolver on an instance of MockResolver.
|
||||
type ResolverCodeNavResolverFuncCall struct {
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// invocation.
|
||||
Result0 resolvers.CodeNavResolver
|
||||
}
|
||||
|
||||
// Args returns an interface slice containing the arguments of this
|
||||
// invocation.
|
||||
func (c ResolverCodeNavResolverFuncCall) Args() []interface{} {
|
||||
return []interface{}{}
|
||||
}
|
||||
|
||||
// Results returns an interface slice containing the results of this
|
||||
// invocation.
|
||||
func (c ResolverCodeNavResolverFuncCall) Results() []interface{} {
|
||||
return []interface{}{c.Result0}
|
||||
}
|
||||
|
||||
// ResolverExecutorResolverFunc describes the behavior when the
|
||||
// ExecutorResolver method of the parent MockResolver instance is invoked.
|
||||
type ResolverExecutorResolverFunc struct {
|
||||
defaultHook func() graphql.Resolver
|
||||
hooks []func() graphql.Resolver
|
||||
history []ResolverExecutorResolverFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// ExecutorResolver delegates to the next hook function in the queue and
|
||||
// stores the parameter and result values of this invocation.
|
||||
func (m *MockResolver) ExecutorResolver() graphql.Resolver {
|
||||
r0 := m.ExecutorResolverFunc.nextHook()()
|
||||
m.ExecutorResolverFunc.appendCall(ResolverExecutorResolverFuncCall{r0})
|
||||
return r0
|
||||
}
|
||||
|
||||
// SetDefaultHook sets function that is called when the ExecutorResolver
|
||||
// method of the parent MockResolver instance is invoked and the hook queue
|
||||
// is empty.
|
||||
func (f *ResolverExecutorResolverFunc) SetDefaultHook(hook func() graphql.Resolver) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
// PushHook adds a function to the end of hook queue. Each invocation of the
|
||||
// ExecutorResolver method of the parent MockResolver instance invokes the
|
||||
// hook at the front of the queue and discards it. After the queue is empty,
|
||||
// the default hook function is invoked for any future action.
|
||||
func (f *ResolverExecutorResolverFunc) PushHook(hook func() graphql.Resolver) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
}
|
||||
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *ResolverExecutorResolverFunc) SetDefaultReturn(r0 graphql.Resolver) {
|
||||
f.SetDefaultHook(func() graphql.Resolver {
|
||||
return r0
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *ResolverExecutorResolverFunc) PushReturn(r0 graphql.Resolver) {
|
||||
f.PushHook(func() graphql.Resolver {
|
||||
return r0
|
||||
})
|
||||
}
|
||||
|
||||
func (f *ResolverExecutorResolverFunc) nextHook() func() graphql.Resolver {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
if len(f.hooks) == 0 {
|
||||
return f.defaultHook
|
||||
}
|
||||
|
||||
hook := f.hooks[0]
|
||||
f.hooks = f.hooks[1:]
|
||||
return hook
|
||||
}
|
||||
|
||||
func (f *ResolverExecutorResolverFunc) appendCall(r0 ResolverExecutorResolverFuncCall) {
|
||||
f.mutex.Lock()
|
||||
f.history = append(f.history, r0)
|
||||
f.mutex.Unlock()
|
||||
}
|
||||
|
||||
// History returns a sequence of ResolverExecutorResolverFuncCall objects
|
||||
// describing the invocations of this function.
|
||||
func (f *ResolverExecutorResolverFunc) History() []ResolverExecutorResolverFuncCall {
|
||||
f.mutex.Lock()
|
||||
history := make([]ResolverExecutorResolverFuncCall, len(f.history))
|
||||
copy(history, f.history)
|
||||
f.mutex.Unlock()
|
||||
|
||||
return history
|
||||
}
|
||||
|
||||
// ResolverExecutorResolverFuncCall is an object that describes an
|
||||
// invocation of method ExecutorResolver on an instance of MockResolver.
|
||||
type ResolverExecutorResolverFuncCall struct {
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// invocation.
|
||||
Result0 graphql.Resolver
|
||||
}
|
||||
|
||||
// Args returns an interface slice containing the arguments of this
|
||||
// invocation.
|
||||
func (c ResolverExecutorResolverFuncCall) Args() []interface{} {
|
||||
return []interface{}{}
|
||||
}
|
||||
|
||||
// Results returns an interface slice containing the results of this
|
||||
// invocation.
|
||||
func (c ResolverExecutorResolverFuncCall) Results() []interface{} {
|
||||
return []interface{}{c.Result0}
|
||||
}
|
||||
|
||||
// ResolverPoliciesResolverFunc describes the behavior when the
|
||||
// PoliciesResolver method of the parent MockResolver instance is invoked.
|
||||
type ResolverPoliciesResolverFunc struct {
|
||||
defaultHook func() resolvers.PoliciesResolver
|
||||
hooks []func() resolvers.PoliciesResolver
|
||||
history []ResolverPoliciesResolverFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// PoliciesResolver delegates to the next hook function in the queue and
|
||||
// stores the parameter and result values of this invocation.
|
||||
func (m *MockResolver) PoliciesResolver() resolvers.PoliciesResolver {
|
||||
r0 := m.PoliciesResolverFunc.nextHook()()
|
||||
m.PoliciesResolverFunc.appendCall(ResolverPoliciesResolverFuncCall{r0})
|
||||
return r0
|
||||
}
|
||||
|
||||
// SetDefaultHook sets function that is called when the PoliciesResolver
|
||||
// method of the parent MockResolver instance is invoked and the hook queue
|
||||
// is empty.
|
||||
func (f *ResolverPoliciesResolverFunc) SetDefaultHook(hook func() resolvers.PoliciesResolver) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
// PushHook adds a function to the end of hook queue. Each invocation of the
|
||||
// PoliciesResolver method of the parent MockResolver instance invokes the
|
||||
// hook at the front of the queue and discards it. After the queue is empty,
|
||||
// the default hook function is invoked for any future action.
|
||||
func (f *ResolverPoliciesResolverFunc) PushHook(hook func() resolvers.PoliciesResolver) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
}
|
||||
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *ResolverPoliciesResolverFunc) SetDefaultReturn(r0 resolvers.PoliciesResolver) {
|
||||
f.SetDefaultHook(func() resolvers.PoliciesResolver {
|
||||
return r0
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *ResolverPoliciesResolverFunc) PushReturn(r0 resolvers.PoliciesResolver) {
|
||||
f.PushHook(func() resolvers.PoliciesResolver {
|
||||
return r0
|
||||
})
|
||||
}
|
||||
|
||||
func (f *ResolverPoliciesResolverFunc) nextHook() func() resolvers.PoliciesResolver {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
if len(f.hooks) == 0 {
|
||||
return f.defaultHook
|
||||
}
|
||||
|
||||
hook := f.hooks[0]
|
||||
f.hooks = f.hooks[1:]
|
||||
return hook
|
||||
}
|
||||
|
||||
func (f *ResolverPoliciesResolverFunc) appendCall(r0 ResolverPoliciesResolverFuncCall) {
|
||||
f.mutex.Lock()
|
||||
f.history = append(f.history, r0)
|
||||
f.mutex.Unlock()
|
||||
}
|
||||
|
||||
// History returns a sequence of ResolverPoliciesResolverFuncCall objects
|
||||
// describing the invocations of this function.
|
||||
func (f *ResolverPoliciesResolverFunc) History() []ResolverPoliciesResolverFuncCall {
|
||||
f.mutex.Lock()
|
||||
history := make([]ResolverPoliciesResolverFuncCall, len(f.history))
|
||||
copy(history, f.history)
|
||||
f.mutex.Unlock()
|
||||
|
||||
return history
|
||||
}
|
||||
|
||||
// ResolverPoliciesResolverFuncCall is an object that describes an
|
||||
// invocation of method PoliciesResolver on an instance of MockResolver.
|
||||
type ResolverPoliciesResolverFuncCall struct {
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// invocation.
|
||||
Result0 resolvers.PoliciesResolver
|
||||
}
|
||||
|
||||
// Args returns an interface slice containing the arguments of this
|
||||
// invocation.
|
||||
func (c ResolverPoliciesResolverFuncCall) Args() []interface{} {
|
||||
return []interface{}{}
|
||||
}
|
||||
|
||||
// Results returns an interface slice containing the results of this
|
||||
// invocation.
|
||||
func (c ResolverPoliciesResolverFuncCall) Results() []interface{} {
|
||||
return []interface{}{c.Result0}
|
||||
}
|
||||
|
||||
// ResolverUploadsResolverFunc describes the behavior when the
|
||||
// UploadsResolver method of the parent MockResolver instance is invoked.
|
||||
type ResolverUploadsResolverFunc struct {
|
||||
defaultHook func() resolvers.UploadsResolver
|
||||
hooks []func() resolvers.UploadsResolver
|
||||
history []ResolverUploadsResolverFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// UploadsResolver delegates to the next hook function in the queue and
|
||||
// stores the parameter and result values of this invocation.
|
||||
func (m *MockResolver) UploadsResolver() resolvers.UploadsResolver {
|
||||
r0 := m.UploadsResolverFunc.nextHook()()
|
||||
m.UploadsResolverFunc.appendCall(ResolverUploadsResolverFuncCall{r0})
|
||||
return r0
|
||||
}
|
||||
|
||||
// SetDefaultHook sets function that is called when the UploadsResolver
|
||||
// method of the parent MockResolver instance is invoked and the hook queue
|
||||
// is empty.
|
||||
func (f *ResolverUploadsResolverFunc) SetDefaultHook(hook func() resolvers.UploadsResolver) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
// PushHook adds a function to the end of hook queue. Each invocation of the
|
||||
// UploadsResolver method of the parent MockResolver instance invokes the
|
||||
// hook at the front of the queue and discards it. After the queue is empty,
|
||||
// the default hook function is invoked for any future action.
|
||||
func (f *ResolverUploadsResolverFunc) PushHook(hook func() resolvers.UploadsResolver) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
}
|
||||
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *ResolverUploadsResolverFunc) SetDefaultReturn(r0 resolvers.UploadsResolver) {
|
||||
f.SetDefaultHook(func() resolvers.UploadsResolver {
|
||||
return r0
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *ResolverUploadsResolverFunc) PushReturn(r0 resolvers.UploadsResolver) {
|
||||
f.PushHook(func() resolvers.UploadsResolver {
|
||||
return r0
|
||||
})
|
||||
}
|
||||
|
||||
func (f *ResolverUploadsResolverFunc) nextHook() func() resolvers.UploadsResolver {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
if len(f.hooks) == 0 {
|
||||
return f.defaultHook
|
||||
}
|
||||
|
||||
hook := f.hooks[0]
|
||||
f.hooks = f.hooks[1:]
|
||||
return hook
|
||||
}
|
||||
|
||||
func (f *ResolverUploadsResolverFunc) appendCall(r0 ResolverUploadsResolverFuncCall) {
|
||||
f.mutex.Lock()
|
||||
f.history = append(f.history, r0)
|
||||
f.mutex.Unlock()
|
||||
}
|
||||
|
||||
// History returns a sequence of ResolverUploadsResolverFuncCall objects
|
||||
// describing the invocations of this function.
|
||||
func (f *ResolverUploadsResolverFunc) History() []ResolverUploadsResolverFuncCall {
|
||||
f.mutex.Lock()
|
||||
history := make([]ResolverUploadsResolverFuncCall, len(f.history))
|
||||
copy(history, f.history)
|
||||
f.mutex.Unlock()
|
||||
|
||||
return history
|
||||
}
|
||||
|
||||
// ResolverUploadsResolverFuncCall is an object that describes an invocation
|
||||
// of method UploadsResolver on an instance of MockResolver.
|
||||
type ResolverUploadsResolverFuncCall struct {
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// invocation.
|
||||
Result0 resolvers.UploadsResolver
|
||||
}
|
||||
|
||||
// Args returns an interface slice containing the arguments of this
|
||||
// invocation.
|
||||
func (c ResolverUploadsResolverFuncCall) Args() []interface{} {
|
||||
return []interface{}{}
|
||||
}
|
||||
|
||||
// Results returns an interface slice containing the results of this
|
||||
// invocation.
|
||||
func (c ResolverUploadsResolverFuncCall) Results() []interface{} {
|
||||
return []interface{}{c.Result0}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,291 +0,0 @@
|
||||
// Code generated by go-mockgen 1.3.4; DO NOT EDIT.
|
||||
//
|
||||
// This file was generated by running `sg generate` (or `go-mockgen`) at the root of
|
||||
// this repository. To add additional mocks to this or another package, add a new entry
|
||||
// to the mockgen.yaml file in the root of this repository.
|
||||
|
||||
package resolvers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// MockDBStore is a mock implementation of the DBStore interface (from the
|
||||
// package
|
||||
// github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/codeintel/resolvers)
|
||||
// used for unit testing.
|
||||
type MockDBStore struct {
|
||||
// LanguagesRequestedByFunc is an instance of a mock function object
|
||||
// controlling the behavior of the method LanguagesRequestedBy.
|
||||
LanguagesRequestedByFunc *DBStoreLanguagesRequestedByFunc
|
||||
// RequestLanguageSupportFunc is an instance of a mock function object
|
||||
// controlling the behavior of the method RequestLanguageSupport.
|
||||
RequestLanguageSupportFunc *DBStoreRequestLanguageSupportFunc
|
||||
}
|
||||
|
||||
// NewMockDBStore creates a new mock of the DBStore interface. All methods
|
||||
// return zero values for all results, unless overwritten.
|
||||
func NewMockDBStore() *MockDBStore {
|
||||
return &MockDBStore{
|
||||
LanguagesRequestedByFunc: &DBStoreLanguagesRequestedByFunc{
|
||||
defaultHook: func(context.Context, int) (r0 []string, r1 error) {
|
||||
return
|
||||
},
|
||||
},
|
||||
RequestLanguageSupportFunc: &DBStoreRequestLanguageSupportFunc{
|
||||
defaultHook: func(context.Context, int, string) (r0 error) {
|
||||
return
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// NewStrictMockDBStore creates a new mock of the DBStore interface. All
|
||||
// methods panic on invocation, unless overwritten.
|
||||
func NewStrictMockDBStore() *MockDBStore {
|
||||
return &MockDBStore{
|
||||
LanguagesRequestedByFunc: &DBStoreLanguagesRequestedByFunc{
|
||||
defaultHook: func(context.Context, int) ([]string, error) {
|
||||
panic("unexpected invocation of MockDBStore.LanguagesRequestedBy")
|
||||
},
|
||||
},
|
||||
RequestLanguageSupportFunc: &DBStoreRequestLanguageSupportFunc{
|
||||
defaultHook: func(context.Context, int, string) error {
|
||||
panic("unexpected invocation of MockDBStore.RequestLanguageSupport")
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// NewMockDBStoreFrom creates a new mock of the MockDBStore interface. All
|
||||
// methods delegate to the given implementation, unless overwritten.
|
||||
func NewMockDBStoreFrom(i DBStore) *MockDBStore {
|
||||
return &MockDBStore{
|
||||
LanguagesRequestedByFunc: &DBStoreLanguagesRequestedByFunc{
|
||||
defaultHook: i.LanguagesRequestedBy,
|
||||
},
|
||||
RequestLanguageSupportFunc: &DBStoreRequestLanguageSupportFunc{
|
||||
defaultHook: i.RequestLanguageSupport,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// DBStoreLanguagesRequestedByFunc describes the behavior when the
|
||||
// LanguagesRequestedBy method of the parent MockDBStore instance is
|
||||
// invoked.
|
||||
type DBStoreLanguagesRequestedByFunc struct {
|
||||
defaultHook func(context.Context, int) ([]string, error)
|
||||
hooks []func(context.Context, int) ([]string, error)
|
||||
history []DBStoreLanguagesRequestedByFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// LanguagesRequestedBy delegates to the next hook function in the queue and
|
||||
// stores the parameter and result values of this invocation.
|
||||
func (m *MockDBStore) LanguagesRequestedBy(v0 context.Context, v1 int) ([]string, error) {
|
||||
r0, r1 := m.LanguagesRequestedByFunc.nextHook()(v0, v1)
|
||||
m.LanguagesRequestedByFunc.appendCall(DBStoreLanguagesRequestedByFuncCall{v0, v1, r0, r1})
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// SetDefaultHook sets function that is called when the LanguagesRequestedBy
|
||||
// method of the parent MockDBStore instance is invoked and the hook queue
|
||||
// is empty.
|
||||
func (f *DBStoreLanguagesRequestedByFunc) SetDefaultHook(hook func(context.Context, int) ([]string, error)) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
// PushHook adds a function to the end of hook queue. Each invocation of the
|
||||
// LanguagesRequestedBy method of the parent MockDBStore instance invokes
|
||||
// the hook at the front of the queue and discards it. After the queue is
|
||||
// empty, the default hook function is invoked for any future action.
|
||||
func (f *DBStoreLanguagesRequestedByFunc) PushHook(hook func(context.Context, int) ([]string, error)) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
}
|
||||
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *DBStoreLanguagesRequestedByFunc) SetDefaultReturn(r0 []string, r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, int) ([]string, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *DBStoreLanguagesRequestedByFunc) PushReturn(r0 []string, r1 error) {
|
||||
f.PushHook(func(context.Context, int) ([]string, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
func (f *DBStoreLanguagesRequestedByFunc) nextHook() func(context.Context, int) ([]string, error) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
if len(f.hooks) == 0 {
|
||||
return f.defaultHook
|
||||
}
|
||||
|
||||
hook := f.hooks[0]
|
||||
f.hooks = f.hooks[1:]
|
||||
return hook
|
||||
}
|
||||
|
||||
func (f *DBStoreLanguagesRequestedByFunc) appendCall(r0 DBStoreLanguagesRequestedByFuncCall) {
|
||||
f.mutex.Lock()
|
||||
f.history = append(f.history, r0)
|
||||
f.mutex.Unlock()
|
||||
}
|
||||
|
||||
// History returns a sequence of DBStoreLanguagesRequestedByFuncCall objects
|
||||
// describing the invocations of this function.
|
||||
func (f *DBStoreLanguagesRequestedByFunc) History() []DBStoreLanguagesRequestedByFuncCall {
|
||||
f.mutex.Lock()
|
||||
history := make([]DBStoreLanguagesRequestedByFuncCall, len(f.history))
|
||||
copy(history, f.history)
|
||||
f.mutex.Unlock()
|
||||
|
||||
return history
|
||||
}
|
||||
|
||||
// DBStoreLanguagesRequestedByFuncCall is an object that describes an
|
||||
// invocation of method LanguagesRequestedBy on an instance of MockDBStore.
|
||||
type DBStoreLanguagesRequestedByFuncCall struct {
|
||||
// Arg0 is the value of the 1st argument passed to this method
|
||||
// invocation.
|
||||
Arg0 context.Context
|
||||
// Arg1 is the value of the 2nd argument passed to this method
|
||||
// invocation.
|
||||
Arg1 int
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// invocation.
|
||||
Result0 []string
|
||||
// Result1 is the value of the 2nd result returned from this method
|
||||
// invocation.
|
||||
Result1 error
|
||||
}
|
||||
|
||||
// Args returns an interface slice containing the arguments of this
|
||||
// invocation.
|
||||
func (c DBStoreLanguagesRequestedByFuncCall) Args() []interface{} {
|
||||
return []interface{}{c.Arg0, c.Arg1}
|
||||
}
|
||||
|
||||
// Results returns an interface slice containing the results of this
|
||||
// invocation.
|
||||
func (c DBStoreLanguagesRequestedByFuncCall) Results() []interface{} {
|
||||
return []interface{}{c.Result0, c.Result1}
|
||||
}
|
||||
|
||||
// DBStoreRequestLanguageSupportFunc describes the behavior when the
|
||||
// RequestLanguageSupport method of the parent MockDBStore instance is
|
||||
// invoked.
|
||||
type DBStoreRequestLanguageSupportFunc struct {
|
||||
defaultHook func(context.Context, int, string) error
|
||||
hooks []func(context.Context, int, string) error
|
||||
history []DBStoreRequestLanguageSupportFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// RequestLanguageSupport delegates to the next hook function in the queue
|
||||
// and stores the parameter and result values of this invocation.
|
||||
func (m *MockDBStore) RequestLanguageSupport(v0 context.Context, v1 int, v2 string) error {
|
||||
r0 := m.RequestLanguageSupportFunc.nextHook()(v0, v1, v2)
|
||||
m.RequestLanguageSupportFunc.appendCall(DBStoreRequestLanguageSupportFuncCall{v0, v1, v2, r0})
|
||||
return r0
|
||||
}
|
||||
|
||||
// SetDefaultHook sets function that is called when the
|
||||
// RequestLanguageSupport method of the parent MockDBStore instance is
|
||||
// invoked and the hook queue is empty.
|
||||
func (f *DBStoreRequestLanguageSupportFunc) SetDefaultHook(hook func(context.Context, int, string) error) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
// PushHook adds a function to the end of hook queue. Each invocation of the
|
||||
// RequestLanguageSupport method of the parent MockDBStore instance invokes
|
||||
// the hook at the front of the queue and discards it. After the queue is
|
||||
// empty, the default hook function is invoked for any future action.
|
||||
func (f *DBStoreRequestLanguageSupportFunc) PushHook(hook func(context.Context, int, string) error) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
}
|
||||
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *DBStoreRequestLanguageSupportFunc) SetDefaultReturn(r0 error) {
|
||||
f.SetDefaultHook(func(context.Context, int, string) error {
|
||||
return r0
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *DBStoreRequestLanguageSupportFunc) PushReturn(r0 error) {
|
||||
f.PushHook(func(context.Context, int, string) error {
|
||||
return r0
|
||||
})
|
||||
}
|
||||
|
||||
func (f *DBStoreRequestLanguageSupportFunc) nextHook() func(context.Context, int, string) error {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
if len(f.hooks) == 0 {
|
||||
return f.defaultHook
|
||||
}
|
||||
|
||||
hook := f.hooks[0]
|
||||
f.hooks = f.hooks[1:]
|
||||
return hook
|
||||
}
|
||||
|
||||
func (f *DBStoreRequestLanguageSupportFunc) appendCall(r0 DBStoreRequestLanguageSupportFuncCall) {
|
||||
f.mutex.Lock()
|
||||
f.history = append(f.history, r0)
|
||||
f.mutex.Unlock()
|
||||
}
|
||||
|
||||
// History returns a sequence of DBStoreRequestLanguageSupportFuncCall
|
||||
// objects describing the invocations of this function.
|
||||
func (f *DBStoreRequestLanguageSupportFunc) History() []DBStoreRequestLanguageSupportFuncCall {
|
||||
f.mutex.Lock()
|
||||
history := make([]DBStoreRequestLanguageSupportFuncCall, len(f.history))
|
||||
copy(history, f.history)
|
||||
f.mutex.Unlock()
|
||||
|
||||
return history
|
||||
}
|
||||
|
||||
// DBStoreRequestLanguageSupportFuncCall is an object that describes an
|
||||
// invocation of method RequestLanguageSupport on an instance of
|
||||
// MockDBStore.
|
||||
type DBStoreRequestLanguageSupportFuncCall struct {
|
||||
// Arg0 is the value of the 1st argument passed to this method
|
||||
// invocation.
|
||||
Arg0 context.Context
|
||||
// Arg1 is the value of the 2nd argument passed to this method
|
||||
// invocation.
|
||||
Arg1 int
|
||||
// Arg2 is the value of the 3rd argument passed to this method
|
||||
// invocation.
|
||||
Arg2 string
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// invocation.
|
||||
Result0 error
|
||||
}
|
||||
|
||||
// Args returns an interface slice containing the arguments of this
|
||||
// invocation.
|
||||
func (c DBStoreRequestLanguageSupportFuncCall) Args() []interface{} {
|
||||
return []interface{}{c.Arg0, c.Arg1, c.Arg2}
|
||||
}
|
||||
|
||||
// Results returns an interface slice containing the results of this
|
||||
// invocation.
|
||||
func (c DBStoreRequestLanguageSupportFuncCall) Results() []interface{} {
|
||||
return []interface{}{c.Result0}
|
||||
}
|
||||
@ -1,6 +1,10 @@
|
||||
package resolvers
|
||||
|
||||
import (
|
||||
autoindexinggraphql "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/transport/graphql"
|
||||
codenavgraphql "github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/transport/graphql"
|
||||
policiesgraphql "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/transport/graphql"
|
||||
uploadsgraphql "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/transport/graphql"
|
||||
executor "github.com/sourcegraph/sourcegraph/internal/services/executors/transport/graphql"
|
||||
)
|
||||
|
||||
@ -11,51 +15,51 @@ import (
|
||||
// by the API.
|
||||
type Resolver interface {
|
||||
ExecutorResolver() executor.Resolver
|
||||
CodeNavResolver() CodeNavResolver
|
||||
PoliciesResolver() PoliciesResolver
|
||||
AutoIndexingResolver() AutoIndexingResolver
|
||||
UploadsResolver() UploadsResolver
|
||||
CodeNavResolver() codenavgraphql.RootResolver
|
||||
PoliciesRootResolver() policiesgraphql.RootResolver
|
||||
AutoIndexingRootResolver() autoindexinggraphql.RootResolver
|
||||
UploadRootResolver() uploadsgraphql.RootResolver
|
||||
}
|
||||
|
||||
type resolver struct {
|
||||
executorResolver executor.Resolver
|
||||
codenavResolver CodeNavResolver
|
||||
policiesResolver PoliciesResolver
|
||||
autoIndexingResolver AutoIndexingResolver
|
||||
uploadsResolver UploadsResolver
|
||||
executorResolver executor.Resolver
|
||||
codenavResolver codenavgraphql.RootResolver
|
||||
policiesRootResolver policiesgraphql.RootResolver
|
||||
autoIndexingRootResolver autoindexinggraphql.RootResolver
|
||||
uploadsRootResolver uploadsgraphql.RootResolver
|
||||
}
|
||||
|
||||
// NewResolver creates a new resolver with the given services.
|
||||
func NewResolver(
|
||||
codenavResolver CodeNavResolver,
|
||||
codenavResolver codenavgraphql.RootResolver,
|
||||
executorResolver executor.Resolver,
|
||||
policiesResolver PoliciesResolver,
|
||||
autoIndexingResolver AutoIndexingResolver,
|
||||
uploadsResolver UploadsResolver,
|
||||
policiesRootResolver policiesgraphql.RootResolver,
|
||||
autoIndexingRootResolver autoindexinggraphql.RootResolver,
|
||||
uploadsRootResolver uploadsgraphql.RootResolver,
|
||||
) Resolver {
|
||||
return &resolver{
|
||||
executorResolver: executorResolver,
|
||||
codenavResolver: codenavResolver,
|
||||
policiesResolver: policiesResolver,
|
||||
autoIndexingResolver: autoIndexingResolver,
|
||||
uploadsResolver: uploadsResolver,
|
||||
executorResolver: executorResolver,
|
||||
codenavResolver: codenavResolver,
|
||||
policiesRootResolver: policiesRootResolver,
|
||||
autoIndexingRootResolver: autoIndexingRootResolver,
|
||||
uploadsRootResolver: uploadsRootResolver,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *resolver) CodeNavResolver() CodeNavResolver {
|
||||
func (r *resolver) CodeNavResolver() codenavgraphql.RootResolver {
|
||||
return r.codenavResolver
|
||||
}
|
||||
|
||||
func (r *resolver) PoliciesResolver() PoliciesResolver {
|
||||
return r.policiesResolver
|
||||
func (r *resolver) PoliciesRootResolver() policiesgraphql.RootResolver {
|
||||
return r.policiesRootResolver
|
||||
}
|
||||
|
||||
func (r *resolver) AutoIndexingResolver() AutoIndexingResolver {
|
||||
return r.autoIndexingResolver
|
||||
func (r *resolver) AutoIndexingRootResolver() autoindexinggraphql.RootResolver {
|
||||
return r.autoIndexingRootResolver
|
||||
}
|
||||
|
||||
func (r *resolver) UploadsResolver() UploadsResolver {
|
||||
return r.uploadsResolver
|
||||
func (r *resolver) UploadRootResolver() uploadsgraphql.RootResolver {
|
||||
return r.uploadsRootResolver
|
||||
}
|
||||
|
||||
func (r *resolver) ExecutorResolver() executor.Resolver {
|
||||
|
||||
@ -24,13 +24,10 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
connections "github.com/sourcegraph/sourcegraph/internal/database/connections/live"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
"github.com/sourcegraph/sourcegraph/internal/symbols"
|
||||
"github.com/sourcegraph/sourcegraph/internal/trace"
|
||||
)
|
||||
|
||||
type Services struct {
|
||||
dbStore *store.Store
|
||||
|
||||
// shared with executor queue
|
||||
InternalUploadHandler http.Handler
|
||||
ExternalUploadHandler http.Handler
|
||||
@ -73,7 +70,7 @@ func NewServices(ctx context.Context, config *Config, siteConfig conftypes.Watch
|
||||
|
||||
// Initialize services
|
||||
uploadSvc := uploads.GetService(db, codeIntelLsifStore, gitserverClient)
|
||||
codenavSvc := codenav.GetService(db, codeIntelLsifStore, uploadSvc, gitserverClient, symbols.DefaultClient)
|
||||
codenavSvc := codenav.GetService(db, codeIntelLsifStore, uploadSvc, gitserverClient)
|
||||
policySvc := policies.GetService(db, uploadSvc, gitserverClient)
|
||||
autoindexingSvc := autoindexing.GetService(db, uploadSvc, gitserverClient, repoUpdaterClient)
|
||||
|
||||
@ -85,8 +82,6 @@ func NewServices(ctx context.Context, config *Config, siteConfig conftypes.Watch
|
||||
externalUploadHandler := newUploadHandler(true)
|
||||
|
||||
return &Services{
|
||||
dbStore: dbStore,
|
||||
|
||||
InternalUploadHandler: internalUploadHandler,
|
||||
ExternalUploadHandler: externalUploadHandler,
|
||||
|
||||
|
||||
@ -7,9 +7,9 @@ import (
|
||||
"github.com/grafana/regexp"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
autoindexingShared "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared"
|
||||
policies "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/enterprise"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/stores/dbstore"
|
||||
codeinteltypes "github.com/sourcegraph/sourcegraph/internal/codeintel/types"
|
||||
"github.com/sourcegraph/sourcegraph/internal/conf"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/basestore"
|
||||
@ -70,7 +70,7 @@ type GitserverClient interface {
|
||||
}
|
||||
|
||||
type IndexEnqueuer interface {
|
||||
QueueIndexes(ctx context.Context, repositoryID int, rev, configuration string, force, bypassLimit bool) ([]autoindexingShared.Index, error)
|
||||
QueueIndexes(ctx context.Context, repositoryID int, rev, configuration string, force, bypassLimit bool) ([]codeinteltypes.Index, error)
|
||||
QueueIndexesForPackage(ctx context.Context, pkg precise.Package) error
|
||||
}
|
||||
|
||||
|
||||
@ -14,10 +14,10 @@ import (
|
||||
regexp "github.com/grafana/regexp"
|
||||
sqlf "github.com/keegancsmith/sqlf"
|
||||
api "github.com/sourcegraph/sourcegraph/internal/api"
|
||||
shared "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared"
|
||||
enterprise "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/enterprise"
|
||||
dbstore "github.com/sourcegraph/sourcegraph/internal/codeintel/stores/dbstore"
|
||||
shared1 "github.com/sourcegraph/sourcegraph/internal/codeintel/stores/shared"
|
||||
shared "github.com/sourcegraph/sourcegraph/internal/codeintel/stores/shared"
|
||||
types1 "github.com/sourcegraph/sourcegraph/internal/codeintel/types"
|
||||
database "github.com/sourcegraph/sourcegraph/internal/database"
|
||||
basestore "github.com/sourcegraph/sourcegraph/internal/database/basestore"
|
||||
protocol "github.com/sourcegraph/sourcegraph/internal/repoupdater/protocol"
|
||||
@ -1827,7 +1827,7 @@ type MockIndexEnqueuer struct {
|
||||
func NewMockIndexEnqueuer() *MockIndexEnqueuer {
|
||||
return &MockIndexEnqueuer{
|
||||
QueueIndexesFunc: &IndexEnqueuerQueueIndexesFunc{
|
||||
defaultHook: func(context.Context, int, string, string, bool, bool) (r0 []shared.Index, r1 error) {
|
||||
defaultHook: func(context.Context, int, string, string, bool, bool) (r0 []types1.Index, r1 error) {
|
||||
return
|
||||
},
|
||||
},
|
||||
@ -1844,7 +1844,7 @@ func NewMockIndexEnqueuer() *MockIndexEnqueuer {
|
||||
func NewStrictMockIndexEnqueuer() *MockIndexEnqueuer {
|
||||
return &MockIndexEnqueuer{
|
||||
QueueIndexesFunc: &IndexEnqueuerQueueIndexesFunc{
|
||||
defaultHook: func(context.Context, int, string, string, bool, bool) ([]shared.Index, error) {
|
||||
defaultHook: func(context.Context, int, string, string, bool, bool) ([]types1.Index, error) {
|
||||
panic("unexpected invocation of MockIndexEnqueuer.QueueIndexes")
|
||||
},
|
||||
},
|
||||
@ -1873,15 +1873,15 @@ func NewMockIndexEnqueuerFrom(i IndexEnqueuer) *MockIndexEnqueuer {
|
||||
// IndexEnqueuerQueueIndexesFunc describes the behavior when the
|
||||
// QueueIndexes method of the parent MockIndexEnqueuer instance is invoked.
|
||||
type IndexEnqueuerQueueIndexesFunc struct {
|
||||
defaultHook func(context.Context, int, string, string, bool, bool) ([]shared.Index, error)
|
||||
hooks []func(context.Context, int, string, string, bool, bool) ([]shared.Index, error)
|
||||
defaultHook func(context.Context, int, string, string, bool, bool) ([]types1.Index, error)
|
||||
hooks []func(context.Context, int, string, string, bool, bool) ([]types1.Index, error)
|
||||
history []IndexEnqueuerQueueIndexesFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// QueueIndexes delegates to the next hook function in the queue and stores
|
||||
// the parameter and result values of this invocation.
|
||||
func (m *MockIndexEnqueuer) QueueIndexes(v0 context.Context, v1 int, v2 string, v3 string, v4 bool, v5 bool) ([]shared.Index, error) {
|
||||
func (m *MockIndexEnqueuer) QueueIndexes(v0 context.Context, v1 int, v2 string, v3 string, v4 bool, v5 bool) ([]types1.Index, error) {
|
||||
r0, r1 := m.QueueIndexesFunc.nextHook()(v0, v1, v2, v3, v4, v5)
|
||||
m.QueueIndexesFunc.appendCall(IndexEnqueuerQueueIndexesFuncCall{v0, v1, v2, v3, v4, v5, r0, r1})
|
||||
return r0, r1
|
||||
@ -1890,7 +1890,7 @@ func (m *MockIndexEnqueuer) QueueIndexes(v0 context.Context, v1 int, v2 string,
|
||||
// SetDefaultHook sets function that is called when the QueueIndexes method
|
||||
// of the parent MockIndexEnqueuer instance is invoked and the hook queue is
|
||||
// empty.
|
||||
func (f *IndexEnqueuerQueueIndexesFunc) SetDefaultHook(hook func(context.Context, int, string, string, bool, bool) ([]shared.Index, error)) {
|
||||
func (f *IndexEnqueuerQueueIndexesFunc) SetDefaultHook(hook func(context.Context, int, string, string, bool, bool) ([]types1.Index, error)) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
@ -1898,7 +1898,7 @@ func (f *IndexEnqueuerQueueIndexesFunc) SetDefaultHook(hook func(context.Context
|
||||
// QueueIndexes method of the parent MockIndexEnqueuer instance invokes the
|
||||
// hook at the front of the queue and discards it. After the queue is empty,
|
||||
// the default hook function is invoked for any future action.
|
||||
func (f *IndexEnqueuerQueueIndexesFunc) PushHook(hook func(context.Context, int, string, string, bool, bool) ([]shared.Index, error)) {
|
||||
func (f *IndexEnqueuerQueueIndexesFunc) PushHook(hook func(context.Context, int, string, string, bool, bool) ([]types1.Index, error)) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
@ -1906,20 +1906,20 @@ func (f *IndexEnqueuerQueueIndexesFunc) PushHook(hook func(context.Context, int,
|
||||
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *IndexEnqueuerQueueIndexesFunc) SetDefaultReturn(r0 []shared.Index, r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, int, string, string, bool, bool) ([]shared.Index, error) {
|
||||
func (f *IndexEnqueuerQueueIndexesFunc) SetDefaultReturn(r0 []types1.Index, r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, int, string, string, bool, bool) ([]types1.Index, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *IndexEnqueuerQueueIndexesFunc) PushReturn(r0 []shared.Index, r1 error) {
|
||||
f.PushHook(func(context.Context, int, string, string, bool, bool) ([]shared.Index, error) {
|
||||
func (f *IndexEnqueuerQueueIndexesFunc) PushReturn(r0 []types1.Index, r1 error) {
|
||||
f.PushHook(func(context.Context, int, string, string, bool, bool) ([]types1.Index, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
func (f *IndexEnqueuerQueueIndexesFunc) nextHook() func(context.Context, int, string, string, bool, bool) ([]shared.Index, error) {
|
||||
func (f *IndexEnqueuerQueueIndexesFunc) nextHook() func(context.Context, int, string, string, bool, bool) ([]types1.Index, error) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
@ -1972,7 +1972,7 @@ type IndexEnqueuerQueueIndexesFuncCall struct {
|
||||
Arg5 bool
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// invocation.
|
||||
Result0 []shared.Index
|
||||
Result0 []types1.Index
|
||||
// Result1 is the value of the 2nd result returned from this method
|
||||
// invocation.
|
||||
Result1 error
|
||||
@ -3047,7 +3047,7 @@ func NewMockPackageReferenceScanner() *MockPackageReferenceScanner {
|
||||
},
|
||||
},
|
||||
NextFunc: &PackageReferenceScannerNextFunc{
|
||||
defaultHook: func() (r0 shared1.PackageReference, r1 bool, r2 error) {
|
||||
defaultHook: func() (r0 shared.PackageReference, r1 bool, r2 error) {
|
||||
return
|
||||
},
|
||||
},
|
||||
@ -3065,7 +3065,7 @@ func NewStrictMockPackageReferenceScanner() *MockPackageReferenceScanner {
|
||||
},
|
||||
},
|
||||
NextFunc: &PackageReferenceScannerNextFunc{
|
||||
defaultHook: func() (shared1.PackageReference, bool, error) {
|
||||
defaultHook: func() (shared.PackageReference, bool, error) {
|
||||
panic("unexpected invocation of MockPackageReferenceScanner.Next")
|
||||
},
|
||||
},
|
||||
@ -3188,15 +3188,15 @@ func (c PackageReferenceScannerCloseFuncCall) Results() []interface{} {
|
||||
// PackageReferenceScannerNextFunc describes the behavior when the Next
|
||||
// method of the parent MockPackageReferenceScanner instance is invoked.
|
||||
type PackageReferenceScannerNextFunc struct {
|
||||
defaultHook func() (shared1.PackageReference, bool, error)
|
||||
hooks []func() (shared1.PackageReference, bool, error)
|
||||
defaultHook func() (shared.PackageReference, bool, error)
|
||||
hooks []func() (shared.PackageReference, bool, error)
|
||||
history []PackageReferenceScannerNextFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// Next delegates to the next hook function in the queue and stores the
|
||||
// parameter and result values of this invocation.
|
||||
func (m *MockPackageReferenceScanner) Next() (shared1.PackageReference, bool, error) {
|
||||
func (m *MockPackageReferenceScanner) Next() (shared.PackageReference, bool, error) {
|
||||
r0, r1, r2 := m.NextFunc.nextHook()()
|
||||
m.NextFunc.appendCall(PackageReferenceScannerNextFuncCall{r0, r1, r2})
|
||||
return r0, r1, r2
|
||||
@ -3205,7 +3205,7 @@ func (m *MockPackageReferenceScanner) Next() (shared1.PackageReference, bool, er
|
||||
// SetDefaultHook sets function that is called when the Next method of the
|
||||
// parent MockPackageReferenceScanner instance is invoked and the hook queue
|
||||
// is empty.
|
||||
func (f *PackageReferenceScannerNextFunc) SetDefaultHook(hook func() (shared1.PackageReference, bool, error)) {
|
||||
func (f *PackageReferenceScannerNextFunc) SetDefaultHook(hook func() (shared.PackageReference, bool, error)) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
@ -3213,7 +3213,7 @@ func (f *PackageReferenceScannerNextFunc) SetDefaultHook(hook func() (shared1.Pa
|
||||
// Next method of the parent MockPackageReferenceScanner instance invokes
|
||||
// the hook at the front of the queue and discards it. After the queue is
|
||||
// empty, the default hook function is invoked for any future action.
|
||||
func (f *PackageReferenceScannerNextFunc) PushHook(hook func() (shared1.PackageReference, bool, error)) {
|
||||
func (f *PackageReferenceScannerNextFunc) PushHook(hook func() (shared.PackageReference, bool, error)) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
@ -3221,20 +3221,20 @@ func (f *PackageReferenceScannerNextFunc) PushHook(hook func() (shared1.PackageR
|
||||
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *PackageReferenceScannerNextFunc) SetDefaultReturn(r0 shared1.PackageReference, r1 bool, r2 error) {
|
||||
f.SetDefaultHook(func() (shared1.PackageReference, bool, error) {
|
||||
func (f *PackageReferenceScannerNextFunc) SetDefaultReturn(r0 shared.PackageReference, r1 bool, r2 error) {
|
||||
f.SetDefaultHook(func() (shared.PackageReference, bool, error) {
|
||||
return r0, r1, r2
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *PackageReferenceScannerNextFunc) PushReturn(r0 shared1.PackageReference, r1 bool, r2 error) {
|
||||
f.PushHook(func() (shared1.PackageReference, bool, error) {
|
||||
func (f *PackageReferenceScannerNextFunc) PushReturn(r0 shared.PackageReference, r1 bool, r2 error) {
|
||||
f.PushHook(func() (shared.PackageReference, bool, error) {
|
||||
return r0, r1, r2
|
||||
})
|
||||
}
|
||||
|
||||
func (f *PackageReferenceScannerNextFunc) nextHook() func() (shared1.PackageReference, bool, error) {
|
||||
func (f *PackageReferenceScannerNextFunc) nextHook() func() (shared.PackageReference, bool, error) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
@ -3269,7 +3269,7 @@ func (f *PackageReferenceScannerNextFunc) History() []PackageReferenceScannerNex
|
||||
type PackageReferenceScannerNextFuncCall struct {
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// invocation.
|
||||
Result0 shared1.PackageReference
|
||||
Result0 shared.PackageReference
|
||||
// Result1 is the value of the 2nd result returned from this method
|
||||
// invocation.
|
||||
Result1 bool
|
||||
|
||||
@ -5,15 +5,15 @@ import (
|
||||
"time"
|
||||
|
||||
policies "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/enterprise"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/policies/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/types"
|
||||
)
|
||||
|
||||
type PolicyMatcher interface {
|
||||
CommitsDescribedByPolicyInternal(ctx context.Context, repositoryID int, policies []shared.ConfigurationPolicy, now time.Time, filterCommits ...string) (map[string][]policies.PolicyMatch, error)
|
||||
CommitsDescribedByPolicyInternal(ctx context.Context, repositoryID int, policies []types.ConfigurationPolicy, now time.Time, filterCommits ...string) (map[string][]policies.PolicyMatch, error)
|
||||
}
|
||||
|
||||
type PolicyService interface {
|
||||
GetConfigurationPolicies(ctx context.Context, opts shared.GetConfigurationPoliciesOptions) ([]shared.ConfigurationPolicy, int, error)
|
||||
GetConfigurationPolicies(ctx context.Context, opts types.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error)
|
||||
}
|
||||
|
||||
type UploadService interface {
|
||||
|
||||
@ -12,7 +12,7 @@ import (
|
||||
"time"
|
||||
|
||||
enterprise "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/enterprise"
|
||||
shared "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/shared"
|
||||
types "github.com/sourcegraph/sourcegraph/internal/codeintel/types"
|
||||
)
|
||||
|
||||
// MockPolicyMatcher is a mock implementation of the PolicyMatcher interface
|
||||
@ -31,7 +31,7 @@ type MockPolicyMatcher struct {
|
||||
func NewMockPolicyMatcher() *MockPolicyMatcher {
|
||||
return &MockPolicyMatcher{
|
||||
CommitsDescribedByPolicyInternalFunc: &PolicyMatcherCommitsDescribedByPolicyInternalFunc{
|
||||
defaultHook: func(context.Context, int, []shared.ConfigurationPolicy, time.Time, ...string) (r0 map[string][]enterprise.PolicyMatch, r1 error) {
|
||||
defaultHook: func(context.Context, int, []types.ConfigurationPolicy, time.Time, ...string) (r0 map[string][]enterprise.PolicyMatch, r1 error) {
|
||||
return
|
||||
},
|
||||
},
|
||||
@ -43,7 +43,7 @@ func NewMockPolicyMatcher() *MockPolicyMatcher {
|
||||
func NewStrictMockPolicyMatcher() *MockPolicyMatcher {
|
||||
return &MockPolicyMatcher{
|
||||
CommitsDescribedByPolicyInternalFunc: &PolicyMatcherCommitsDescribedByPolicyInternalFunc{
|
||||
defaultHook: func(context.Context, int, []shared.ConfigurationPolicy, time.Time, ...string) (map[string][]enterprise.PolicyMatch, error) {
|
||||
defaultHook: func(context.Context, int, []types.ConfigurationPolicy, time.Time, ...string) (map[string][]enterprise.PolicyMatch, error) {
|
||||
panic("unexpected invocation of MockPolicyMatcher.CommitsDescribedByPolicyInternal")
|
||||
},
|
||||
},
|
||||
@ -65,15 +65,15 @@ func NewMockPolicyMatcherFrom(i PolicyMatcher) *MockPolicyMatcher {
|
||||
// when the CommitsDescribedByPolicyInternal method of the parent
|
||||
// MockPolicyMatcher instance is invoked.
|
||||
type PolicyMatcherCommitsDescribedByPolicyInternalFunc struct {
|
||||
defaultHook func(context.Context, int, []shared.ConfigurationPolicy, time.Time, ...string) (map[string][]enterprise.PolicyMatch, error)
|
||||
hooks []func(context.Context, int, []shared.ConfigurationPolicy, time.Time, ...string) (map[string][]enterprise.PolicyMatch, error)
|
||||
defaultHook func(context.Context, int, []types.ConfigurationPolicy, time.Time, ...string) (map[string][]enterprise.PolicyMatch, error)
|
||||
hooks []func(context.Context, int, []types.ConfigurationPolicy, time.Time, ...string) (map[string][]enterprise.PolicyMatch, error)
|
||||
history []PolicyMatcherCommitsDescribedByPolicyInternalFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// CommitsDescribedByPolicyInternal delegates to the next hook function in
|
||||
// the queue and stores the parameter and result values of this invocation.
|
||||
func (m *MockPolicyMatcher) CommitsDescribedByPolicyInternal(v0 context.Context, v1 int, v2 []shared.ConfigurationPolicy, v3 time.Time, v4 ...string) (map[string][]enterprise.PolicyMatch, error) {
|
||||
func (m *MockPolicyMatcher) CommitsDescribedByPolicyInternal(v0 context.Context, v1 int, v2 []types.ConfigurationPolicy, v3 time.Time, v4 ...string) (map[string][]enterprise.PolicyMatch, error) {
|
||||
r0, r1 := m.CommitsDescribedByPolicyInternalFunc.nextHook()(v0, v1, v2, v3, v4...)
|
||||
m.CommitsDescribedByPolicyInternalFunc.appendCall(PolicyMatcherCommitsDescribedByPolicyInternalFuncCall{v0, v1, v2, v3, v4, r0, r1})
|
||||
return r0, r1
|
||||
@ -82,7 +82,7 @@ func (m *MockPolicyMatcher) CommitsDescribedByPolicyInternal(v0 context.Context,
|
||||
// SetDefaultHook sets function that is called when the
|
||||
// CommitsDescribedByPolicyInternal method of the parent MockPolicyMatcher
|
||||
// instance is invoked and the hook queue is empty.
|
||||
func (f *PolicyMatcherCommitsDescribedByPolicyInternalFunc) SetDefaultHook(hook func(context.Context, int, []shared.ConfigurationPolicy, time.Time, ...string) (map[string][]enterprise.PolicyMatch, error)) {
|
||||
func (f *PolicyMatcherCommitsDescribedByPolicyInternalFunc) SetDefaultHook(hook func(context.Context, int, []types.ConfigurationPolicy, time.Time, ...string) (map[string][]enterprise.PolicyMatch, error)) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ func (f *PolicyMatcherCommitsDescribedByPolicyInternalFunc) SetDefaultHook(hook
|
||||
// instance invokes the hook at the front of the queue and discards it.
|
||||
// After the queue is empty, the default hook function is invoked for any
|
||||
// future action.
|
||||
func (f *PolicyMatcherCommitsDescribedByPolicyInternalFunc) PushHook(hook func(context.Context, int, []shared.ConfigurationPolicy, time.Time, ...string) (map[string][]enterprise.PolicyMatch, error)) {
|
||||
func (f *PolicyMatcherCommitsDescribedByPolicyInternalFunc) PushHook(hook func(context.Context, int, []types.ConfigurationPolicy, time.Time, ...string) (map[string][]enterprise.PolicyMatch, error)) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
@ -100,19 +100,19 @@ func (f *PolicyMatcherCommitsDescribedByPolicyInternalFunc) PushHook(hook func(c
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *PolicyMatcherCommitsDescribedByPolicyInternalFunc) SetDefaultReturn(r0 map[string][]enterprise.PolicyMatch, r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, int, []shared.ConfigurationPolicy, time.Time, ...string) (map[string][]enterprise.PolicyMatch, error) {
|
||||
f.SetDefaultHook(func(context.Context, int, []types.ConfigurationPolicy, time.Time, ...string) (map[string][]enterprise.PolicyMatch, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *PolicyMatcherCommitsDescribedByPolicyInternalFunc) PushReturn(r0 map[string][]enterprise.PolicyMatch, r1 error) {
|
||||
f.PushHook(func(context.Context, int, []shared.ConfigurationPolicy, time.Time, ...string) (map[string][]enterprise.PolicyMatch, error) {
|
||||
f.PushHook(func(context.Context, int, []types.ConfigurationPolicy, time.Time, ...string) (map[string][]enterprise.PolicyMatch, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
func (f *PolicyMatcherCommitsDescribedByPolicyInternalFunc) nextHook() func(context.Context, int, []shared.ConfigurationPolicy, time.Time, ...string) (map[string][]enterprise.PolicyMatch, error) {
|
||||
func (f *PolicyMatcherCommitsDescribedByPolicyInternalFunc) nextHook() func(context.Context, int, []types.ConfigurationPolicy, time.Time, ...string) (map[string][]enterprise.PolicyMatch, error) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
@ -155,7 +155,7 @@ type PolicyMatcherCommitsDescribedByPolicyInternalFuncCall struct {
|
||||
Arg1 int
|
||||
// Arg2 is the value of the 3rd argument passed to this method
|
||||
// invocation.
|
||||
Arg2 []shared.ConfigurationPolicy
|
||||
Arg2 []types.ConfigurationPolicy
|
||||
// Arg3 is the value of the 4th argument passed to this method
|
||||
// invocation.
|
||||
Arg3 time.Time
|
||||
|
||||
@ -7,7 +7,7 @@ import (
|
||||
"github.com/sourcegraph/log"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/policies/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/types"
|
||||
"github.com/sourcegraph/sourcegraph/internal/conf"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain"
|
||||
"github.com/sourcegraph/sourcegraph/internal/goroutine"
|
||||
@ -83,7 +83,7 @@ func (s *scheduler) handleRepository(ctx context.Context, repositoryID int, now
|
||||
|
||||
for {
|
||||
// Retrieve the set of configuration policies that affect indexing for this repository.
|
||||
policies, totalCount, err := s.policySvc.GetConfigurationPolicies(ctx, shared.GetConfigurationPoliciesOptions{
|
||||
policies, totalCount, err := s.policySvc.GetConfigurationPolicies(ctx, types.GetConfigurationPoliciesOptions{
|
||||
RepositoryID: repositoryID,
|
||||
ForIndexing: true,
|
||||
Limit: ConfigInst.PolicyBatchSize,
|
||||
|
||||
@ -15,6 +15,7 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/env"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
"github.com/sourcegraph/sourcegraph/internal/symbols"
|
||||
"github.com/sourcegraph/sourcegraph/internal/trace"
|
||||
)
|
||||
|
||||
@ -43,8 +44,9 @@ func GetService(db database.DB, uploadSvc shared.UploadService, gitserver shared
|
||||
|
||||
s := store.New(db, oc("store"))
|
||||
inf := inference.GetService(db)
|
||||
sclient := symbols.DefaultClient
|
||||
|
||||
svc = newService(s, uploadSvc, gitserver, repoUpdater, inf, oc("service"))
|
||||
svc = newService(s, uploadSvc, gitserver, sclient, repoUpdater, inf, oc("service"))
|
||||
})
|
||||
|
||||
return svc
|
||||
|
||||
@ -33,6 +33,10 @@ type operations struct {
|
||||
// Index Configuration
|
||||
getIndexConfigurationByRepositoryID *observation.Operation
|
||||
updateIndexConfigurationByRepositoryID *observation.Operation
|
||||
|
||||
// Language Support
|
||||
getLanguagesRequestedBy *observation.Operation
|
||||
setRequestLanguageSupport *observation.Operation
|
||||
}
|
||||
|
||||
func newOperations(observationContext *observation.Context) *operations {
|
||||
@ -81,5 +85,9 @@ func newOperations(observationContext *observation.Context) *operations {
|
||||
// Index Configuration
|
||||
getIndexConfigurationByRepositoryID: op("GetIndexConfigurationByRepositoryID"),
|
||||
updateIndexConfigurationByRepositoryID: op("UpdateIndexConfigurationByRepositoryID"),
|
||||
|
||||
// Language Support
|
||||
getLanguagesRequestedBy: op("GetLanguagesRequestedBy"),
|
||||
setRequestLanguageSupport: op("SetRequestLanguageSupport"),
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ import (
|
||||
"github.com/lib/pq"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/types"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/basestore"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/dbutil"
|
||||
)
|
||||
@ -19,8 +20,8 @@ var scanIndexes = basestore.NewSliceScanner(scanIndex)
|
||||
// scanFirstIndex scans a slice of indexes from the return value of `*Store.query` and returns the first.
|
||||
var scanFirstIndex = basestore.NewFirstScanner(scanIndex)
|
||||
|
||||
func scanIndex(s dbutil.Scanner) (index shared.Index, err error) {
|
||||
var executionLogs []shared.ExecutionLogEntry
|
||||
func scanIndex(s dbutil.Scanner) (index types.Index, err error) {
|
||||
var executionLogs []types.ExecutionLogEntry
|
||||
if err := s.Scan(
|
||||
&index.ID,
|
||||
&index.Commit,
|
||||
@ -76,8 +77,8 @@ func scanIndexConfiguration(s dbutil.Scanner) (indexConfiguration shared.IndexCo
|
||||
var scanIndexesWithCount = basestore.NewSliceWithCountScanner(scanIndexWithCount)
|
||||
|
||||
// scanIndexes scans a slice of indexes from the return value of `*Store.query`.
|
||||
func scanIndexWithCount(s dbutil.Scanner) (index shared.Index, count int, err error) {
|
||||
var executionLogs []shared.ExecutionLogEntry
|
||||
func scanIndexWithCount(s dbutil.Scanner) (index types.Index, count int, err error) {
|
||||
var executionLogs []types.ExecutionLogEntry
|
||||
|
||||
if err := s.Scan(
|
||||
&index.ID,
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
logger "github.com/sourcegraph/log"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/types"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/basestore"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
@ -24,10 +25,10 @@ type Store interface {
|
||||
DeleteSourcedCommits(ctx context.Context, repositoryID int, commit string, maximumCommitLag time.Duration) (indexesDeleted int, err error)
|
||||
|
||||
// Indexes
|
||||
InsertIndexes(ctx context.Context, indexes []shared.Index) (_ []shared.Index, err error)
|
||||
GetIndexes(ctx context.Context, opts shared.GetIndexesOptions) (_ []shared.Index, _ int, err error)
|
||||
GetIndexByID(ctx context.Context, id int) (_ shared.Index, _ bool, err error)
|
||||
GetIndexesByIDs(ctx context.Context, ids ...int) (_ []shared.Index, err error)
|
||||
InsertIndexes(ctx context.Context, indexes []types.Index) (_ []types.Index, err error)
|
||||
GetIndexes(ctx context.Context, opts types.GetIndexesOptions) (_ []types.Index, _ int, err error)
|
||||
GetIndexByID(ctx context.Context, id int) (_ types.Index, _ bool, err error)
|
||||
GetIndexesByIDs(ctx context.Context, ids ...int) (_ []types.Index, err error)
|
||||
GetRecentIndexesSummary(ctx context.Context, repositoryID int) (summaries []shared.IndexesWithRepositoryNamespace, err error)
|
||||
GetLastIndexScanForRepository(ctx context.Context, repositoryID int) (_ *time.Time, err error)
|
||||
DeleteIndexByID(ctx context.Context, id int) (_ bool, err error)
|
||||
@ -40,12 +41,14 @@ type Store interface {
|
||||
// Index configurations
|
||||
GetIndexConfigurationByRepositoryID(ctx context.Context, repositoryID int) (_ shared.IndexConfiguration, _ bool, err error)
|
||||
UpdateIndexConfigurationByRepositoryID(ctx context.Context, repositoryID int, data []byte) (err error)
|
||||
}
|
||||
|
||||
type RepoRev struct {
|
||||
ID int
|
||||
RepositoryID int
|
||||
Rev string
|
||||
// Language support
|
||||
GetLanguagesRequestedBy(ctx context.Context, userID int) (_ []string, err error)
|
||||
SetRequestLanguageSupport(ctx context.Context, userID int, language string) (err error)
|
||||
|
||||
// GetUnsafeDB returns the underlying database handle. This is used by the
|
||||
// resolvers that have the old convention of using the database handle directly.
|
||||
GetUnsafeDB() database.DB
|
||||
}
|
||||
|
||||
// store manages the autoindexing store.
|
||||
@ -84,3 +87,9 @@ func (s *store) transact(ctx context.Context) (*store, error) {
|
||||
func (s *store) Done(err error) error {
|
||||
return s.db.Done(err)
|
||||
}
|
||||
|
||||
// GetUnsafeDB returns the underlying database handle. This is used by the
|
||||
// resolvers that have the old convention of using the database handle directly.
|
||||
func (s *store) GetUnsafeDB() database.DB {
|
||||
return database.NewDBWith(s.logger, s.db)
|
||||
}
|
||||
|
||||
@ -9,13 +9,14 @@ import (
|
||||
"github.com/opentracing/opentracing-go/log"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/types"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/basestore"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
)
|
||||
|
||||
// InsertIndexes inserts a new index and returns the hydrated index models.
|
||||
func (s *store) InsertIndexes(ctx context.Context, indexes []shared.Index) (_ []shared.Index, err error) {
|
||||
func (s *store) InsertIndexes(ctx context.Context, indexes []types.Index) (_ []types.Index, err error) {
|
||||
ctx, _, endObservation := s.operations.insertIndex.With(ctx, &err, observation.Args{})
|
||||
defer func() {
|
||||
endObservation(1, observation.Args{LogFields: []log.Field{
|
||||
@ -30,7 +31,7 @@ func (s *store) InsertIndexes(ctx context.Context, indexes []shared.Index) (_ []
|
||||
values := make([]*sqlf.Query, 0, len(indexes))
|
||||
for _, index := range indexes {
|
||||
if index.DockerSteps == nil {
|
||||
index.DockerSteps = []shared.DockerStep{}
|
||||
index.DockerSteps = []types.DockerStep{}
|
||||
}
|
||||
if index.IndexerArgs == nil {
|
||||
index.IndexerArgs = []string{}
|
||||
@ -88,7 +89,7 @@ RETURNING id
|
||||
`
|
||||
|
||||
// GetIndexes returns a list of indexes and the total count of records matching the given conditions.
|
||||
func (s *store) GetIndexes(ctx context.Context, opts shared.GetIndexesOptions) (_ []shared.Index, _ int, err error) {
|
||||
func (s *store) GetIndexes(ctx context.Context, opts types.GetIndexesOptions) (_ []types.Index, _ int, err error) {
|
||||
ctx, trace, endObservation := s.operations.getIndexes.With(ctx, &err, observation.Args{LogFields: []log.Field{
|
||||
log.Int("repositoryID", opts.RepositoryID),
|
||||
log.String("state", opts.State),
|
||||
@ -204,7 +205,7 @@ func makeStateCondition(state string) *sqlf.Query {
|
||||
}
|
||||
|
||||
// GetIndexByID returns an index by its identifier and boolean flag indicating its existence.
|
||||
func (s *store) GetIndexByID(ctx context.Context, id int) (_ shared.Index, _ bool, err error) {
|
||||
func (s *store) GetIndexByID(ctx context.Context, id int) (_ types.Index, _ bool, err error) {
|
||||
ctx, _, endObservation := s.operations.getIndexByID.With(ctx, &err, observation.Args{LogFields: []log.Field{
|
||||
log.Int("id", id),
|
||||
}})
|
||||
@ -212,7 +213,7 @@ func (s *store) GetIndexByID(ctx context.Context, id int) (_ shared.Index, _ boo
|
||||
|
||||
authzConds, err := database.AuthzQueryConds(ctx, database.NewDBWith(s.logger, s.db))
|
||||
if err != nil {
|
||||
return shared.Index{}, false, err
|
||||
return types.Index{}, false, err
|
||||
}
|
||||
|
||||
return scanFirstIndex(s.db.Query(ctx, sqlf.Sprintf(getIndexByIDQuery, id, authzConds)))
|
||||
@ -265,7 +266,7 @@ WHERE repo.deleted_at IS NULL AND u.id = %s AND %s
|
||||
|
||||
// GetIndexesByIDs returns an index for each of the given identifiers. Not all given ids will necessarily
|
||||
// have a corresponding element in the returned list.
|
||||
func (s *store) GetIndexesByIDs(ctx context.Context, ids ...int) (_ []shared.Index, err error) {
|
||||
func (s *store) GetIndexesByIDs(ctx context.Context, ids ...int) (_ []types.Index, err error) {
|
||||
ctx, _, endObservation := s.operations.getIndexesByIDs.With(ctx, &err, observation.Args{LogFields: []log.Field{
|
||||
log.String("ids", intsToString(ids)),
|
||||
}})
|
||||
@ -474,6 +475,12 @@ VALUES (%s, %s)
|
||||
ON CONFLICT DO NOTHING
|
||||
`
|
||||
|
||||
type RepoRev struct {
|
||||
ID int
|
||||
RepositoryID int
|
||||
Rev string
|
||||
}
|
||||
|
||||
// GetQueuedRepoRev selects a batch of repository and revisions to be processed by the auto-indexing
|
||||
// scheduler. If in a transaction, the seleted records will remain locked until the enclosing transaction
|
||||
// has been committed or rolled back.
|
||||
|
||||
@ -16,6 +16,7 @@ import (
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/globals"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/types"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/basestore"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/dbtest"
|
||||
@ -31,12 +32,12 @@ func TestInsertIndexes(t *testing.T) {
|
||||
|
||||
insertRepo(t, db, 50, "")
|
||||
|
||||
indexes, err := store.InsertIndexes(ctx, []shared.Index{
|
||||
indexes, err := store.InsertIndexes(ctx, []types.Index{
|
||||
{
|
||||
State: "queued",
|
||||
Commit: makeCommit(1),
|
||||
RepositoryID: 50,
|
||||
DockerSteps: []shared.DockerStep{
|
||||
DockerSteps: []types.DockerStep{
|
||||
{
|
||||
Image: "cimg/node:12.16",
|
||||
Commands: []string{"yarn install --frozen-lockfile --no-progress"},
|
||||
@ -47,7 +48,7 @@ func TestInsertIndexes(t *testing.T) {
|
||||
Indexer: "sourcegraph/scip-typescript:latest",
|
||||
IndexerArgs: []string{"index", "--yarn-workspaces"},
|
||||
Outfile: "dump.lsif",
|
||||
ExecutionLogs: []shared.ExecutionLogEntry{
|
||||
ExecutionLogs: []types.ExecutionLogEntry{
|
||||
{Command: []string{"op", "1"}, Out: "Indexing\nUploading\nDone with 1.\n"},
|
||||
{Command: []string{"op", "2"}, Out: "Indexing\nUploading\nDone with 2.\n"},
|
||||
},
|
||||
@ -56,7 +57,7 @@ func TestInsertIndexes(t *testing.T) {
|
||||
State: "queued",
|
||||
Commit: makeCommit(2),
|
||||
RepositoryID: 50,
|
||||
DockerSteps: []shared.DockerStep{
|
||||
DockerSteps: []types.DockerStep{
|
||||
{
|
||||
Image: "cimg/rust:nightly",
|
||||
Commands: []string{"cargo install"},
|
||||
@ -67,7 +68,7 @@ func TestInsertIndexes(t *testing.T) {
|
||||
Indexer: "sourcegraph/lsif-rust:15",
|
||||
IndexerArgs: []string{"-v"},
|
||||
Outfile: "dump.lsif",
|
||||
ExecutionLogs: []shared.ExecutionLogEntry{
|
||||
ExecutionLogs: []types.ExecutionLogEntry{
|
||||
{Command: []string{"op", "1"}, Out: "Done with 1.\n"},
|
||||
{Command: []string{"op", "2"}, Out: "Done with 2.\n"},
|
||||
},
|
||||
@ -82,7 +83,7 @@ func TestInsertIndexes(t *testing.T) {
|
||||
|
||||
rank1 := 1
|
||||
rank2 := 2
|
||||
expected := []shared.Index{
|
||||
expected := []types.Index{
|
||||
{
|
||||
ID: 1,
|
||||
Commit: makeCommit(1),
|
||||
@ -93,7 +94,7 @@ func TestInsertIndexes(t *testing.T) {
|
||||
FinishedAt: nil,
|
||||
RepositoryID: 50,
|
||||
RepositoryName: "n-50",
|
||||
DockerSteps: []shared.DockerStep{
|
||||
DockerSteps: []types.DockerStep{
|
||||
{
|
||||
Image: "cimg/node:12.16",
|
||||
Commands: []string{"yarn install --frozen-lockfile --no-progress"},
|
||||
@ -104,7 +105,7 @@ func TestInsertIndexes(t *testing.T) {
|
||||
Indexer: "sourcegraph/scip-typescript:latest",
|
||||
IndexerArgs: []string{"index", "--yarn-workspaces"},
|
||||
Outfile: "dump.lsif",
|
||||
ExecutionLogs: []shared.ExecutionLogEntry{
|
||||
ExecutionLogs: []types.ExecutionLogEntry{
|
||||
{Command: []string{"op", "1"}, Out: "Indexing\nUploading\nDone with 1.\n"},
|
||||
{Command: []string{"op", "2"}, Out: "Indexing\nUploading\nDone with 2.\n"},
|
||||
},
|
||||
@ -120,7 +121,7 @@ func TestInsertIndexes(t *testing.T) {
|
||||
FinishedAt: nil,
|
||||
RepositoryID: 50,
|
||||
RepositoryName: "n-50",
|
||||
DockerSteps: []shared.DockerStep{
|
||||
DockerSteps: []types.DockerStep{
|
||||
{
|
||||
Image: "cimg/rust:nightly",
|
||||
Commands: []string{"cargo install"},
|
||||
@ -131,7 +132,7 @@ func TestInsertIndexes(t *testing.T) {
|
||||
Indexer: "sourcegraph/lsif-rust:15",
|
||||
IndexerArgs: []string{"-v"},
|
||||
Outfile: "dump.lsif",
|
||||
ExecutionLogs: []shared.ExecutionLogEntry{
|
||||
ExecutionLogs: []types.ExecutionLogEntry{
|
||||
{Command: []string{"op", "1"}, Out: "Done with 1.\n"},
|
||||
{Command: []string{"op", "2"}, Out: "Done with 2.\n"},
|
||||
},
|
||||
@ -171,16 +172,16 @@ func TestGetIndexes(t *testing.T) {
|
||||
uploadID1, uploadID2, uploadID3, uploadID4 := 10, 11, 12, 13
|
||||
|
||||
insertIndexes(t, db,
|
||||
shared.Index{ID: 1, Commit: makeCommit(3331), QueuedAt: t1, State: "queued", AssociatedUploadID: &uploadID1},
|
||||
shared.Index{ID: 2, QueuedAt: t2, State: "errored", FailureMessage: &failureMessage},
|
||||
shared.Index{ID: 3, Commit: makeCommit(3333), QueuedAt: t3, State: "queued", AssociatedUploadID: &uploadID1},
|
||||
shared.Index{ID: 4, QueuedAt: t4, State: "queued", RepositoryID: 51, RepositoryName: "foo bar x"},
|
||||
shared.Index{ID: 5, Commit: makeCommit(3333), QueuedAt: t5, State: "processing", AssociatedUploadID: &uploadID1},
|
||||
shared.Index{ID: 6, QueuedAt: t6, State: "processing", RepositoryID: 52, RepositoryName: "foo bar y"},
|
||||
shared.Index{ID: 7, QueuedAt: t7},
|
||||
shared.Index{ID: 8, QueuedAt: t8},
|
||||
shared.Index{ID: 9, QueuedAt: t9, State: "queued"},
|
||||
shared.Index{ID: 10, QueuedAt: t10},
|
||||
types.Index{ID: 1, Commit: makeCommit(3331), QueuedAt: t1, State: "queued", AssociatedUploadID: &uploadID1},
|
||||
types.Index{ID: 2, QueuedAt: t2, State: "errored", FailureMessage: &failureMessage},
|
||||
types.Index{ID: 3, Commit: makeCommit(3333), QueuedAt: t3, State: "queued", AssociatedUploadID: &uploadID1},
|
||||
types.Index{ID: 4, QueuedAt: t4, State: "queued", RepositoryID: 51, RepositoryName: "foo bar x"},
|
||||
types.Index{ID: 5, Commit: makeCommit(3333), QueuedAt: t5, State: "processing", AssociatedUploadID: &uploadID1},
|
||||
types.Index{ID: 6, QueuedAt: t6, State: "processing", RepositoryID: 52, RepositoryName: "foo bar y"},
|
||||
types.Index{ID: 7, QueuedAt: t7},
|
||||
types.Index{ID: 8, QueuedAt: t8},
|
||||
types.Index{ID: 9, QueuedAt: t9, State: "queued"},
|
||||
types.Index{ID: 10, QueuedAt: t10},
|
||||
)
|
||||
insertUploads(t, db,
|
||||
Upload{ID: uploadID1, AssociatedIndexID: &indexID1},
|
||||
@ -221,7 +222,7 @@ func TestGetIndexes(t *testing.T) {
|
||||
)
|
||||
|
||||
t.Run(name, func(t *testing.T) {
|
||||
indexes, totalCount, err := store.GetIndexes(ctx, shared.GetIndexesOptions{
|
||||
indexes, totalCount, err := store.GetIndexes(ctx, types.GetIndexesOptions{
|
||||
RepositoryID: testCase.repositoryID,
|
||||
State: testCase.state,
|
||||
Term: testCase.term,
|
||||
@ -256,7 +257,7 @@ func TestGetIndexes(t *testing.T) {
|
||||
defer globals.SetPermissionsUserMapping(before)
|
||||
|
||||
indexes, totalCount, err := store.GetIndexes(ctx,
|
||||
shared.GetIndexesOptions{
|
||||
types.GetIndexesOptions{
|
||||
Limit: 1,
|
||||
},
|
||||
)
|
||||
@ -285,7 +286,7 @@ func TestGetIndexByID(t *testing.T) {
|
||||
uploadID := 5
|
||||
queuedAt := time.Unix(1587396557, 0).UTC()
|
||||
startedAt := queuedAt.Add(time.Minute)
|
||||
expected := shared.Index{
|
||||
expected := types.Index{
|
||||
ID: 1,
|
||||
Commit: makeCommit(1),
|
||||
QueuedAt: queuedAt,
|
||||
@ -295,7 +296,7 @@ func TestGetIndexByID(t *testing.T) {
|
||||
FinishedAt: nil,
|
||||
RepositoryID: 123,
|
||||
RepositoryName: "n-123",
|
||||
DockerSteps: []shared.DockerStep{
|
||||
DockerSteps: []types.DockerStep{
|
||||
{
|
||||
Image: "cimg/node:12.16",
|
||||
Commands: []string{"yarn install --frozen-lockfile --no-progress"},
|
||||
@ -306,7 +307,7 @@ func TestGetIndexByID(t *testing.T) {
|
||||
Indexer: "sourcegraph/scip-typescript:latest",
|
||||
IndexerArgs: []string{"index", "--yarn-workspaces"},
|
||||
Outfile: "dump.lsif",
|
||||
ExecutionLogs: []shared.ExecutionLogEntry{
|
||||
ExecutionLogs: []types.ExecutionLogEntry{
|
||||
{Command: []string{"op", "1"}, Out: "Indexing\nUploading\nDone with 1.\n"},
|
||||
{Command: []string{"op", "2"}, Out: "Indexing\nUploading\nDone with 2.\n"},
|
||||
},
|
||||
@ -353,16 +354,16 @@ func TestGetIndexesByIDs(t *testing.T) {
|
||||
uploadID1, uploadID2, uploadID3, uploadID4 := 10, 11, 12, 13
|
||||
|
||||
insertIndexes(t, db,
|
||||
shared.Index{ID: 1, AssociatedUploadID: &uploadID1},
|
||||
shared.Index{ID: 2},
|
||||
shared.Index{ID: 3, AssociatedUploadID: &uploadID1},
|
||||
shared.Index{ID: 4},
|
||||
shared.Index{ID: 5, AssociatedUploadID: &uploadID1},
|
||||
shared.Index{ID: 6},
|
||||
shared.Index{ID: 7},
|
||||
shared.Index{ID: 8},
|
||||
shared.Index{ID: 9},
|
||||
shared.Index{ID: 10},
|
||||
types.Index{ID: 1, AssociatedUploadID: &uploadID1},
|
||||
types.Index{ID: 2},
|
||||
types.Index{ID: 3, AssociatedUploadID: &uploadID1},
|
||||
types.Index{ID: 4},
|
||||
types.Index{ID: 5, AssociatedUploadID: &uploadID1},
|
||||
types.Index{ID: 6},
|
||||
types.Index{ID: 7},
|
||||
types.Index{ID: 8},
|
||||
types.Index{ID: 9},
|
||||
types.Index{ID: 10},
|
||||
)
|
||||
insertUploads(t, db,
|
||||
Upload{ID: uploadID1, AssociatedIndexID: &indexID1},
|
||||
@ -420,13 +421,13 @@ func TestGetQueuedIndexRank(t *testing.T) {
|
||||
t7 := t1.Add(+time.Minute * 5)
|
||||
|
||||
insertIndexes(t, db,
|
||||
shared.Index{ID: 1, QueuedAt: t1, State: "queued"},
|
||||
shared.Index{ID: 2, QueuedAt: t2, State: "queued"},
|
||||
shared.Index{ID: 3, QueuedAt: t3, State: "queued"},
|
||||
shared.Index{ID: 4, QueuedAt: t4, State: "queued"},
|
||||
shared.Index{ID: 5, QueuedAt: t5, State: "queued"},
|
||||
shared.Index{ID: 6, QueuedAt: t6, State: "processing"},
|
||||
shared.Index{ID: 7, QueuedAt: t1, State: "queued", ProcessAfter: &t7},
|
||||
types.Index{ID: 1, QueuedAt: t1, State: "queued"},
|
||||
types.Index{ID: 2, QueuedAt: t2, State: "queued"},
|
||||
types.Index{ID: 3, QueuedAt: t3, State: "queued"},
|
||||
types.Index{ID: 4, QueuedAt: t4, State: "queued"},
|
||||
types.Index{ID: 5, QueuedAt: t5, State: "queued"},
|
||||
types.Index{ID: 6, QueuedAt: t6, State: "processing"},
|
||||
types.Index{ID: 7, QueuedAt: t1, State: "queued", ProcessAfter: &t7},
|
||||
)
|
||||
|
||||
if index, _, _ := store.GetIndexByID(context.Background(), 1); index.Rank == nil || *index.Rank != 1 {
|
||||
@ -476,27 +477,27 @@ func TestRecentIndexesSummary(t *testing.T) {
|
||||
r1 := 1
|
||||
r2 := 2
|
||||
|
||||
addDefaults := func(index shared.Index) shared.Index {
|
||||
addDefaults := func(index types.Index) types.Index {
|
||||
index.Commit = makeCommit(index.ID)
|
||||
index.RepositoryID = 50
|
||||
index.RepositoryName = "n-50"
|
||||
index.DockerSteps = []shared.DockerStep{}
|
||||
index.DockerSteps = []types.DockerStep{}
|
||||
index.IndexerArgs = []string{}
|
||||
index.LocalSteps = []string{}
|
||||
return index
|
||||
}
|
||||
|
||||
indexes := []shared.Index{
|
||||
addDefaults(shared.Index{ID: 150, QueuedAt: t0, Root: "r1", Indexer: "i1", State: "queued", Rank: &r2}), // visible (group 1)
|
||||
addDefaults(shared.Index{ID: 151, QueuedAt: t1, Root: "r1", Indexer: "i1", State: "queued", Rank: &r1}), // visible (group 1)
|
||||
addDefaults(shared.Index{ID: 152, FinishedAt: &t2, Root: "r1", Indexer: "i1", State: "errored"}), // visible (group 1)
|
||||
addDefaults(shared.Index{ID: 153, FinishedAt: &t3, Root: "r1", Indexer: "i2", State: "completed"}), // visible (group 2)
|
||||
addDefaults(shared.Index{ID: 154, FinishedAt: &t4, Root: "r2", Indexer: "i1", State: "completed"}), // visible (group 3)
|
||||
addDefaults(shared.Index{ID: 155, FinishedAt: &t5, Root: "r2", Indexer: "i1", State: "errored"}), // shadowed
|
||||
addDefaults(shared.Index{ID: 156, FinishedAt: &t6, Root: "r2", Indexer: "i2", State: "completed"}), // visible (group 4)
|
||||
addDefaults(shared.Index{ID: 157, FinishedAt: &t7, Root: "r2", Indexer: "i2", State: "errored"}), // shadowed
|
||||
addDefaults(shared.Index{ID: 158, FinishedAt: &t8, Root: "r2", Indexer: "i2", State: "errored"}), // shadowed
|
||||
addDefaults(shared.Index{ID: 159, FinishedAt: &t9, Root: "r2", Indexer: "i2", State: "errored"}), // shadowed
|
||||
indexes := []types.Index{
|
||||
addDefaults(types.Index{ID: 150, QueuedAt: t0, Root: "r1", Indexer: "i1", State: "queued", Rank: &r2}), // visible (group 1)
|
||||
addDefaults(types.Index{ID: 151, QueuedAt: t1, Root: "r1", Indexer: "i1", State: "queued", Rank: &r1}), // visible (group 1)
|
||||
addDefaults(types.Index{ID: 152, FinishedAt: &t2, Root: "r1", Indexer: "i1", State: "errored"}), // visible (group 1)
|
||||
addDefaults(types.Index{ID: 153, FinishedAt: &t3, Root: "r1", Indexer: "i2", State: "completed"}), // visible (group 2)
|
||||
addDefaults(types.Index{ID: 154, FinishedAt: &t4, Root: "r2", Indexer: "i1", State: "completed"}), // visible (group 3)
|
||||
addDefaults(types.Index{ID: 155, FinishedAt: &t5, Root: "r2", Indexer: "i1", State: "errored"}), // shadowed
|
||||
addDefaults(types.Index{ID: 156, FinishedAt: &t6, Root: "r2", Indexer: "i2", State: "completed"}), // visible (group 4)
|
||||
addDefaults(types.Index{ID: 157, FinishedAt: &t7, Root: "r2", Indexer: "i2", State: "errored"}), // shadowed
|
||||
addDefaults(types.Index{ID: 158, FinishedAt: &t8, Root: "r2", Indexer: "i2", State: "errored"}), // shadowed
|
||||
addDefaults(types.Index{ID: 159, FinishedAt: &t9, Root: "r2", Indexer: "i2", State: "errored"}), // shadowed
|
||||
}
|
||||
insertIndexes(t, db, indexes...)
|
||||
|
||||
@ -506,10 +507,10 @@ func TestRecentIndexesSummary(t *testing.T) {
|
||||
}
|
||||
|
||||
expected := []shared.IndexesWithRepositoryNamespace{
|
||||
{Root: "r1", Indexer: "i1", Indexes: []shared.Index{indexes[0], indexes[1], indexes[2]}},
|
||||
{Root: "r1", Indexer: "i2", Indexes: []shared.Index{indexes[3]}},
|
||||
{Root: "r2", Indexer: "i1", Indexes: []shared.Index{indexes[4]}},
|
||||
{Root: "r2", Indexer: "i2", Indexes: []shared.Index{indexes[6]}},
|
||||
{Root: "r1", Indexer: "i1", Indexes: []types.Index{indexes[0], indexes[1], indexes[2]}},
|
||||
{Root: "r1", Indexer: "i2", Indexes: []types.Index{indexes[3]}},
|
||||
{Root: "r2", Indexer: "i1", Indexes: []types.Index{indexes[4]}},
|
||||
{Root: "r2", Indexer: "i2", Indexes: []types.Index{indexes[6]}},
|
||||
}
|
||||
if diff := cmp.Diff(expected, summary); diff != "" {
|
||||
t.Errorf("unexpected index summary (-want +got):\n%s", diff)
|
||||
@ -554,7 +555,7 @@ func TestDeleteIndexByID(t *testing.T) {
|
||||
db := database.NewDB(logger, dbtest.NewDB(logger, t))
|
||||
store := New(db, &observation.TestContext)
|
||||
|
||||
insertIndexes(t, db, shared.Index{ID: 1})
|
||||
insertIndexes(t, db, types.Index{ID: 1})
|
||||
|
||||
if found, err := store.DeleteIndexByID(context.Background(), 1); err != nil {
|
||||
t.Fatalf("unexpected error deleting index: %s", err)
|
||||
@ -587,10 +588,10 @@ func TestDeleteIndexesWithoutRepository(t *testing.T) {
|
||||
db := database.NewDB(logger, dbtest.NewDB(logger, t))
|
||||
store := New(db, &observation.TestContext)
|
||||
|
||||
var indexes []shared.Index
|
||||
var indexes []types.Index
|
||||
for i := 0; i < 25; i++ {
|
||||
for j := 0; j < 10+i; j++ {
|
||||
indexes = append(indexes, shared.Index{ID: len(indexes) + 1, RepositoryID: 50 + i})
|
||||
indexes = append(indexes, types.Index{ID: len(indexes) + 1, RepositoryID: 50 + i})
|
||||
}
|
||||
}
|
||||
insertIndexes(t, db, indexes...)
|
||||
@ -632,7 +633,7 @@ func TestIsQueued(t *testing.T) {
|
||||
db := database.NewDB(logger, dbtest.NewDB(logger, t))
|
||||
store := New(db, &observation.TestContext)
|
||||
|
||||
insertIndexes(t, db, shared.Index{ID: 1, RepositoryID: 1, Commit: makeCommit(1)})
|
||||
insertIndexes(t, db, types.Index{ID: 1, RepositoryID: 1, Commit: makeCommit(1)})
|
||||
insertUploads(t, db, Upload{ID: 2, RepositoryID: 2, Commit: makeCommit(2)})
|
||||
insertUploads(t, db, Upload{ID: 3, RepositoryID: 3, Commit: makeCommit(3), State: "deleted"})
|
||||
|
||||
|
||||
@ -0,0 +1,39 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/keegancsmith/sqlf"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/basestore"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
)
|
||||
|
||||
func (s *store) GetLanguagesRequestedBy(ctx context.Context, userID int) (_ []string, err error) {
|
||||
ctx, _, endObservation := s.operations.getLanguagesRequestedBy.With(ctx, &err, observation.Args{})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
return basestore.ScanStrings(s.db.Query(ctx, sqlf.Sprintf(languagesRequestedByQuery, userID)))
|
||||
}
|
||||
|
||||
const languagesRequestedByQuery = `
|
||||
-- source: internal/codeintel/autoindexing/internal/store/store_language_support.go:GetLanguagesRequestedBy
|
||||
SELECT language_id
|
||||
FROM codeintel_langugage_support_requests
|
||||
WHERE user_id = %s
|
||||
ORDER BY language_id
|
||||
`
|
||||
|
||||
func (s *store) SetRequestLanguageSupport(ctx context.Context, userID int, language string) (err error) {
|
||||
ctx, _, endObservation := s.operations.setRequestLanguageSupport.With(ctx, &err, observation.Args{})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
return s.db.Exec(ctx, sqlf.Sprintf(requestLanguageSupportQuery, userID, language))
|
||||
}
|
||||
|
||||
const requestLanguageSupportQuery = `
|
||||
-- source: internal/codeintel/autoindexing/internal/store/store_language_support.go:SetRequestLanguageSupport
|
||||
INSERT INTO codeintel_langugage_support_requests (user_id, language_id)
|
||||
VALUES (%s, %s)
|
||||
ON CONFLICT DO NOTHING
|
||||
`
|
||||
@ -14,6 +14,7 @@ import (
|
||||
"github.com/sourcegraph/log/logtest"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/types"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/basestore"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/dbtest"
|
||||
@ -29,11 +30,11 @@ func TestGetStaleSourcedCommits(t *testing.T) {
|
||||
now := time.Unix(1587396557, 0).UTC()
|
||||
|
||||
insertIndexes(t, db,
|
||||
shared.Index{ID: 1, RepositoryID: 50, Commit: makeCommit(1)},
|
||||
shared.Index{ID: 2, RepositoryID: 50, Commit: makeCommit(2)},
|
||||
shared.Index{ID: 3, RepositoryID: 50, Commit: makeCommit(3)},
|
||||
shared.Index{ID: 4, RepositoryID: 51, Commit: makeCommit(6)},
|
||||
shared.Index{ID: 5, RepositoryID: 52, Commit: makeCommit(7)},
|
||||
types.Index{ID: 1, RepositoryID: 50, Commit: makeCommit(1)},
|
||||
types.Index{ID: 2, RepositoryID: 50, Commit: makeCommit(2)},
|
||||
types.Index{ID: 3, RepositoryID: 50, Commit: makeCommit(3)},
|
||||
types.Index{ID: 4, RepositoryID: 51, Commit: makeCommit(6)},
|
||||
types.Index{ID: 5, RepositoryID: 52, Commit: makeCommit(7)},
|
||||
)
|
||||
|
||||
sourcedCommits, err := store.GetStaleSourcedCommits(context.Background(), time.Minute, 5, now)
|
||||
@ -82,11 +83,11 @@ func TestUpdateSourcedCommits(t *testing.T) {
|
||||
now := time.Unix(1587396557, 0).UTC()
|
||||
|
||||
insertIndexes(t, db,
|
||||
shared.Index{ID: 1, RepositoryID: 50, Commit: makeCommit(3)},
|
||||
shared.Index{ID: 2, RepositoryID: 50, Commit: makeCommit(2)},
|
||||
shared.Index{ID: 3, RepositoryID: 52, Commit: makeCommit(7)},
|
||||
shared.Index{ID: 4, RepositoryID: 51, Commit: makeCommit(6)},
|
||||
shared.Index{ID: 5, RepositoryID: 50, Commit: makeCommit(1)},
|
||||
types.Index{ID: 1, RepositoryID: 50, Commit: makeCommit(3)},
|
||||
types.Index{ID: 2, RepositoryID: 50, Commit: makeCommit(2)},
|
||||
types.Index{ID: 3, RepositoryID: 52, Commit: makeCommit(7)},
|
||||
types.Index{ID: 4, RepositoryID: 51, Commit: makeCommit(6)},
|
||||
types.Index{ID: 5, RepositoryID: 50, Commit: makeCommit(1)},
|
||||
)
|
||||
|
||||
indexesUpdated, err := store.UpdateSourcedCommits(context.Background(), 50, makeCommit(1), now)
|
||||
@ -120,11 +121,11 @@ func TestDeleteSourcedCommits(t *testing.T) {
|
||||
store := New(db, &observation.TestContext)
|
||||
|
||||
insertIndexes(t, db,
|
||||
shared.Index{ID: 1, RepositoryID: 50, Commit: makeCommit(3)},
|
||||
shared.Index{ID: 2, RepositoryID: 50, Commit: makeCommit(2)},
|
||||
shared.Index{ID: 3, RepositoryID: 52, Commit: makeCommit(7)},
|
||||
shared.Index{ID: 4, RepositoryID: 51, Commit: makeCommit(6)},
|
||||
shared.Index{ID: 5, RepositoryID: 50, Commit: makeCommit(1)},
|
||||
types.Index{ID: 1, RepositoryID: 50, Commit: makeCommit(3)},
|
||||
types.Index{ID: 2, RepositoryID: 50, Commit: makeCommit(2)},
|
||||
types.Index{ID: 3, RepositoryID: 52, Commit: makeCommit(7)},
|
||||
types.Index{ID: 4, RepositoryID: 51, Commit: makeCommit(6)},
|
||||
types.Index{ID: 5, RepositoryID: 50, Commit: makeCommit(1)},
|
||||
)
|
||||
|
||||
indexesDeleted, err := store.DeleteSourcedCommits(context.Background(), 52, makeCommit(7), time.Hour)
|
||||
@ -152,7 +153,7 @@ func TestDeleteSourcedCommits(t *testing.T) {
|
||||
}
|
||||
|
||||
// insertIndexes populates the lsif_indexes table with the given index models.
|
||||
func insertIndexes(t testing.TB, db database.DB, indexes ...shared.Index) {
|
||||
func insertIndexes(t testing.TB, db database.DB, indexes ...types.Index) {
|
||||
for _, index := range indexes {
|
||||
if index.Commit == "" {
|
||||
index.Commit = makeCommit(index.ID)
|
||||
@ -164,7 +165,7 @@ func insertIndexes(t testing.TB, db database.DB, indexes ...shared.Index) {
|
||||
index.RepositoryID = 50
|
||||
}
|
||||
if index.DockerSteps == nil {
|
||||
index.DockerSteps = []shared.DockerStep{}
|
||||
index.DockerSteps = []types.DockerStep{}
|
||||
}
|
||||
if index.IndexerArgs == nil {
|
||||
index.IndexerArgs = []string{}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -29,6 +29,16 @@ type operations struct {
|
||||
getIndexConfigurationByRepositoryID *observation.Operation
|
||||
updateIndexConfigurationByRepositoryID *observation.Operation
|
||||
inferIndexConfiguration *observation.Operation
|
||||
|
||||
// Auth
|
||||
checkCurrentUserIsSiteAdmin *observation.Operation
|
||||
|
||||
// Tags
|
||||
getListTags *observation.Operation
|
||||
|
||||
// Language support
|
||||
getLanguagesRequestedBy *observation.Operation
|
||||
setRequestLanguageSupport *observation.Operation
|
||||
}
|
||||
|
||||
func newOperations(observationContext *observation.Context) *operations {
|
||||
@ -69,5 +79,15 @@ func newOperations(observationContext *observation.Context) *operations {
|
||||
getIndexConfigurationByRepositoryID: op("GetIndexConfigurationByRepositoryID"),
|
||||
updateIndexConfigurationByRepositoryID: op("UpdateIndexConfigurationByRepositoryID"),
|
||||
inferIndexConfiguration: op("InferIndexConfiguration"),
|
||||
|
||||
// Auth
|
||||
checkCurrentUserIsSiteAdmin: op("CheckCurrentUserIsSiteAdmin"),
|
||||
|
||||
// Tags
|
||||
getListTags: op("GetListTags"),
|
||||
|
||||
// Language support
|
||||
getLanguagesRequestedBy: op("GetLanguagesRequestedBy"),
|
||||
setRequestLanguageSupport: op("SetRequestLanguageSupport"),
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,17 +2,24 @@ package autoindexing
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/regexp"
|
||||
otlog "github.com/opentracing/opentracing-go/log"
|
||||
traceLog "github.com/opentracing/opentracing-go/log"
|
||||
"github.com/sourcegraph/log"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/store"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/types"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/errcode"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
"github.com/sourcegraph/sourcegraph/internal/symbols"
|
||||
"github.com/sourcegraph/sourcegraph/lib/codeintel/autoindex/config"
|
||||
"github.com/sourcegraph/sourcegraph/lib/codeintel/precise"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
@ -27,26 +34,41 @@ type service interface {
|
||||
DeleteSourcedCommits(ctx context.Context, repositoryID int, commit string, maximumCommitLag time.Duration, now time.Time) (indexesDeleted int, err error)
|
||||
|
||||
// Indexes
|
||||
GetIndexes(ctx context.Context, opts shared.GetIndexesOptions) (_ []shared.Index, _ int, err error)
|
||||
GetIndexByID(ctx context.Context, id int) (_ shared.Index, _ bool, err error)
|
||||
GetIndexesByIDs(ctx context.Context, ids ...int) (_ []shared.Index, err error)
|
||||
GetIndexes(ctx context.Context, opts types.GetIndexesOptions) (_ []types.Index, _ int, err error)
|
||||
GetIndexByID(ctx context.Context, id int) (_ types.Index, _ bool, err error)
|
||||
GetIndexesByIDs(ctx context.Context, ids ...int) (_ []types.Index, err error)
|
||||
GetRecentIndexesSummary(ctx context.Context, repositoryID int) (summaries []shared.IndexesWithRepositoryNamespace, err error)
|
||||
GetLastIndexScanForRepository(ctx context.Context, repositoryID int) (_ *time.Time, err error)
|
||||
DeleteIndexByID(ctx context.Context, id int) (_ bool, err error)
|
||||
DeleteIndexesWithoutRepository(ctx context.Context, now time.Time) (map[int]int, error)
|
||||
QueueIndexes(ctx context.Context, repositoryID int, rev, configuration string, force, bypassLimit bool) (_ []shared.Index, err error)
|
||||
QueueIndexes(ctx context.Context, repositoryID int, rev, configuration string, force, bypassLimit bool) (_ []types.Index, err error)
|
||||
QueueIndexesForPackage(ctx context.Context, pkg precise.Package) (err error)
|
||||
|
||||
// Index configurations
|
||||
GetIndexConfigurationByRepositoryID(ctx context.Context, repositoryID int) (_ shared.IndexConfiguration, _ bool, err error)
|
||||
InferIndexConfiguration(ctx context.Context, repositoryID int, commit string, bypassLimit bool) (_ *config.IndexConfiguration, hints []config.IndexJobHint, err error)
|
||||
UpdateIndexConfigurationByRepositoryID(ctx context.Context, repositoryID int, data []byte) (err error)
|
||||
|
||||
// Tags
|
||||
GetListTags(ctx context.Context, repo api.RepoName, commitObjs ...string) (_ []*gitdomain.Tag, err error)
|
||||
|
||||
// Utilities
|
||||
GetUnsafeDB() database.DB
|
||||
ListFiles(ctx context.Context, repositoryID int, commit string, pattern *regexp.Regexp) ([]string, error)
|
||||
|
||||
// Symbols client
|
||||
GetSupportedByCtags(ctx context.Context, filepath string, repoName api.RepoName) (bool, string, error)
|
||||
|
||||
// Language Support
|
||||
GetLanguagesRequestedBy(ctx context.Context, userID int) (_ []string, err error)
|
||||
SetRequestLanguageSupport(ctx context.Context, userID int, language string) (err error)
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
store store.Store
|
||||
uploadSvc shared.UploadService
|
||||
gitserverClient shared.GitserverClient
|
||||
symbolsClient *symbols.Client
|
||||
repoUpdater shared.RepoUpdaterClient
|
||||
inferenceService shared.InferenceService
|
||||
operations *operations
|
||||
@ -57,6 +79,7 @@ func newService(
|
||||
store store.Store,
|
||||
uploadSvc shared.UploadService,
|
||||
gitserver shared.GitserverClient,
|
||||
symbolsClient *symbols.Client,
|
||||
repoUpdater shared.RepoUpdaterClient,
|
||||
inferenceSvc shared.InferenceService,
|
||||
observationContext *observation.Context,
|
||||
@ -65,6 +88,7 @@ func newService(
|
||||
store: store,
|
||||
uploadSvc: uploadSvc,
|
||||
gitserverClient: gitserver,
|
||||
symbolsClient: symbolsClient,
|
||||
repoUpdater: repoUpdater,
|
||||
inferenceService: inferenceSvc,
|
||||
operations: newOperations(observationContext),
|
||||
@ -72,21 +96,21 @@ func newService(
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) GetIndexes(ctx context.Context, opts shared.GetIndexesOptions) (_ []shared.Index, _ int, err error) {
|
||||
func (s *Service) GetIndexes(ctx context.Context, opts types.GetIndexesOptions) (_ []types.Index, _ int, err error) {
|
||||
ctx, _, endObservation := s.operations.getIndexes.With(ctx, &err, observation.Args{})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
return s.store.GetIndexes(ctx, opts)
|
||||
}
|
||||
|
||||
func (s *Service) GetIndexByID(ctx context.Context, id int) (_ shared.Index, _ bool, err error) {
|
||||
func (s *Service) GetIndexByID(ctx context.Context, id int) (_ types.Index, _ bool, err error) {
|
||||
ctx, _, endObservation := s.operations.getIndexByID.With(ctx, &err, observation.Args{})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
return s.store.GetIndexByID(ctx, id)
|
||||
}
|
||||
|
||||
func (s *Service) GetIndexesByIDs(ctx context.Context, ids ...int) (_ []shared.Index, err error) {
|
||||
func (s *Service) GetIndexesByIDs(ctx context.Context, ids ...int) (_ []types.Index, err error) {
|
||||
ctx, _, endObservation := s.operations.getIndexesByIDs.With(ctx, &err, observation.Args{})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
@ -203,6 +227,58 @@ func (s *Service) UpdateIndexConfigurationByRepositoryID(ctx context.Context, re
|
||||
return s.store.UpdateIndexConfigurationByRepositoryID(ctx, repositoryID, data)
|
||||
}
|
||||
|
||||
func (s *Service) GetUnsafeDB() database.DB {
|
||||
return s.store.GetUnsafeDB()
|
||||
}
|
||||
|
||||
func (s *Service) ListFiles(ctx context.Context, repositoryID int, commit string, pattern *regexp.Regexp) ([]string, error) {
|
||||
return s.gitserverClient.ListFiles(ctx, repositoryID, commit, pattern)
|
||||
}
|
||||
|
||||
func (s *Service) GetSupportedByCtags(ctx context.Context, filepath string, repoName api.RepoName) (bool, string, error) {
|
||||
mappings, err := s.symbolsClient.ListLanguageMappings(ctx, repoName)
|
||||
if err != nil {
|
||||
return false, "", err
|
||||
}
|
||||
|
||||
for language, globs := range mappings {
|
||||
for _, glob := range globs {
|
||||
if glob.Match(filepath) {
|
||||
return true, language, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false, "", nil
|
||||
}
|
||||
|
||||
func (s *Service) SetRequestLanguageSupport(ctx context.Context, userID int, language string) (err error) {
|
||||
ctx, _, endObservation := s.operations.setRequestLanguageSupport.With(ctx, &err, observation.Args{
|
||||
LogFields: []traceLog.Field{traceLog.Int("userID", userID), traceLog.String("language", language)},
|
||||
})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
return s.store.SetRequestLanguageSupport(ctx, userID, language)
|
||||
}
|
||||
|
||||
func (s *Service) GetLanguagesRequestedBy(ctx context.Context, userID int) (_ []string, err error) {
|
||||
ctx, _, endObservation := s.operations.getLanguagesRequestedBy.With(ctx, &err, observation.Args{
|
||||
LogFields: []traceLog.Field{traceLog.Int("userID", userID)},
|
||||
})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
return s.store.GetLanguagesRequestedBy(ctx, userID)
|
||||
}
|
||||
|
||||
func (s *Service) GetListTags(ctx context.Context, repo api.RepoName, commitObjs ...string) (_ []*gitdomain.Tag, err error) {
|
||||
ctx, _, endObservation := s.operations.getListTags.With(ctx, &err, observation.Args{
|
||||
LogFields: []traceLog.Field{traceLog.String("repo", string(repo)), traceLog.String("commitObjs", fmt.Sprintf("%v", commitObjs))},
|
||||
})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
return s.gitserverClient.ListTags(ctx, repo, commitObjs...)
|
||||
}
|
||||
|
||||
func (s *Service) QueueRepoRev(ctx context.Context, repositoryID int, rev string) (err error) {
|
||||
ctx, _, endObservation := s.operations.queueRepoRev.With(ctx, &err, observation.Args{
|
||||
LogFields: []otlog.Field{
|
||||
@ -256,7 +332,7 @@ func (s *Service) ProcessRepoRevs(ctx context.Context, batchSize int) (err error
|
||||
// If the force flag is false, then the presence of an upload or index record for this given repository and commit
|
||||
// will cause this method to no-op. Note that this is NOT a guarantee that there will never be any duplicate records
|
||||
// when the flag is false.
|
||||
func (s *Service) QueueIndexes(ctx context.Context, repositoryID int, rev, configuration string, force, bypassLimit bool) (_ []shared.Index, err error) {
|
||||
func (s *Service) QueueIndexes(ctx context.Context, repositoryID int, rev, configuration string, force, bypassLimit bool) (_ []types.Index, err error) {
|
||||
ctx, trace, endObservation := s.operations.queueIndex.With(ctx, &err, observation.Args{
|
||||
LogFields: []otlog.Field{
|
||||
otlog.Int("repositoryID", repositoryID),
|
||||
@ -321,7 +397,7 @@ func (s *Service) QueueIndexesForPackage(ctx context.Context, pkg precise.Packag
|
||||
// If the force flag is false, then the presence of an upload or index record for this given repository and commit
|
||||
// will cause this method to no-op. Note that this is NOT a guarantee that there will never be any duplicate records
|
||||
// when the flag is false.
|
||||
func (s *Service) queueIndexForRepositoryAndCommit(ctx context.Context, repositoryID int, commit, configuration string, force, bypassLimit bool, trace observation.TraceLogger) ([]shared.Index, error) {
|
||||
func (s *Service) queueIndexForRepositoryAndCommit(ctx context.Context, repositoryID int, commit, configuration string, force, bypassLimit bool, trace observation.TraceLogger) ([]types.Index, error) {
|
||||
if !force {
|
||||
isQueued, err := s.store.IsQueued(ctx, repositoryID, commit)
|
||||
if err != nil {
|
||||
@ -380,16 +456,16 @@ func (s *Service) inferIndexJobHintsFromRepositoryStructure(ctx context.Context,
|
||||
return indexes, nil
|
||||
}
|
||||
|
||||
type configurationFactoryFunc func(ctx context.Context, repositoryID int, commit string, bypassLimit bool) ([]shared.Index, bool, error)
|
||||
type configurationFactoryFunc func(ctx context.Context, repositoryID int, commit string, bypassLimit bool) ([]types.Index, bool, error)
|
||||
|
||||
// getIndexRecords determines the set of index records that should be enqueued for the given commit.
|
||||
// For each repository, we look for index configuration in the following order:
|
||||
//
|
||||
// - supplied explicitly via parameter
|
||||
// - in the database
|
||||
// - committed to `sourcegraph.yaml` in the repository
|
||||
// - inferred from the repository structure
|
||||
func (s *Service) getIndexRecords(ctx context.Context, repositoryID int, commit, configuration string, bypassLimit bool) ([]shared.Index, error) {
|
||||
// - supplied explicitly via parameter
|
||||
// - in the database
|
||||
// - committed to `sourcegraph.yaml` in the repository
|
||||
// - inferred from the repository structure
|
||||
func (s *Service) getIndexRecords(ctx context.Context, repositoryID int, commit, configuration string, bypassLimit bool) ([]types.Index, error) {
|
||||
fns := []configurationFactoryFunc{
|
||||
makeExplicitConfigurationFactory(configuration),
|
||||
s.getIndexRecordsFromConfigurationInDatabase,
|
||||
@ -413,7 +489,7 @@ func (s *Service) getIndexRecords(ctx context.Context, repositoryID int, commit,
|
||||
// flag is returned.
|
||||
func makeExplicitConfigurationFactory(configuration string) configurationFactoryFunc {
|
||||
logger := log.Scoped("explicitConfigurationFactory", "")
|
||||
return func(ctx context.Context, repositoryID int, commit string, _ bool) ([]shared.Index, bool, error) {
|
||||
return func(ctx context.Context, repositoryID int, commit string, _ bool) ([]types.Index, bool, error) {
|
||||
if configuration == "" {
|
||||
return nil, false, nil
|
||||
}
|
||||
@ -433,7 +509,7 @@ func makeExplicitConfigurationFactory(configuration string) configurationFactory
|
||||
|
||||
// getIndexRecordsFromConfigurationInDatabase returns a set of index jobs configured via the UI for
|
||||
// the given repository. If no jobs are configured via the UI then a false valued flag is returned.
|
||||
func (s *Service) getIndexRecordsFromConfigurationInDatabase(ctx context.Context, repositoryID int, commit string, _ bool) ([]shared.Index, bool, error) {
|
||||
func (s *Service) getIndexRecordsFromConfigurationInDatabase(ctx context.Context, repositoryID int, commit string, _ bool) ([]types.Index, bool, error) {
|
||||
indexConfigurationRecord, ok, err := s.store.GetIndexConfigurationByRepositoryID(ctx, repositoryID)
|
||||
if err != nil {
|
||||
return nil, false, errors.Wrap(err, "dbstore.GetIndexConfigurationByRepositoryID")
|
||||
@ -457,7 +533,7 @@ func (s *Service) getIndexRecordsFromConfigurationInDatabase(ctx context.Context
|
||||
// getIndexRecordsFromConfigurationInRepository returns a set of index jobs configured via a committed
|
||||
// configuration file at the given commit. If no jobs are configured within the repository then a false
|
||||
// valued flag is returned.
|
||||
func (s *Service) getIndexRecordsFromConfigurationInRepository(ctx context.Context, repositoryID int, commit string, _ bool) ([]shared.Index, bool, error) {
|
||||
func (s *Service) getIndexRecordsFromConfigurationInRepository(ctx context.Context, repositoryID int, commit string, _ bool) ([]types.Index, bool, error) {
|
||||
isConfigured, err := s.gitserverClient.FileExists(ctx, repositoryID, commit, "sourcegraph.yaml")
|
||||
if err != nil {
|
||||
return nil, false, errors.Wrap(err, "gitserver.FileExists")
|
||||
@ -486,7 +562,7 @@ func (s *Service) getIndexRecordsFromConfigurationInRepository(ctx context.Conte
|
||||
// inferIndexRecordsFromRepositoryStructure looks at the repository contents at the given commit and
|
||||
// determines a set of index jobs that are likely to succeed. If no jobs could be inferred then a
|
||||
// false valued flag is returned.
|
||||
func (s *Service) inferIndexRecordsFromRepositoryStructure(ctx context.Context, repositoryID int, commit string, bypassLimit bool) ([]shared.Index, bool, error) {
|
||||
func (s *Service) inferIndexRecordsFromRepositoryStructure(ctx context.Context, repositoryID int, commit string, bypassLimit bool) ([]types.Index, bool, error) {
|
||||
indexJobs, err := s.inferIndexJobsFromRepositoryStructure(ctx, repositoryID, commit, bypassLimit)
|
||||
if err != nil || len(indexJobs) == 0 {
|
||||
return nil, false, err
|
||||
@ -497,25 +573,25 @@ func (s *Service) inferIndexRecordsFromRepositoryStructure(ctx context.Context,
|
||||
|
||||
// convertIndexConfiguration converts an index configuration object into a set of index records to be
|
||||
// inserted into the database.
|
||||
func convertIndexConfiguration(repositoryID int, commit string, indexConfiguration config.IndexConfiguration) (indexes []shared.Index) {
|
||||
func convertIndexConfiguration(repositoryID int, commit string, indexConfiguration config.IndexConfiguration) (indexes []types.Index) {
|
||||
for _, indexJob := range indexConfiguration.IndexJobs {
|
||||
var dockerSteps []shared.DockerStep
|
||||
var dockerSteps []types.DockerStep
|
||||
for _, dockerStep := range indexConfiguration.SharedSteps {
|
||||
dockerSteps = append(dockerSteps, shared.DockerStep{
|
||||
dockerSteps = append(dockerSteps, types.DockerStep{
|
||||
Root: dockerStep.Root,
|
||||
Image: dockerStep.Image,
|
||||
Commands: dockerStep.Commands,
|
||||
})
|
||||
}
|
||||
for _, dockerStep := range indexJob.Steps {
|
||||
dockerSteps = append(dockerSteps, shared.DockerStep{
|
||||
dockerSteps = append(dockerSteps, types.DockerStep{
|
||||
Root: dockerStep.Root,
|
||||
Image: dockerStep.Image,
|
||||
Commands: dockerStep.Commands,
|
||||
})
|
||||
}
|
||||
|
||||
indexes = append(indexes, shared.Index{
|
||||
indexes = append(indexes, types.Index{
|
||||
Commit: commit,
|
||||
RepositoryID: repositoryID,
|
||||
State: "queued",
|
||||
@ -533,18 +609,18 @@ func convertIndexConfiguration(repositoryID int, commit string, indexConfigurati
|
||||
|
||||
// convertInferredConfiguration converts a set of index jobs into a set of index records to be inserted
|
||||
// into the database.
|
||||
func convertInferredConfiguration(repositoryID int, commit string, indexJobs []config.IndexJob) (indexes []shared.Index) {
|
||||
func convertInferredConfiguration(repositoryID int, commit string, indexJobs []config.IndexJob) (indexes []types.Index) {
|
||||
for _, indexJob := range indexJobs {
|
||||
var dockerSteps []shared.DockerStep
|
||||
var dockerSteps []types.DockerStep
|
||||
for _, dockerStep := range indexJob.Steps {
|
||||
dockerSteps = append(dockerSteps, shared.DockerStep{
|
||||
dockerSteps = append(dockerSteps, types.DockerStep{
|
||||
Root: dockerStep.Root,
|
||||
Image: dockerStep.Image,
|
||||
Commands: dockerStep.Commands,
|
||||
})
|
||||
}
|
||||
|
||||
indexes = append(indexes, shared.Index{
|
||||
indexes = append(indexes, types.Index{
|
||||
RepositoryID: repositoryID,
|
||||
Commit: commit,
|
||||
State: "queued",
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared"
|
||||
types "github.com/sourcegraph/sourcegraph/internal/codeintel/types"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/grafana/regexp"
|
||||
@ -57,7 +58,7 @@ func TestQueueIndexesExplicit(t *testing.T) {
|
||||
}`
|
||||
|
||||
mockDBStore := NewMockStore()
|
||||
mockDBStore.InsertIndexesFunc.SetDefaultHook(func(ctx context.Context, indexes []shared.Index) ([]shared.Index, error) { return indexes, nil })
|
||||
mockDBStore.InsertIndexesFunc.SetDefaultHook(func(ctx context.Context, indexes []types.Index) ([]types.Index, error) { return indexes, nil })
|
||||
mockGitserverClient := NewMockGitserverClient()
|
||||
mockGitserverClient.ResolveRevisionFunc.SetDefaultHook(func(ctx context.Context, repositoryID int, rev string) (api.CommitID, error) {
|
||||
return api.CommitID(fmt.Sprintf("c%d", repositoryID)), nil
|
||||
@ -65,7 +66,7 @@ func TestQueueIndexesExplicit(t *testing.T) {
|
||||
mockUploadSvc := NewMockUploadService()
|
||||
inferenceService := NewMockInferenceService()
|
||||
|
||||
scheduler := newService(mockDBStore, mockUploadSvc, mockGitserverClient, nil, inferenceService, &observation.TestContext)
|
||||
scheduler := newService(mockDBStore, mockUploadSvc, mockGitserverClient, nil, nil, inferenceService, &observation.TestContext)
|
||||
_, _ = scheduler.QueueIndexes(context.Background(), 42, "HEAD", config, false, false)
|
||||
|
||||
if len(mockDBStore.IsQueuedFunc.History()) != 1 {
|
||||
@ -82,17 +83,17 @@ func TestQueueIndexesExplicit(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
var indexes []shared.Index
|
||||
var indexes []types.Index
|
||||
for _, call := range mockDBStore.InsertIndexesFunc.History() {
|
||||
indexes = append(indexes, call.Result0...)
|
||||
}
|
||||
|
||||
expectedIndexes := []shared.Index{
|
||||
expectedIndexes := []types.Index{
|
||||
{
|
||||
RepositoryID: 42,
|
||||
Commit: "c42",
|
||||
State: "queued",
|
||||
DockerSteps: []shared.DockerStep{
|
||||
DockerSteps: []types.DockerStep{
|
||||
{
|
||||
Root: "/",
|
||||
Image: "node:12",
|
||||
@ -110,7 +111,7 @@ func TestQueueIndexesExplicit(t *testing.T) {
|
||||
RepositoryID: 42,
|
||||
Commit: "c42",
|
||||
State: "queued",
|
||||
DockerSteps: []shared.DockerStep{
|
||||
DockerSteps: []types.DockerStep{
|
||||
{
|
||||
Root: "/",
|
||||
Image: "node:12",
|
||||
@ -165,7 +166,7 @@ func TestQueueIndexesInDatabase(t *testing.T) {
|
||||
}
|
||||
|
||||
mockDBStore := NewMockStore()
|
||||
mockDBStore.InsertIndexesFunc.SetDefaultHook(func(ctx context.Context, indexes []shared.Index) ([]shared.Index, error) { return indexes, nil })
|
||||
mockDBStore.InsertIndexesFunc.SetDefaultHook(func(ctx context.Context, indexes []types.Index) ([]types.Index, error) { return indexes, nil })
|
||||
mockDBStore.GetIndexConfigurationByRepositoryIDFunc.SetDefaultReturn(indexConfiguration, true, nil)
|
||||
|
||||
mockGitserverClient := NewMockGitserverClient()
|
||||
@ -175,7 +176,7 @@ func TestQueueIndexesInDatabase(t *testing.T) {
|
||||
mockUploadSvc := NewMockUploadService()
|
||||
inferenceService := NewMockInferenceService()
|
||||
|
||||
scheduler := newService(mockDBStore, mockUploadSvc, mockGitserverClient, nil, inferenceService, &observation.TestContext)
|
||||
scheduler := newService(mockDBStore, mockUploadSvc, mockGitserverClient, nil, nil, inferenceService, &observation.TestContext)
|
||||
_, _ = scheduler.QueueIndexes(context.Background(), 42, "HEAD", "", false, false)
|
||||
|
||||
if len(mockDBStore.GetIndexConfigurationByRepositoryIDFunc.History()) != 1 {
|
||||
@ -206,17 +207,17 @@ func TestQueueIndexesInDatabase(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
var indexes []shared.Index
|
||||
var indexes []types.Index
|
||||
for _, call := range mockDBStore.InsertIndexesFunc.History() {
|
||||
indexes = append(indexes, call.Result0...)
|
||||
}
|
||||
|
||||
expectedIndexes := []shared.Index{
|
||||
expectedIndexes := []types.Index{
|
||||
{
|
||||
RepositoryID: 42,
|
||||
Commit: "c42",
|
||||
State: "queued",
|
||||
DockerSteps: []shared.DockerStep{
|
||||
DockerSteps: []types.DockerStep{
|
||||
{
|
||||
Root: "/",
|
||||
Image: "node:12",
|
||||
@ -234,7 +235,7 @@ func TestQueueIndexesInDatabase(t *testing.T) {
|
||||
RepositoryID: 42,
|
||||
Commit: "c42",
|
||||
State: "queued",
|
||||
DockerSteps: []shared.DockerStep{
|
||||
DockerSteps: []types.DockerStep{
|
||||
{
|
||||
Root: "/",
|
||||
Image: "node:12",
|
||||
@ -277,7 +278,7 @@ index_jobs:
|
||||
|
||||
func TestQueueIndexesInRepository(t *testing.T) {
|
||||
mockDBStore := NewMockStore()
|
||||
mockDBStore.InsertIndexesFunc.SetDefaultHook(func(ctx context.Context, indexes []shared.Index) ([]shared.Index, error) { return indexes, nil })
|
||||
mockDBStore.InsertIndexesFunc.SetDefaultHook(func(ctx context.Context, indexes []types.Index) ([]types.Index, error) { return indexes, nil })
|
||||
|
||||
mockGitserverClient := NewMockGitserverClient()
|
||||
mockGitserverClient.ResolveRevisionFunc.SetDefaultHook(func(ctx context.Context, repositoryID int, rev string) (api.CommitID, error) {
|
||||
@ -290,7 +291,7 @@ func TestQueueIndexesInRepository(t *testing.T) {
|
||||
mockUploadSvc := NewMockUploadService()
|
||||
inferenceService := NewMockInferenceService()
|
||||
|
||||
scheduler := newService(mockDBStore, mockUploadSvc, mockGitserverClient, nil, inferenceService, &observation.TestContext)
|
||||
scheduler := newService(mockDBStore, mockUploadSvc, mockGitserverClient, nil, nil, inferenceService, &observation.TestContext)
|
||||
|
||||
if _, err := scheduler.QueueIndexes(context.Background(), 42, "HEAD", "", false, false); err != nil {
|
||||
t.Fatalf("unexpected error performing update: %s", err)
|
||||
@ -310,17 +311,17 @@ func TestQueueIndexesInRepository(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
var indexes []shared.Index
|
||||
var indexes []types.Index
|
||||
for _, call := range mockDBStore.InsertIndexesFunc.History() {
|
||||
indexes = append(indexes, call.Result0...)
|
||||
}
|
||||
|
||||
expectedIndexes := []shared.Index{
|
||||
expectedIndexes := []types.Index{
|
||||
{
|
||||
RepositoryID: 42,
|
||||
Commit: "c42",
|
||||
State: "queued",
|
||||
DockerSteps: []shared.DockerStep{
|
||||
DockerSteps: []types.DockerStep{
|
||||
{
|
||||
Root: "/",
|
||||
Image: "node:12",
|
||||
@ -338,7 +339,7 @@ func TestQueueIndexesInRepository(t *testing.T) {
|
||||
RepositoryID: 42,
|
||||
Commit: "c42",
|
||||
State: "queued",
|
||||
DockerSteps: []shared.DockerStep{
|
||||
DockerSteps: []types.DockerStep{
|
||||
{
|
||||
Root: "/",
|
||||
Image: "node:12",
|
||||
@ -358,7 +359,7 @@ func TestQueueIndexesInRepository(t *testing.T) {
|
||||
|
||||
func TestQueueIndexesInferred(t *testing.T) {
|
||||
mockDBStore := NewMockStore()
|
||||
mockDBStore.InsertIndexesFunc.SetDefaultHook(func(ctx context.Context, indexes []shared.Index) ([]shared.Index, error) { return indexes, nil })
|
||||
mockDBStore.InsertIndexesFunc.SetDefaultHook(func(ctx context.Context, indexes []types.Index) ([]types.Index, error) { return indexes, nil })
|
||||
|
||||
mockGitserverClient := NewMockGitserverClient()
|
||||
mockGitserverClient.ResolveRevisionFunc.SetDefaultHook(func(ctx context.Context, repositoryID int, rev string) (api.CommitID, error) {
|
||||
@ -388,7 +389,7 @@ func TestQueueIndexesInferred(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
scheduler := newService(mockDBStore, mockUploadSvc, mockGitserverClient, nil, inferenceService, &observation.TestContext)
|
||||
scheduler := newService(mockDBStore, mockUploadSvc, mockGitserverClient, nil, nil, inferenceService, &observation.TestContext)
|
||||
|
||||
for _, id := range []int{41, 42, 43, 44} {
|
||||
if _, err := scheduler.QueueIndexes(context.Background(), id, "HEAD", "", false, false); err != nil {
|
||||
@ -428,7 +429,7 @@ func TestQueueIndexesInferred(t *testing.T) {
|
||||
|
||||
func TestQueueIndexesInferredTooLarge(t *testing.T) {
|
||||
mockDBStore := NewMockStore()
|
||||
mockDBStore.InsertIndexesFunc.SetDefaultHook(func(ctx context.Context, indexes []shared.Index) ([]shared.Index, error) { return indexes, nil })
|
||||
mockDBStore.InsertIndexesFunc.SetDefaultHook(func(ctx context.Context, indexes []types.Index) ([]types.Index, error) { return indexes, nil })
|
||||
|
||||
var paths []string
|
||||
for i := 0; i < 25; i++ {
|
||||
@ -450,7 +451,7 @@ func TestQueueIndexesInferredTooLarge(t *testing.T) {
|
||||
inferenceService := NewMockInferenceService()
|
||||
|
||||
maximumIndexJobsPerInferredConfiguration = 20
|
||||
scheduler := newService(mockDBStore, mockUploadSvc, mockGitserverClient, nil, inferenceService, &observation.TestContext)
|
||||
scheduler := newService(mockDBStore, mockUploadSvc, mockGitserverClient, nil, nil, inferenceService, &observation.TestContext)
|
||||
|
||||
if _, err := scheduler.QueueIndexes(context.Background(), 42, "HEAD", "", false, false); err != nil {
|
||||
t.Fatalf("unexpected error performing update: %s", err)
|
||||
@ -463,7 +464,7 @@ func TestQueueIndexesInferredTooLarge(t *testing.T) {
|
||||
|
||||
func TestQueueIndexesForPackage(t *testing.T) {
|
||||
mockDBStore := NewMockStore()
|
||||
mockDBStore.InsertIndexesFunc.SetDefaultHook(func(ctx context.Context, indexes []shared.Index) ([]shared.Index, error) { return indexes, nil })
|
||||
mockDBStore.InsertIndexesFunc.SetDefaultHook(func(ctx context.Context, indexes []types.Index) ([]types.Index, error) { return indexes, nil })
|
||||
mockDBStore.IsQueuedFunc.SetDefaultReturn(false, nil)
|
||||
|
||||
mockGitserverClient := NewMockGitserverClient()
|
||||
@ -503,7 +504,7 @@ func TestQueueIndexesForPackage(t *testing.T) {
|
||||
}, nil
|
||||
})
|
||||
|
||||
scheduler := newService(mockDBStore, mockUploadSvc, mockGitserverClient, mockRepoUpdater, inferenceService, &observation.TestContext)
|
||||
scheduler := newService(mockDBStore, mockUploadSvc, mockGitserverClient, nil, mockRepoUpdater, inferenceService, &observation.TestContext)
|
||||
|
||||
_ = scheduler.QueueIndexesForPackage(context.Background(), precise.Package{
|
||||
Scheme: "gomod",
|
||||
@ -528,17 +529,17 @@ func TestQueueIndexesForPackage(t *testing.T) {
|
||||
if len(mockDBStore.InsertIndexesFunc.History()) != 1 {
|
||||
t.Errorf("unexpected number of calls to InsertIndexes. want=%d have=%d", 1, len(mockDBStore.InsertIndexesFunc.History()))
|
||||
} else {
|
||||
var indexes []shared.Index
|
||||
var indexes []types.Index
|
||||
for _, call := range mockDBStore.InsertIndexesFunc.History() {
|
||||
indexes = append(indexes, call.Result0...)
|
||||
}
|
||||
|
||||
expectedIndexes := []shared.Index{
|
||||
expectedIndexes := []types.Index{
|
||||
{
|
||||
RepositoryID: 42,
|
||||
Commit: "c42",
|
||||
State: "queued",
|
||||
DockerSteps: []shared.DockerStep{
|
||||
DockerSteps: []types.DockerStep{
|
||||
{
|
||||
Image: "sourcegraph/lsif-go:latest",
|
||||
Commands: []string{"go mod download"},
|
||||
|
||||
@ -6,6 +6,8 @@ import (
|
||||
"github.com/grafana/regexp"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/types"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain"
|
||||
"github.com/sourcegraph/sourcegraph/internal/repoupdater/protocol"
|
||||
"github.com/sourcegraph/sourcegraph/lib/codeintel/autoindex/config"
|
||||
)
|
||||
@ -21,6 +23,7 @@ type GitserverClient interface {
|
||||
FileExists(ctx context.Context, repositoryID int, commit, file string) (bool, error)
|
||||
RawContents(ctx context.Context, repositoryID int, commit, file string) ([]byte, error)
|
||||
ResolveRevision(ctx context.Context, repositoryID int, versionString string) (api.CommitID, error)
|
||||
ListTags(ctx context.Context, repo api.RepoName, commitObjs ...string) (_ []*gitdomain.Tag, err error)
|
||||
}
|
||||
|
||||
type InferenceService interface {
|
||||
@ -29,6 +32,7 @@ type InferenceService interface {
|
||||
}
|
||||
|
||||
type UploadService interface {
|
||||
GetRepoName(ctx context.Context, repositoryID int) (_ string, err error) // upload service
|
||||
GetDirtyRepositories(ctx context.Context) (_ map[int]int, err error) // upload service
|
||||
GetRepoName(ctx context.Context, repositoryID int) (_ string, err error) // upload service
|
||||
GetDirtyRepositories(ctx context.Context) (_ map[int]int, err error) // upload service
|
||||
GetUploadsByIDs(ctx context.Context, ids ...int) (_ []types.Upload, err error) // upload service
|
||||
}
|
||||
|
||||
@ -1,12 +1,9 @@
|
||||
package shared
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/workerutil"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/types"
|
||||
)
|
||||
|
||||
type IndexJob struct {
|
||||
@ -19,82 +16,6 @@ type SourcedCommits struct {
|
||||
Commits []string
|
||||
}
|
||||
|
||||
// Index is a subset of the lsif_indexes table and stores both processed and unprocessed
|
||||
// records.
|
||||
type Index struct {
|
||||
ID int `json:"id"`
|
||||
Commit string `json:"commit"`
|
||||
QueuedAt time.Time `json:"queuedAt"`
|
||||
State string `json:"state"`
|
||||
FailureMessage *string `json:"failureMessage"`
|
||||
StartedAt *time.Time `json:"startedAt"`
|
||||
FinishedAt *time.Time `json:"finishedAt"`
|
||||
ProcessAfter *time.Time `json:"processAfter"`
|
||||
NumResets int `json:"numResets"`
|
||||
NumFailures int `json:"numFailures"`
|
||||
RepositoryID int `json:"repositoryId"`
|
||||
LocalSteps []string `json:"local_steps"`
|
||||
RepositoryName string `json:"repositoryName"`
|
||||
DockerSteps []DockerStep `json:"docker_steps"`
|
||||
Root string `json:"root"`
|
||||
Indexer string `json:"indexer"`
|
||||
IndexerArgs []string `json:"indexer_args"` // TODO - convert this to `IndexCommand string`
|
||||
Outfile string `json:"outfile"`
|
||||
ExecutionLogs []ExecutionLogEntry `json:"execution_logs"`
|
||||
Rank *int `json:"placeInQueue"`
|
||||
AssociatedUploadID *int `json:"associatedUpload"`
|
||||
}
|
||||
|
||||
type DockerStep struct {
|
||||
Root string `json:"root"`
|
||||
Image string `json:"image"`
|
||||
Commands []string `json:"commands"`
|
||||
}
|
||||
|
||||
func (s *DockerStep) Scan(value any) error {
|
||||
b, ok := value.([]byte)
|
||||
if !ok {
|
||||
return errors.Errorf("value is not []byte: %T", value)
|
||||
}
|
||||
|
||||
return json.Unmarshal(b, &s)
|
||||
}
|
||||
|
||||
func (s DockerStep) Value() (driver.Value, error) {
|
||||
return json.Marshal(s)
|
||||
}
|
||||
|
||||
// ExecutionLogEntry represents a command run by the executor.
|
||||
type ExecutionLogEntry struct {
|
||||
Key string `json:"key"`
|
||||
Command []string `json:"command"`
|
||||
StartTime time.Time `json:"startTime"`
|
||||
ExitCode *int `json:"exitCode,omitempty"`
|
||||
Out string `json:"out,omitempty"`
|
||||
DurationMs *int `json:"durationMs,omitempty"`
|
||||
}
|
||||
|
||||
func (e *ExecutionLogEntry) Scan(value any) error {
|
||||
b, ok := value.([]byte)
|
||||
if !ok {
|
||||
return errors.Errorf("value is not []byte: %T", value)
|
||||
}
|
||||
|
||||
return json.Unmarshal(b, &e)
|
||||
}
|
||||
|
||||
func (e ExecutionLogEntry) Value() (driver.Value, error) {
|
||||
return json.Marshal(e)
|
||||
}
|
||||
|
||||
func ExecutionLogEntries(raw []workerutil.ExecutionLogEntry) (entries []ExecutionLogEntry) {
|
||||
for _, entry := range raw {
|
||||
entries = append(entries, ExecutionLogEntry(entry))
|
||||
}
|
||||
|
||||
return entries
|
||||
}
|
||||
|
||||
// IndexConfiguration stores the index configuration for a repository.
|
||||
type IndexConfiguration struct {
|
||||
ID int `json:"id"`
|
||||
@ -102,16 +23,51 @@ type IndexConfiguration struct {
|
||||
Data []byte `json:"data"`
|
||||
}
|
||||
|
||||
type GetIndexesOptions struct {
|
||||
RepositoryID int
|
||||
State string
|
||||
Term string
|
||||
Limit int
|
||||
Offset int
|
||||
}
|
||||
|
||||
type IndexesWithRepositoryNamespace struct {
|
||||
Root string
|
||||
Indexer string
|
||||
Indexes []Index
|
||||
Indexes []types.Index
|
||||
}
|
||||
|
||||
// UploadLocation is a path and range pair from within a particular upload. The target commit
|
||||
// denotes the target commit for which the location was set (the originally requested commit).
|
||||
type UploadLocation struct {
|
||||
Dump Dump
|
||||
Path string
|
||||
TargetCommit string
|
||||
TargetRange Range
|
||||
}
|
||||
|
||||
// Dump is a subset of the lsif_uploads table (queried via the lsif_dumps_with_repository_name view)
|
||||
// and stores only processed records.
|
||||
type Dump struct {
|
||||
ID int `json:"id"`
|
||||
Commit string `json:"commit"`
|
||||
Root string `json:"root"`
|
||||
VisibleAtTip bool `json:"visibleAtTip"`
|
||||
UploadedAt time.Time `json:"uploadedAt"`
|
||||
State string `json:"state"`
|
||||
FailureMessage *string `json:"failureMessage"`
|
||||
StartedAt *time.Time `json:"startedAt"`
|
||||
FinishedAt *time.Time `json:"finishedAt"`
|
||||
ProcessAfter *time.Time `json:"processAfter"`
|
||||
NumResets int `json:"numResets"`
|
||||
NumFailures int `json:"numFailures"`
|
||||
RepositoryID int `json:"repositoryId"`
|
||||
RepositoryName string `json:"repositoryName"`
|
||||
Indexer string `json:"indexer"`
|
||||
IndexerVersion string `json:"indexerVersion"`
|
||||
AssociatedIndexID *int `json:"associatedIndex"`
|
||||
}
|
||||
|
||||
// Range is an inclusive bounds within a file.
|
||||
type Range struct {
|
||||
Start Position
|
||||
End Position
|
||||
}
|
||||
|
||||
// Position is a unique position within a file.
|
||||
type Position struct {
|
||||
Line int
|
||||
Character int
|
||||
}
|
||||
|
||||
@ -5,29 +5,32 @@ import (
|
||||
|
||||
"github.com/opentracing/opentracing-go/log"
|
||||
|
||||
gql "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
"github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/codeintel/resolvers"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
)
|
||||
|
||||
type codeIntelSupportResolver struct {
|
||||
repo api.RepoName
|
||||
path string
|
||||
resolver resolvers.Resolver
|
||||
errTracer *observation.ErrCollector
|
||||
type GitBlobCodeIntelSupportResolver interface {
|
||||
SearchBasedSupport(context.Context) (SearchBasedSupportResolver, error)
|
||||
PreciseSupport(context.Context) (PreciseSupportResolver, error)
|
||||
}
|
||||
|
||||
func NewCodeIntelSupportResolver(resolver resolvers.Resolver, repoName api.RepoName, path string, errTracer *observation.ErrCollector) gql.GitBlobCodeIntelSupportResolver {
|
||||
type codeIntelSupportResolver struct {
|
||||
repo api.RepoName
|
||||
path string
|
||||
autoindexSvc AutoIndexingService
|
||||
errTracer *observation.ErrCollector
|
||||
}
|
||||
|
||||
func NewCodeIntelSupportResolver(autoindexSvc AutoIndexingService, repoName api.RepoName, path string, errTracer *observation.ErrCollector) GitBlobCodeIntelSupportResolver {
|
||||
return &codeIntelSupportResolver{
|
||||
repo: repoName,
|
||||
path: path,
|
||||
resolver: resolver,
|
||||
errTracer: errTracer,
|
||||
repo: repoName,
|
||||
path: path,
|
||||
autoindexSvc: autoindexSvc,
|
||||
errTracer: errTracer,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *codeIntelSupportResolver) SearchBasedSupport(ctx context.Context) (_ gql.SearchBasedSupportResolver, err error) {
|
||||
func (r *codeIntelSupportResolver) SearchBasedSupport(ctx context.Context) (_ SearchBasedSupportResolver, err error) {
|
||||
var (
|
||||
ctagsSupported bool
|
||||
language string
|
||||
@ -40,8 +43,7 @@ func (r *codeIntelSupportResolver) SearchBasedSupport(ctx context.Context) (_ gq
|
||||
log.Bool("ctagsSupported", ctagsSupported))
|
||||
}()
|
||||
|
||||
codeNavResolver := r.resolver.CodeNavResolver()
|
||||
ctagsSupported, language, err = codeNavResolver.GetSupportedByCtags(ctx, r.path, r.repo)
|
||||
ctagsSupported, language, err = r.autoindexSvc.GetSupportedByCtags(ctx, r.path, r.repo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -53,6 +55,6 @@ func (r *codeIntelSupportResolver) SearchBasedSupport(ctx context.Context) (_ gq
|
||||
return NewSearchBasedCodeIntelResolver(language), nil
|
||||
}
|
||||
|
||||
func (r *codeIntelSupportResolver) PreciseSupport(ctx context.Context) (gql.PreciseSupportResolver, error) {
|
||||
func (r *codeIntelSupportResolver) PreciseSupport(ctx context.Context) (PreciseSupportResolver, error) {
|
||||
return NewPreciseCodeIntelSupportResolver(r.path), nil
|
||||
}
|
||||
@ -0,0 +1,115 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
codeinteltypes "github.com/sourcegraph/sourcegraph/internal/codeintel/types"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/codeintel/autoindex/config"
|
||||
)
|
||||
|
||||
type GitTreeCodeIntelSupportResolver interface {
|
||||
SearchBasedSupport(context.Context) (*[]GitTreeSearchBasedCoverage, error)
|
||||
PreciseSupport(context.Context) (*[]GitTreePreciseCoverage, error)
|
||||
}
|
||||
|
||||
type preciseSupportInferenceConfidence string
|
||||
|
||||
const (
|
||||
languageSupport preciseSupportInferenceConfidence = "LANGUAGE_SUPPORTED"
|
||||
projectStructureSupported preciseSupportInferenceConfidence = "PROJECT_STRUCTURE_SUPPORTED"
|
||||
indexJobInfered preciseSupportInferenceConfidence = "INDEX_JOB_INFERED"
|
||||
)
|
||||
|
||||
type codeIntelTreeInfoResolver struct {
|
||||
autoindexSvc AutoIndexingService
|
||||
commit string
|
||||
path string
|
||||
files []string
|
||||
repo *types.Repo
|
||||
errTracer *observation.ErrCollector
|
||||
}
|
||||
|
||||
func NewCodeIntelTreeInfoResolver(autoindexSvc AutoIndexingService, repo *types.Repo, commit, path string, files []string, errTracer *observation.ErrCollector) GitTreeCodeIntelSupportResolver {
|
||||
return &codeIntelTreeInfoResolver{
|
||||
autoindexSvc: autoindexSvc,
|
||||
repo: repo,
|
||||
commit: commit,
|
||||
path: path,
|
||||
files: files,
|
||||
errTracer: errTracer,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *codeIntelTreeInfoResolver) SearchBasedSupport(ctx context.Context) (*[]GitTreeSearchBasedCoverage, error) {
|
||||
langMapping := make(map[string][]string)
|
||||
for _, file := range r.files {
|
||||
ok, lang, err := r.autoindexSvc.GetSupportedByCtags(ctx, file, r.repo.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if ok {
|
||||
langMapping[lang] = append(langMapping[lang], file)
|
||||
}
|
||||
}
|
||||
|
||||
resolvers := make([]GitTreeSearchBasedCoverage, 0, len(langMapping))
|
||||
|
||||
for lang, files := range langMapping {
|
||||
resolvers = append(resolvers, &codeIntelTreeSearchBasedCoverageResolver{
|
||||
paths: files,
|
||||
language: lang,
|
||||
})
|
||||
}
|
||||
|
||||
return &resolvers, nil
|
||||
}
|
||||
|
||||
func (r *codeIntelTreeInfoResolver) PreciseSupport(ctx context.Context) (*[]GitTreePreciseCoverage, error) {
|
||||
configurations, _, err := r.autoindexSvc.InferIndexConfiguration(ctx, int(r.repo.ID), r.commit, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resolvers []GitTreePreciseCoverage
|
||||
|
||||
if configurations != nil {
|
||||
for _, job := range configurations.IndexJobs {
|
||||
if job.Root == r.path {
|
||||
resolvers = append(resolvers, &codeIntelTreePreciseCoverageResolver{
|
||||
confidence: indexJobInfered,
|
||||
// drop the tag if it exists
|
||||
indexer: codeinteltypes.ImageToIndexer[strings.Split(job.Indexer, ":")[0]],
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_, hints, err := r.autoindexSvc.InferIndexConfiguration(ctx, int(r.repo.ID), r.commit, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, hint := range hints {
|
||||
if hint.Root == r.path {
|
||||
var confidence preciseSupportInferenceConfidence
|
||||
switch hint.HintConfidence {
|
||||
case config.HintConfidenceLanguageSupport:
|
||||
confidence = languageSupport
|
||||
case config.HintConfidenceProjectStructureSupported:
|
||||
confidence = projectStructureSupported
|
||||
default:
|
||||
continue
|
||||
}
|
||||
resolvers = append(resolvers, &codeIntelTreePreciseCoverageResolver{
|
||||
confidence: confidence,
|
||||
// expected that job hints don't include a tag in the indexer name
|
||||
indexer: codeinteltypes.ImageToIndexer[hint.Indexer],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return &resolvers, nil
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/types"
|
||||
)
|
||||
|
||||
type GitTreePreciseCoverage interface {
|
||||
Support() PreciseSupportResolver
|
||||
Confidence() string
|
||||
}
|
||||
|
||||
type codeIntelTreePreciseCoverageResolver struct {
|
||||
confidence preciseSupportInferenceConfidence
|
||||
indexer types.CodeIntelIndexerResolver
|
||||
}
|
||||
|
||||
func (r *codeIntelTreePreciseCoverageResolver) Support() PreciseSupportResolver {
|
||||
return NewPreciseCodeIntelSupportResolverFromIndexers([]types.CodeIntelIndexerResolver{r.indexer})
|
||||
}
|
||||
|
||||
func (r *codeIntelTreePreciseCoverageResolver) Confidence() string {
|
||||
return string(r.confidence)
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package graphql
|
||||
|
||||
type GitTreeSearchBasedCoverage interface {
|
||||
CoveredPaths() []string
|
||||
Support() SearchBasedSupportResolver
|
||||
}
|
||||
|
||||
type codeIntelTreeSearchBasedCoverageResolver struct {
|
||||
paths []string
|
||||
language string
|
||||
}
|
||||
|
||||
func (r *codeIntelTreeSearchBasedCoverageResolver) CoveredPaths() []string {
|
||||
return r.paths
|
||||
}
|
||||
|
||||
func (r *codeIntelTreeSearchBasedCoverageResolver) Support() SearchBasedSupportResolver {
|
||||
return NewSearchBasedCodeIntelResolver(r.language)
|
||||
}
|
||||
53
internal/codeintel/autoindexing/transport/graphql/iface.go
Normal file
53
internal/codeintel/autoindexing/transport/graphql/iface.go
Normal file
@ -0,0 +1,53 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/regexp"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/types"
|
||||
uploadshared "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain"
|
||||
"github.com/sourcegraph/sourcegraph/lib/codeintel/autoindex/config"
|
||||
)
|
||||
|
||||
type AutoIndexingService interface {
|
||||
GetIndexConfigurationByRepositoryID(ctx context.Context, repositoryID int) (_ shared.IndexConfiguration, _ bool, err error)
|
||||
GetIndexes(ctx context.Context, opts types.GetIndexesOptions) (_ []types.Index, _ int, err error)
|
||||
GetIndexByID(ctx context.Context, id int) (_ types.Index, _ bool, err error)
|
||||
GetIndexesByIDs(ctx context.Context, ids ...int) (_ []types.Index, err error)
|
||||
GetRecentIndexesSummary(ctx context.Context, repositoryID int) (summaries []shared.IndexesWithRepositoryNamespace, err error)
|
||||
GetLastIndexScanForRepository(ctx context.Context, repositoryID int) (_ *time.Time, err error)
|
||||
UpdateIndexConfigurationByRepositoryID(ctx context.Context, repositoryID int, data []byte) (err error)
|
||||
DeleteIndexByID(ctx context.Context, id int) (_ bool, err error)
|
||||
|
||||
InferIndexConfiguration(ctx context.Context, repositoryID int, commit string, bypassLimit bool) (_ *config.IndexConfiguration, hints []config.IndexJobHint, err error)
|
||||
QueueIndexes(ctx context.Context, repositoryID int, rev, configuration string, force, bypassLimit bool) (_ []types.Index, err error)
|
||||
|
||||
GetListTags(ctx context.Context, repo api.RepoName, commitObjs ...string) (_ []*gitdomain.Tag, err error)
|
||||
ListFiles(ctx context.Context, repositoryID int, commit string, pattern *regexp.Regexp) ([]string, error)
|
||||
|
||||
GetSupportedByCtags(ctx context.Context, filepath string, repoName api.RepoName) (bool, string, error)
|
||||
GetLanguagesRequestedBy(ctx context.Context, userID int) (_ []string, err error)
|
||||
SetRequestLanguageSupport(ctx context.Context, userID int, language string) (err error)
|
||||
|
||||
GetUnsafeDB() database.DB
|
||||
}
|
||||
|
||||
type UploadsService interface {
|
||||
GetLastUploadRetentionScanForRepository(ctx context.Context, repositoryID int) (_ *time.Time, err error)
|
||||
GetRecentUploadsSummary(ctx context.Context, repositoryID int) (upload []uploadshared.UploadsWithRepositoryNamespace, err error)
|
||||
GetUploads(ctx context.Context, opts types.GetUploadsOptions) (uploads []types.Upload, totalCount int, err error)
|
||||
GetAuditLogsForUpload(ctx context.Context, uploadID int) (_ []types.UploadLog, err error)
|
||||
GetListTags(ctx context.Context, repo api.RepoName, commitObjs ...string) (_ []*gitdomain.Tag, err error)
|
||||
GetUploadDocumentsForPath(ctx context.Context, bundleID int, pathPattern string) ([]string, int, error)
|
||||
GetUploadsByIDs(ctx context.Context, ids ...int) (_ []types.Upload, err error)
|
||||
}
|
||||
|
||||
type PolicyService interface {
|
||||
GetRetentionPolicyOverview(ctx context.Context, upload types.Upload, matchesOnly bool, first int, after int64, query string, now time.Time) (matches []types.RetentionPolicyMatchCandidate, totalCount int, err error)
|
||||
}
|
||||
@ -7,30 +7,32 @@ import (
|
||||
|
||||
"github.com/opentracing/opentracing-go/log"
|
||||
|
||||
gql "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
"github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/codeintel/resolvers"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
"github.com/sourcegraph/sourcegraph/lib/codeintel/autoindex/config"
|
||||
)
|
||||
|
||||
type IndexConfigurationResolver struct {
|
||||
resolver resolvers.Resolver
|
||||
type IndexConfigurationResolver interface {
|
||||
Configuration(ctx context.Context) (*string, error)
|
||||
InferredConfiguration(ctx context.Context) (*string, error)
|
||||
}
|
||||
|
||||
type indexConfigurationResolver struct {
|
||||
autoindexSvc AutoIndexingService
|
||||
repositoryID int
|
||||
errTracer *observation.ErrCollector
|
||||
}
|
||||
|
||||
func NewIndexConfigurationResolver(resolver resolvers.Resolver, repositoryID int, errTracer *observation.ErrCollector) gql.IndexConfigurationResolver {
|
||||
return &IndexConfigurationResolver{
|
||||
resolver: resolver,
|
||||
func NewIndexConfigurationResolver(autoindexSvc AutoIndexingService, repositoryID int, errTracer *observation.ErrCollector) IndexConfigurationResolver {
|
||||
return &indexConfigurationResolver{
|
||||
autoindexSvc: autoindexSvc,
|
||||
repositoryID: repositoryID,
|
||||
errTracer: errTracer,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *IndexConfigurationResolver) Configuration(ctx context.Context) (_ *string, err error) {
|
||||
func (r *indexConfigurationResolver) Configuration(ctx context.Context) (_ *string, err error) {
|
||||
defer r.errTracer.Collect(&err, log.String("indexConfigResolver.field", "configuration"))
|
||||
autoIndexingResolver := r.resolver.AutoIndexingResolver()
|
||||
configuration, exists, err := autoIndexingResolver.GetIndexConfiguration(ctx, r.repositoryID)
|
||||
configuration, exists, err := r.autoindexSvc.GetIndexConfigurationByRepositoryID(ctx, r.repositoryID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -38,17 +40,16 @@ func (r *IndexConfigurationResolver) Configuration(ctx context.Context) (_ *stri
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return strPtr(string(configuration)), nil
|
||||
return strPtr(string(configuration.Data)), nil
|
||||
}
|
||||
|
||||
func (r *IndexConfigurationResolver) InferredConfiguration(ctx context.Context) (_ *string, err error) {
|
||||
func (r *indexConfigurationResolver) InferredConfiguration(ctx context.Context) (_ *string, err error) {
|
||||
defer r.errTracer.Collect(&err, log.String("indexConfigResolver.field", "inferredConfiguration"))
|
||||
autoIndexingResolver := r.resolver.AutoIndexingResolver()
|
||||
configuration, exists, err := autoIndexingResolver.InferedIndexConfiguration(ctx, r.repositoryID, "")
|
||||
configuration, _, err := r.autoindexSvc.InferIndexConfiguration(ctx, r.repositoryID, "", true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !exists {
|
||||
if configuration == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
3266
internal/codeintel/autoindexing/transport/graphql/mocks_temp.go
Normal file
3266
internal/codeintel/autoindexing/transport/graphql/mocks_temp.go
Normal file
File diff suppressed because it is too large
Load Diff
@ -9,18 +9,29 @@ import (
|
||||
|
||||
type operations struct {
|
||||
// Indexes
|
||||
getIndexByID *observation.Operation
|
||||
getIndexesByIDs *observation.Operation
|
||||
getRecentIndexesSummary *observation.Operation
|
||||
getLastIndexScanForRepository *observation.Operation
|
||||
deleteIndexByID *observation.Operation
|
||||
deleteLsifIndexes *observation.Operation
|
||||
queueAutoIndexJobsForRepo *observation.Operation
|
||||
lsifIndexByID *observation.Operation
|
||||
lsifIndexes *observation.Operation
|
||||
lsifIndexesByRepo *observation.Operation
|
||||
indexConfiguration *observation.Operation
|
||||
updateIndexConfiguration *observation.Operation
|
||||
|
||||
// Index Configuration
|
||||
getIndexConfiguration *observation.Operation
|
||||
updateIndexConfigurationByRepositoryID *observation.Operation
|
||||
inferedIndexConfiguration *observation.Operation
|
||||
inferedIndexConfigurationHints *observation.Operation
|
||||
inferedIndexConfiguration *observation.Operation
|
||||
inferedIndexConfigurationHints *observation.Operation
|
||||
|
||||
// Language Support
|
||||
requestLanguageSupport *observation.Operation
|
||||
requestedLanguageSupport *observation.Operation
|
||||
setRequestLanguageSupport *observation.Operation
|
||||
|
||||
// Misc
|
||||
repositorySummary *observation.Operation
|
||||
getSupportedByCtags *observation.Operation
|
||||
gitBlobCodeIntelInfo *observation.Operation
|
||||
}
|
||||
|
||||
func newOperations(observationContext *observation.Context) *operations {
|
||||
@ -41,17 +52,28 @@ func newOperations(observationContext *observation.Context) *operations {
|
||||
|
||||
return &operations{
|
||||
// Indexes
|
||||
getIndexByID: op("GetIndexByID"),
|
||||
getIndexesByIDs: op("GetIndexesByIDs"),
|
||||
getRecentIndexesSummary: op("GetRecentIndexesSummary"),
|
||||
getLastIndexScanForRepository: op("GetLastIndexScanForRepository"),
|
||||
deleteIndexByID: op("DeleteIndexByID"),
|
||||
queueAutoIndexJobsForRepo: op("QueueAutoIndexJobsForRepo"),
|
||||
deleteLsifIndexes: op("DeleteLsifIndexes"),
|
||||
lsifIndexByID: op("LsifIndexByID"),
|
||||
lsifIndexes: op("LsifIndexes"),
|
||||
lsifIndexesByRepo: op("LsifIndexesByRepo"),
|
||||
indexConfiguration: op("IndexConfiguration"),
|
||||
updateIndexConfiguration: op("UpdateIndexConfiguration"),
|
||||
|
||||
// Index Configuration
|
||||
getIndexConfiguration: op("IndexConfiguration"),
|
||||
updateIndexConfigurationByRepositoryID: op("UpdateIndexConfigurationByRepositoryID"),
|
||||
inferedIndexConfiguration: op("InferedIndexConfiguration"),
|
||||
inferedIndexConfigurationHints: op("InferedIndexConfigurationHints"),
|
||||
inferedIndexConfiguration: op("InferedIndexConfiguration"),
|
||||
inferedIndexConfigurationHints: op("InferedIndexConfigurationHints"),
|
||||
|
||||
// Language Support
|
||||
requestLanguageSupport: op("RequestLanguageSupport"),
|
||||
requestedLanguageSupport: op("RequestedLanguageSupport"),
|
||||
setRequestLanguageSupport: op("SetRequestLanguageSupport"),
|
||||
|
||||
// Misc
|
||||
repositorySummary: op("RepositorySummary"),
|
||||
getSupportedByCtags: op("GetSupportedByCtags"),
|
||||
gitBlobCodeIntelInfo: op("GitBlobCodeIntelInfo"),
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,58 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/types"
|
||||
)
|
||||
|
||||
type PreciseSupportResolver interface {
|
||||
SupportLevel() string
|
||||
Indexers() *[]types.CodeIntelIndexerResolver
|
||||
}
|
||||
|
||||
type preciseCodeIntelSupportType string
|
||||
|
||||
const (
|
||||
native preciseCodeIntelSupportType = "NATIVE"
|
||||
thirdParty preciseCodeIntelSupportType = "THIRD_PARTY"
|
||||
unknown preciseCodeIntelSupportType = "UNKNOWN"
|
||||
)
|
||||
|
||||
type preciseCodeIntelSupportResolver struct {
|
||||
indexers []types.CodeIntelIndexerResolver
|
||||
}
|
||||
|
||||
func NewPreciseCodeIntelSupportResolver(filepath string) PreciseSupportResolver {
|
||||
return &preciseCodeIntelSupportResolver{
|
||||
indexers: types.LanguageToIndexer[path.Ext(filepath)],
|
||||
}
|
||||
}
|
||||
|
||||
func NewPreciseCodeIntelSupportResolverFromIndexers(indexers []types.CodeIntelIndexerResolver) PreciseSupportResolver {
|
||||
return &preciseCodeIntelSupportResolver{
|
||||
indexers: indexers,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *preciseCodeIntelSupportResolver) SupportLevel() string {
|
||||
// if the first indexer in a list is from us, consider native support
|
||||
nativeRecommendation := len(r.indexers) > 0 &&
|
||||
strings.HasPrefix(r.indexers[0].URL(), "https://github.com/sourcegraph")
|
||||
|
||||
if nativeRecommendation {
|
||||
return string(native)
|
||||
} else if len(r.indexers) > 0 {
|
||||
return string(thirdParty)
|
||||
} else {
|
||||
return string(unknown)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *preciseCodeIntelSupportResolver) Indexers() *[]types.CodeIntelIndexerResolver {
|
||||
if len(r.indexers) == 0 {
|
||||
return nil
|
||||
}
|
||||
return &r.indexers
|
||||
}
|
||||
@ -1,161 +0,0 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/opentracing/opentracing-go/log"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
"github.com/sourcegraph/sourcegraph/lib/codeintel/autoindex/config"
|
||||
)
|
||||
|
||||
type Resolver interface {
|
||||
// Indexes
|
||||
GetIndexByID(ctx context.Context, id int) (shared.Index, bool, error) // simple dbstore
|
||||
GetIndexesByIDs(ctx context.Context, ids ...int) ([]shared.Index, error) // simple dbstore
|
||||
GetRecentIndexesSummary(ctx context.Context, repositoryID int) (summaries []shared.IndexesWithRepositoryNamespace, err error)
|
||||
GetLastIndexScanForRepository(ctx context.Context, repositoryID int) (_ *time.Time, err error)
|
||||
DeleteIndexByID(ctx context.Context, id int) error // simple dbstore
|
||||
QueueAutoIndexJobsForRepo(ctx context.Context, repositoryID int, rev, configuration string) ([]shared.Index, error) // in the service QueueIndexes
|
||||
|
||||
// Index Configuration
|
||||
GetIndexConfiguration(ctx context.Context, repositoryID int) ([]byte, bool, error) // GetIndexConfigurationByRepositoryID
|
||||
InferedIndexConfiguration(ctx context.Context, repositoryID int, commit string) (*config.IndexConfiguration, bool, error) // in the service InferIndexConfiguration first return
|
||||
InferedIndexConfigurationHints(ctx context.Context, repositoryID int, commit string) ([]config.IndexJobHint, error) // in the service InferIndexConfiguration second return
|
||||
UpdateIndexConfigurationByRepositoryID(ctx context.Context, repositoryID int, configuration string) error // simple dbstore
|
||||
|
||||
// Index Connection Factory
|
||||
IndexConnectionResolverFromFactory(opts shared.GetIndexesOptions) *IndexesResolver // for the resolver
|
||||
}
|
||||
|
||||
type resolver struct {
|
||||
svc *autoindexing.Service
|
||||
operations *operations
|
||||
}
|
||||
|
||||
func New(svc *autoindexing.Service, observationContext *observation.Context) Resolver {
|
||||
return &resolver{
|
||||
svc: svc,
|
||||
operations: newOperations(observationContext),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *resolver) GetIndexByID(ctx context.Context, id int) (_ shared.Index, _ bool, err error) {
|
||||
ctx, _, endObservation := r.operations.getIndexByID.With(ctx, &err, observation.Args{
|
||||
LogFields: []log.Field{log.Int("id", id)},
|
||||
})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
return r.svc.GetIndexByID(ctx, id)
|
||||
}
|
||||
|
||||
func (r *resolver) GetIndexesByIDs(ctx context.Context, ids ...int) (_ []shared.Index, err error) {
|
||||
ctx, _, endObservation := r.operations.getIndexesByIDs.With(ctx, &err, observation.Args{
|
||||
LogFields: []log.Field{log.Int("totalIds", len(ids))},
|
||||
})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
return r.svc.GetIndexesByIDs(ctx, ids...)
|
||||
}
|
||||
|
||||
func (r *resolver) GetRecentIndexesSummary(ctx context.Context, repositoryID int) (summaries []shared.IndexesWithRepositoryNamespace, err error) {
|
||||
ctx, _, endObservation := r.operations.getRecentIndexesSummary.With(ctx, &err, observation.Args{
|
||||
LogFields: []log.Field{log.Int("repositoryID", repositoryID)},
|
||||
})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
return r.svc.GetRecentIndexesSummary(ctx, repositoryID)
|
||||
}
|
||||
|
||||
func (r *resolver) GetLastIndexScanForRepository(ctx context.Context, repositoryID int) (_ *time.Time, err error) {
|
||||
ctx, _, endObservation := r.operations.getLastIndexScanForRepository.With(ctx, &err, observation.Args{
|
||||
LogFields: []log.Field{log.Int("repositoryID", repositoryID)},
|
||||
})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
return r.svc.GetLastIndexScanForRepository(ctx, repositoryID)
|
||||
}
|
||||
|
||||
func (r *resolver) DeleteIndexByID(ctx context.Context, id int) (err error) {
|
||||
ctx, _, endObservation := r.operations.deleteIndexByID.With(ctx, &err, observation.Args{
|
||||
LogFields: []log.Field{log.Int("id", id)},
|
||||
})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
_, err = r.svc.DeleteIndexByID(ctx, id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *resolver) QueueAutoIndexJobsForRepo(ctx context.Context, repositoryID int, rev, configuration string) (_ []shared.Index, err error) {
|
||||
ctx, _, endObservation := r.operations.queueAutoIndexJobsForRepo.With(ctx, &err, observation.Args{
|
||||
LogFields: []log.Field{log.Int("repositoryID", repositoryID), log.String("rev", rev), log.String("configuration", configuration)},
|
||||
})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
return r.svc.QueueIndexes(ctx, repositoryID, rev, configuration, true, true)
|
||||
}
|
||||
|
||||
func (r *resolver) GetIndexConfiguration(ctx context.Context, repositoryID int) (_ []byte, _ bool, err error) {
|
||||
ctx, _, endObservation := r.operations.getIndexConfiguration.With(ctx, &err, observation.Args{
|
||||
LogFields: []log.Field{log.Int("repositoryID", repositoryID)},
|
||||
})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
configuration, exists, err := r.svc.GetIndexConfigurationByRepositoryID(ctx, repositoryID)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
if !exists {
|
||||
return nil, false, nil
|
||||
}
|
||||
|
||||
return configuration.Data, true, nil
|
||||
}
|
||||
|
||||
func (r *resolver) InferedIndexConfiguration(ctx context.Context, repositoryID int, commit string) (_ *config.IndexConfiguration, _ bool, err error) {
|
||||
ctx, _, endObservation := r.operations.inferedIndexConfiguration.With(ctx, &err, observation.Args{
|
||||
LogFields: []log.Field{log.Int("repositoryID", repositoryID), log.String("commit", commit)},
|
||||
})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
maybeConfig, _, err := r.svc.InferIndexConfiguration(ctx, repositoryID, commit, true)
|
||||
if err != nil || maybeConfig == nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
return maybeConfig, true, nil
|
||||
}
|
||||
|
||||
func (r *resolver) InferedIndexConfigurationHints(ctx context.Context, repositoryID int, commit string) (_ []config.IndexJobHint, err error) {
|
||||
ctx, _, endObservation := r.operations.inferedIndexConfigurationHints.With(ctx, &err, observation.Args{
|
||||
LogFields: []log.Field{log.Int("repositoryID", repositoryID), log.String("commit", commit)},
|
||||
})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
_, hints, err := r.svc.InferIndexConfiguration(ctx, repositoryID, commit, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return hints, nil
|
||||
}
|
||||
|
||||
func (r *resolver) UpdateIndexConfigurationByRepositoryID(ctx context.Context, repositoryID int, configuration string) (err error) {
|
||||
ctx, _, endObservation := r.operations.updateIndexConfigurationByRepositoryID.With(ctx, &err, observation.Args{
|
||||
LogFields: []log.Field{log.Int("repositoryID", repositoryID), log.String("configuration", configuration)},
|
||||
})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
if _, err := config.UnmarshalJSON([]byte(configuration)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return r.svc.UpdateIndexConfigurationByRepositoryID(ctx, repositoryID, []byte(configuration))
|
||||
}
|
||||
|
||||
func (r *resolver) IndexConnectionResolverFromFactory(opts shared.GetIndexesOptions) *IndexesResolver {
|
||||
return NewIndexesResolver(r.svc, opts)
|
||||
}
|
||||
@ -0,0 +1,464 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/regexp"
|
||||
"github.com/graph-gophers/graphql-go"
|
||||
"github.com/opentracing/opentracing-go/log"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/backend"
|
||||
"github.com/sourcegraph/sourcegraph/internal/actor"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/sharedresolvers"
|
||||
resolvers "github.com/sourcegraph/sourcegraph/internal/codeintel/sharedresolvers"
|
||||
"github.com/sourcegraph/sourcegraph/internal/conf"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/codeintel/autoindex/config"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
)
|
||||
|
||||
type RootResolver interface {
|
||||
// Mirrors AutoindexingServiceResolver in graphqlbackend
|
||||
IndexConfiguration(ctx context.Context, id graphql.ID) (IndexConfigurationResolver, error) // TODO - rename ...ForRepo
|
||||
DeleteLSIFIndex(ctx context.Context, args *struct{ ID graphql.ID }) (*resolvers.EmptyResponse, error)
|
||||
LSIFIndexByID(ctx context.Context, id graphql.ID) (_ resolvers.LSIFIndexResolver, err error)
|
||||
LSIFIndexes(ctx context.Context, args *LSIFIndexesQueryArgs) (resolvers.LSIFIndexConnectionResolver, error)
|
||||
LSIFIndexesByRepo(ctx context.Context, args *LSIFRepositoryIndexesQueryArgs) (resolvers.LSIFIndexConnectionResolver, error)
|
||||
QueueAutoIndexJobsForRepo(ctx context.Context, args *QueueAutoIndexJobsForRepoArgs) ([]resolvers.LSIFIndexResolver, error)
|
||||
UpdateRepositoryIndexConfiguration(ctx context.Context, args *UpdateRepositoryIndexConfigurationArgs) (*resolvers.EmptyResponse, error)
|
||||
RepositorySummary(ctx context.Context, id graphql.ID) (_ resolvers.CodeIntelRepositorySummaryResolver, err error)
|
||||
GitBlobCodeIntelInfo(ctx context.Context, args *GitTreeEntryCodeIntelInfoArgs) (_ GitBlobCodeIntelSupportResolver, err error)
|
||||
GitTreeCodeIntelInfo(ctx context.Context, args *GitTreeEntryCodeIntelInfoArgs) (resolver GitTreeCodeIntelSupportResolver, err error)
|
||||
RequestLanguageSupport(ctx context.Context, args *RequestLanguageSupportArgs) (_ *sharedresolvers.EmptyResponse, err error)
|
||||
RequestedLanguageSupport(ctx context.Context) (_ []string, err error)
|
||||
|
||||
// AutoIndexing
|
||||
GetRecentIndexesSummary(ctx context.Context, repositoryID int) (summaries []shared.IndexesWithRepositoryNamespace, err error)
|
||||
GetLastIndexScanForRepository(ctx context.Context, repositoryID int) (_ *time.Time, err error)
|
||||
InferedIndexConfiguration(ctx context.Context, repositoryID int, commit string) (_ *config.IndexConfiguration, _ bool, err error)
|
||||
InferedIndexConfigurationHints(ctx context.Context, repositoryID int, commit string) (_ []config.IndexJobHint, err error)
|
||||
|
||||
// Symbols client
|
||||
GetSupportedByCtags(ctx context.Context, filepath string, repoName api.RepoName) (bool, string, error)
|
||||
}
|
||||
|
||||
type rootResolver struct {
|
||||
autoindexSvc AutoIndexingService
|
||||
uploadSvc UploadsService
|
||||
policySvc PolicyService
|
||||
operations *operations
|
||||
}
|
||||
|
||||
func NewRootResolver(autoindexSvc AutoIndexingService, uploadSvc UploadsService, policySvc PolicyService, observationContext *observation.Context) RootResolver {
|
||||
return &rootResolver{
|
||||
autoindexSvc: autoindexSvc,
|
||||
uploadSvc: uploadSvc,
|
||||
policySvc: policySvc,
|
||||
operations: newOperations(observationContext),
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
autoIndexingEnabled = conf.CodeIntelAutoIndexingEnabled
|
||||
errAutoIndexingNotEnabled = errors.New("precise code intelligence auto-indexing is not enabled")
|
||||
)
|
||||
|
||||
// 🚨 SECURITY: Only entrypoint is within the repository resolver so the user is already authenticated
|
||||
func (r *rootResolver) IndexConfiguration(ctx context.Context, id graphql.ID) (_ IndexConfigurationResolver, err error) {
|
||||
_, traceErrs, endObservation := r.operations.indexConfiguration.WithErrors(ctx, &err, observation.Args{LogFields: []log.Field{
|
||||
log.String("repoID", string(id)),
|
||||
}})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
if !autoIndexingEnabled() {
|
||||
return nil, errAutoIndexingNotEnabled
|
||||
}
|
||||
|
||||
repositoryID, err := UnmarshalRepositoryID(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewIndexConfigurationResolver(r.autoindexSvc, int(repositoryID), traceErrs), nil
|
||||
}
|
||||
|
||||
// 🚨 SECURITY: Only site admins may modify code intelligence index data
|
||||
func (r *rootResolver) DeleteLSIFIndex(ctx context.Context, args *struct{ ID graphql.ID }) (_ *resolvers.EmptyResponse, err error) {
|
||||
ctx, _, endObservation := r.operations.deleteLsifIndexes.With(ctx, &err, observation.Args{LogFields: []log.Field{
|
||||
log.String("indexID", string(args.ID)),
|
||||
}})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
if err := backend.CheckCurrentUserIsSiteAdmin(ctx, r.autoindexSvc.GetUnsafeDB()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !autoIndexingEnabled() {
|
||||
return nil, errAutoIndexingNotEnabled
|
||||
}
|
||||
|
||||
indexID, err := unmarshalLSIFIndexGQLID(args.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := r.autoindexSvc.DeleteIndexByID(ctx, int(indexID)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &resolvers.EmptyResponse{}, nil
|
||||
}
|
||||
|
||||
// 🚨 SECURITY: dbstore layer handles authz for GetIndexByID
|
||||
func (r *rootResolver) LSIFIndexByID(ctx context.Context, id graphql.ID) (_ resolvers.LSIFIndexResolver, err error) {
|
||||
if !autoIndexingEnabled() {
|
||||
return nil, errAutoIndexingNotEnabled
|
||||
}
|
||||
|
||||
ctx, traceErrs, endObservation := r.operations.lsifIndexByID.WithErrors(ctx, &err, observation.Args{LogFields: []log.Field{
|
||||
log.String("indexID", string(id)),
|
||||
}})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
indexID, err := unmarshalLSIFIndexGQLID(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Create a new prefetcher here as we only want to cache upload and index records in
|
||||
// the same graphQL request, not across different request.
|
||||
prefetcher := resolvers.NewPrefetcher(r.autoindexSvc, r.uploadSvc)
|
||||
|
||||
index, exists, err := prefetcher.GetIndexByID(ctx, int(indexID))
|
||||
if err != nil || !exists {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resolvers.NewIndexResolver(r.autoindexSvc, r.uploadSvc, r.policySvc, index, prefetcher, traceErrs), nil
|
||||
}
|
||||
|
||||
type LSIFIndexesQueryArgs struct {
|
||||
ConnectionArgs
|
||||
Query *string
|
||||
State *string
|
||||
After *string
|
||||
}
|
||||
|
||||
type LSIFRepositoryIndexesQueryArgs struct {
|
||||
*LSIFIndexesQueryArgs
|
||||
RepositoryID graphql.ID
|
||||
}
|
||||
|
||||
// 🚨 SECURITY: dbstore layer handles authz for GetIndexes
|
||||
func (r *rootResolver) LSIFIndexes(ctx context.Context, args *LSIFIndexesQueryArgs) (_ resolvers.LSIFIndexConnectionResolver, err error) {
|
||||
if !autoIndexingEnabled() {
|
||||
return nil, errAutoIndexingNotEnabled
|
||||
}
|
||||
|
||||
ctx, _, endObservation := r.operations.lsifIndexes.With(ctx, &err, observation.Args{})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
// Delegate behavior to LSIFIndexesByRepo with no specified repository identifier
|
||||
return r.LSIFIndexesByRepo(ctx, &LSIFRepositoryIndexesQueryArgs{LSIFIndexesQueryArgs: args})
|
||||
}
|
||||
|
||||
// 🚨 SECURITY: dbstore layer handles authz for GetIndexes
|
||||
func (r *rootResolver) LSIFIndexesByRepo(ctx context.Context, args *LSIFRepositoryIndexesQueryArgs) (_ resolvers.LSIFIndexConnectionResolver, err error) {
|
||||
if !autoIndexingEnabled() {
|
||||
return nil, errAutoIndexingNotEnabled
|
||||
}
|
||||
|
||||
ctx, traceErrs, endObservation := r.operations.lsifIndexesByRepo.WithErrors(ctx, &err, observation.Args{LogFields: []log.Field{
|
||||
log.String("repoID", string(args.RepositoryID)),
|
||||
}})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
opts, err := makeGetIndexesOptions(args)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Create a new prefetcher here as we only want to cache upload and index records in
|
||||
// the same graphQL request, not across different request.
|
||||
prefetcher := resolvers.NewPrefetcher(r.autoindexSvc, r.uploadSvc)
|
||||
|
||||
// Create a new indexConnectionResolver here as we only want to index records in
|
||||
// the same graphQL request, not across different request.
|
||||
// indexConnectionResolver := r.resolver.AutoIndexingResolver().IndexConnectionResolverFromFactory(opts)
|
||||
indexConnectionResolver := resolvers.NewIndexesResolver(r.autoindexSvc, opts)
|
||||
|
||||
return resolvers.NewIndexConnectionResolver(r.autoindexSvc, r.uploadSvc, r.policySvc, indexConnectionResolver, prefetcher, traceErrs), nil
|
||||
}
|
||||
|
||||
type QueueAutoIndexJobsForRepoArgs struct {
|
||||
Repository graphql.ID
|
||||
Rev *string
|
||||
Configuration *string
|
||||
}
|
||||
|
||||
// 🚨 SECURITY: Only site admins may queue auto-index jobs
|
||||
func (r *rootResolver) QueueAutoIndexJobsForRepo(ctx context.Context, args *QueueAutoIndexJobsForRepoArgs) (_ []resolvers.LSIFIndexResolver, err error) {
|
||||
ctx, traceErrs, endObservation := r.operations.queueAutoIndexJobsForRepo.WithErrors(ctx, &err, observation.Args{LogFields: []log.Field{
|
||||
log.String("repoID", string(args.Repository)),
|
||||
}})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
if err := backend.CheckCurrentUserIsSiteAdmin(ctx, r.autoindexSvc.GetUnsafeDB()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !autoIndexingEnabled() {
|
||||
return nil, errAutoIndexingNotEnabled
|
||||
}
|
||||
|
||||
repositoryID, err := UnmarshalRepositoryID(args.Repository)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rev := "HEAD"
|
||||
if args.Rev != nil {
|
||||
rev = *args.Rev
|
||||
}
|
||||
|
||||
configuration := ""
|
||||
if args.Configuration != nil {
|
||||
configuration = *args.Configuration
|
||||
}
|
||||
|
||||
// autoindexingResolver := r.resolver.AutoIndexingResolver()
|
||||
// indexes, err := r.autoindexSvc.QueueAutoIndexJobsForRepo(ctx, int(repositoryID), rev, configuration)
|
||||
indexes, err := r.autoindexSvc.QueueIndexes(ctx, int(repositoryID), rev, configuration, true, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Create a new prefetcher here as we only want to cache upload and index records in
|
||||
// the same graphQL request, not across different request.
|
||||
prefetcher := resolvers.NewPrefetcher(r.autoindexSvc, r.uploadSvc)
|
||||
|
||||
lsifIndexResolvers := make([]resolvers.LSIFIndexResolver, 0, len(indexes))
|
||||
for i := range indexes {
|
||||
// index := convertSharedIndexToDBStoreIndex(indexes[i])
|
||||
lsifIndexResolvers = append(lsifIndexResolvers, resolvers.NewIndexResolver(r.autoindexSvc, r.uploadSvc, r.policySvc, indexes[i], prefetcher, traceErrs))
|
||||
}
|
||||
|
||||
return lsifIndexResolvers, nil
|
||||
}
|
||||
|
||||
type UpdateRepositoryIndexConfigurationArgs struct {
|
||||
Repository graphql.ID
|
||||
Configuration string
|
||||
}
|
||||
|
||||
// 🚨 SECURITY: Only site admins may modify code intelligence indexing configuration
|
||||
func (r *rootResolver) UpdateRepositoryIndexConfiguration(ctx context.Context, args *UpdateRepositoryIndexConfigurationArgs) (_ *resolvers.EmptyResponse, err error) {
|
||||
ctx, _, endObservation := r.operations.updateIndexConfiguration.With(ctx, &err, observation.Args{LogFields: []log.Field{
|
||||
log.String("repoID", string(args.Repository)),
|
||||
}})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
if err := backend.CheckCurrentUserIsSiteAdmin(ctx, r.autoindexSvc.GetUnsafeDB()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !autoIndexingEnabled() {
|
||||
return nil, errAutoIndexingNotEnabled
|
||||
}
|
||||
|
||||
repositoryID, err := unmarshalLSIFIndexGQLID(args.Repository)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := config.UnmarshalJSON([]byte(args.Configuration)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := r.autoindexSvc.UpdateIndexConfigurationByRepositoryID(ctx, int(repositoryID), []byte(args.Configuration)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &resolvers.EmptyResponse{}, nil
|
||||
}
|
||||
|
||||
type GitTreeEntryCodeIntelInfoArgs struct {
|
||||
Repo *types.Repo
|
||||
Path string
|
||||
Commit string
|
||||
}
|
||||
|
||||
func (r *rootResolver) GitBlobCodeIntelInfo(ctx context.Context, args *GitTreeEntryCodeIntelInfoArgs) (_ GitBlobCodeIntelSupportResolver, err error) {
|
||||
ctx, errTracer, endObservation := r.operations.gitBlobCodeIntelInfo.WithErrors(ctx, &err, observation.Args{})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
return NewCodeIntelSupportResolver(r.autoindexSvc, args.Repo.Name, args.Path, errTracer), nil
|
||||
}
|
||||
|
||||
func (r *rootResolver) GitTreeCodeIntelInfo(ctx context.Context, args *GitTreeEntryCodeIntelInfoArgs) (resolver GitTreeCodeIntelSupportResolver, err error) {
|
||||
ctx, errTracer, endObservation := r.operations.gitBlobCodeIntelInfo.WithErrors(ctx, &err, observation.Args{LogFields: []log.Field{
|
||||
log.Int("repoID", int(args.Repo.ID)),
|
||||
log.String("path", args.Path),
|
||||
log.String("commit", args.Commit),
|
||||
}})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
filesRegex, err := regexp.Compile("^" + regexp.QuoteMeta(args.Path) + "[^.]{1}[^/]*$")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "path '%s' caused invalid regex", args.Path)
|
||||
}
|
||||
|
||||
files, err := r.autoindexSvc.ListFiles(ctx, int(args.Repo.ID), args.Commit, filesRegex)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "gitserver.ListFiles: error listing files at %s for repo %d", args.Path, args.Repo.ID)
|
||||
}
|
||||
|
||||
return NewCodeIntelTreeInfoResolver(r.autoindexSvc, args.Repo, args.Commit, args.Path, files, errTracer), nil
|
||||
}
|
||||
|
||||
func (r *rootResolver) GetRecentIndexesSummary(ctx context.Context, repositoryID int) (summaries []shared.IndexesWithRepositoryNamespace, err error) {
|
||||
ctx, _, endObservation := r.operations.getRecentIndexesSummary.With(ctx, &err, observation.Args{
|
||||
LogFields: []log.Field{log.Int("repositoryID", repositoryID)},
|
||||
})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
return r.autoindexSvc.GetRecentIndexesSummary(ctx, repositoryID)
|
||||
}
|
||||
|
||||
func (r *rootResolver) GetLastIndexScanForRepository(ctx context.Context, repositoryID int) (_ *time.Time, err error) {
|
||||
ctx, _, endObservation := r.operations.getLastIndexScanForRepository.With(ctx, &err, observation.Args{
|
||||
LogFields: []log.Field{log.Int("repositoryID", repositoryID)},
|
||||
})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
return r.autoindexSvc.GetLastIndexScanForRepository(ctx, repositoryID)
|
||||
}
|
||||
|
||||
func (r *rootResolver) InferedIndexConfiguration(ctx context.Context, repositoryID int, commit string) (_ *config.IndexConfiguration, _ bool, err error) {
|
||||
ctx, _, endObservation := r.operations.inferedIndexConfiguration.With(ctx, &err, observation.Args{
|
||||
LogFields: []log.Field{log.Int("repositoryID", repositoryID), log.String("commit", commit)},
|
||||
})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
maybeConfig, _, err := r.autoindexSvc.InferIndexConfiguration(ctx, repositoryID, commit, true)
|
||||
if err != nil || maybeConfig == nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
return maybeConfig, true, nil
|
||||
}
|
||||
|
||||
func (r *rootResolver) InferedIndexConfigurationHints(ctx context.Context, repositoryID int, commit string) (_ []config.IndexJobHint, err error) {
|
||||
ctx, _, endObservation := r.operations.inferedIndexConfigurationHints.With(ctx, &err, observation.Args{
|
||||
LogFields: []log.Field{log.Int("repositoryID", repositoryID), log.String("commit", commit)},
|
||||
})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
_, hints, err := r.autoindexSvc.InferIndexConfiguration(ctx, repositoryID, commit, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return hints, nil
|
||||
}
|
||||
|
||||
func (r *rootResolver) RepositorySummary(ctx context.Context, id graphql.ID) (_ resolvers.CodeIntelRepositorySummaryResolver, err error) {
|
||||
ctx, errTracer, endObservation := r.operations.repositorySummary.WithErrors(ctx, &err, observation.Args{LogFields: []log.Field{
|
||||
log.String("repoID", string(id)),
|
||||
}})
|
||||
endObservation.OnCancel(ctx, 1, observation.Args{})
|
||||
|
||||
repositoryID, err := UnmarshalRepositoryID(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
repoID := int(repositoryID)
|
||||
|
||||
// uploadResolver := r.resolver.UploadsResolver()
|
||||
recentUploads, err := r.uploadSvc.GetRecentUploadsSummary(ctx, repoID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
lastUploadRetentionScan, err := r.uploadSvc.GetLastUploadRetentionScanForRepository(ctx, repoID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// recentIndexes, err := r.resolver.AutoIndexingRootResolver().GetRecentIndexesSummary(ctx, repoID)
|
||||
recentIndexes, err := r.autoindexSvc.GetRecentIndexesSummary(ctx, repoID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// lastIndexScan, err := r.resolver.AutoIndexingRootResolver().GetLastIndexScanForRepository(ctx, repoID)
|
||||
lastIndexScan, err := r.autoindexSvc.GetLastIndexScanForRepository(ctx, repoID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
summary := sharedresolvers.RepositorySummary{
|
||||
RecentUploads: recentUploads,
|
||||
RecentIndexes: recentIndexes,
|
||||
LastUploadRetentionScan: lastUploadRetentionScan,
|
||||
LastIndexScan: lastIndexScan,
|
||||
}
|
||||
|
||||
// Create a new prefetcher here as we only want to cache upload and index records in
|
||||
// the same graphQL request, not across different request.
|
||||
prefetcher := sharedresolvers.NewPrefetcher(r.autoindexSvc, r.uploadSvc)
|
||||
|
||||
return sharedresolvers.NewRepositorySummaryResolver(r.autoindexSvc, r.uploadSvc, r.policySvc, summary, prefetcher, errTracer), nil
|
||||
}
|
||||
|
||||
// HERE HERE HERE
|
||||
func (r *rootResolver) GetSupportedByCtags(ctx context.Context, filepath string, repoName api.RepoName) (_ bool, _ string, err error) {
|
||||
ctx, _, endObservation := r.operations.getSupportedByCtags.With(ctx, &err, observation.Args{
|
||||
LogFields: []log.Field{log.String("repoName", string(repoName))},
|
||||
})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
return r.autoindexSvc.GetSupportedByCtags(ctx, filepath, repoName)
|
||||
}
|
||||
|
||||
type RequestLanguageSupportArgs struct {
|
||||
Language string
|
||||
}
|
||||
|
||||
func (r *rootResolver) RequestLanguageSupport(ctx context.Context, args *RequestLanguageSupportArgs) (_ *sharedresolvers.EmptyResponse, err error) {
|
||||
ctx, _, endObservation := r.operations.requestLanguageSupport.With(ctx, &err, observation.Args{})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
userID := int(actor.FromContext(ctx).UID)
|
||||
if userID == 0 {
|
||||
return nil, errors.Newf("language support requests only logged for authenticated users")
|
||||
}
|
||||
|
||||
if err := r.autoindexSvc.SetRequestLanguageSupport(ctx, userID, args.Language); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &sharedresolvers.EmptyResponse{}, nil
|
||||
}
|
||||
|
||||
func (r *rootResolver) SetRequestLanguageSupport(ctx context.Context, userID int, language string) (err error) {
|
||||
ctx, _, endObservation := r.operations.setRequestLanguageSupport.With(ctx, &err, observation.Args{
|
||||
LogFields: []log.Field{log.Int("userID", userID), log.String("language", language)},
|
||||
})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
return r.autoindexSvc.SetRequestLanguageSupport(ctx, userID, language)
|
||||
}
|
||||
|
||||
func (r *rootResolver) RequestedLanguageSupport(ctx context.Context) (_ []string, err error) {
|
||||
ctx, _, endObservation := r.operations.requestedLanguageSupport.With(ctx, &err, observation.Args{})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
userID := int(actor.FromContext(ctx).UID)
|
||||
if userID == 0 {
|
||||
return nil, errors.Newf("language support requests only logged for authenticated users")
|
||||
}
|
||||
|
||||
return r.autoindexSvc.GetLanguagesRequestedBy(ctx, userID)
|
||||
}
|
||||
@ -0,0 +1,64 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"testing"
|
||||
|
||||
"github.com/graph-gophers/graphql-go"
|
||||
|
||||
"github.com/sourcegraph/log/logtest"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/backend"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
)
|
||||
|
||||
func init() {
|
||||
autoIndexingEnabled = func() bool { return true }
|
||||
}
|
||||
|
||||
func TestDeleteLSIFIndex(t *testing.T) {
|
||||
users := database.NewStrictMockUserStore()
|
||||
users.GetByCurrentAuthUserFunc.SetDefaultReturn(&types.User{SiteAdmin: true}, nil)
|
||||
|
||||
db := database.NewStrictMockDB()
|
||||
db.UsersFunc.SetDefaultReturn(users)
|
||||
|
||||
id := graphql.ID(base64.StdEncoding.EncodeToString([]byte("LSIFIndex:42")))
|
||||
mockUploadsService := NewMockUploadsService()
|
||||
mockPolicyService := NewMockPolicyService()
|
||||
mockAutoIndexingService := NewMockAutoIndexingService()
|
||||
mockAutoIndexingService.GetUnsafeDBFunc.SetDefaultReturn(db)
|
||||
|
||||
rootResolver := NewRootResolver(mockAutoIndexingService, mockUploadsService, mockPolicyService, &observation.TestContext)
|
||||
|
||||
if _, err := rootResolver.DeleteLSIFIndex(context.Background(), &struct{ ID graphql.ID }{id}); err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
|
||||
if len(mockAutoIndexingService.DeleteIndexByIDFunc.History()) != 1 {
|
||||
t.Fatalf("unexpected call count. want=%d have=%d", 1, len(mockAutoIndexingService.DeleteIndexByIDFunc.History()))
|
||||
}
|
||||
if val := mockAutoIndexingService.DeleteIndexByIDFunc.History()[0].Arg1; val != 42 {
|
||||
t.Fatalf("unexpected upload id. want=%d have=%d", 42, val)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteLSIFIndexUnauthenticated(t *testing.T) {
|
||||
logger := logtest.Scoped(t)
|
||||
db := database.NewDB(logger, nil)
|
||||
|
||||
id := graphql.ID(base64.StdEncoding.EncodeToString([]byte("LSIFIndex:42")))
|
||||
mockUploadsService := NewMockUploadsService()
|
||||
mockPolicyService := NewMockPolicyService()
|
||||
mockAutoIndexingService := NewMockAutoIndexingService()
|
||||
mockAutoIndexingService.GetUnsafeDBFunc.SetDefaultReturn(db)
|
||||
|
||||
rootResolver := NewRootResolver(mockAutoIndexingService, mockUploadsService, mockPolicyService, &observation.TestContext)
|
||||
|
||||
if _, err := rootResolver.DeleteLSIFIndex(context.Background(), &struct{ ID graphql.ID }{id}); err != backend.ErrNotAuthenticated {
|
||||
t.Errorf("unexpected error. want=%q have=%q", backend.ErrNotAuthenticated, err)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
package graphql
|
||||
|
||||
type SearchBasedSupportResolver interface {
|
||||
SupportLevel() string
|
||||
Language() string
|
||||
}
|
||||
|
||||
type searchBasedCodeIntelSupportType string
|
||||
|
||||
const (
|
||||
unsupported searchBasedCodeIntelSupportType = "UNSUPPORTED"
|
||||
basic searchBasedCodeIntelSupportType = "BASIC"
|
||||
)
|
||||
|
||||
type searchBasedSupportResolver struct {
|
||||
language string
|
||||
}
|
||||
|
||||
func NewSearchBasedCodeIntelResolver(language string) SearchBasedSupportResolver {
|
||||
return &searchBasedSupportResolver{language}
|
||||
}
|
||||
|
||||
func (r *searchBasedSupportResolver) SupportLevel() string {
|
||||
if r.language != "" {
|
||||
return string(basic)
|
||||
}
|
||||
return string(unsupported)
|
||||
}
|
||||
|
||||
func (r *searchBasedSupportResolver) Language() string {
|
||||
return r.language
|
||||
}
|
||||
222
internal/codeintel/autoindexing/transport/graphql/utils.go
Normal file
222
internal/codeintel/autoindexing/transport/graphql/utils.go
Normal file
@ -0,0 +1,222 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/graph-gophers/graphql-go"
|
||||
"github.com/graph-gophers/graphql-go/relay"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
)
|
||||
|
||||
// strPtr creates a pointer to the given value. If the value is an
|
||||
// empty string, a nil pointer is returned.
|
||||
func strPtr(val string) *string {
|
||||
if val == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &val
|
||||
}
|
||||
|
||||
// DateTime implements the DateTime GraphQL scalar type.
|
||||
type DateTime struct{ time.Time }
|
||||
|
||||
// DateTimeOrNil is a helper function that returns nil for time == nil and otherwise wraps time in
|
||||
// DateTime.
|
||||
func DateTimeOrNil(time *time.Time) *DateTime {
|
||||
if time == nil {
|
||||
return nil
|
||||
}
|
||||
return &DateTime{Time: *time}
|
||||
}
|
||||
|
||||
func (DateTime) ImplementsGraphQLType(name string) bool {
|
||||
return name == "DateTime"
|
||||
}
|
||||
|
||||
func (v DateTime) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(v.Time.Format(time.RFC3339))
|
||||
}
|
||||
|
||||
func (v *DateTime) UnmarshalGraphQL(input any) error {
|
||||
s, ok := input.(string)
|
||||
if !ok {
|
||||
return errors.Errorf("invalid GraphQL DateTime scalar value input (got %T, expected string)", input)
|
||||
}
|
||||
t, err := time.Parse(time.RFC3339, s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*v = DateTime{Time: t}
|
||||
return nil
|
||||
}
|
||||
|
||||
func marshalLSIFIndexGQLID(indexID int64) graphql.ID {
|
||||
return relay.MarshalID("LSIFIndex", indexID)
|
||||
}
|
||||
|
||||
func unmarshalLSIFIndexGQLID(id graphql.ID) (indexID int64, err error) {
|
||||
err = relay.UnmarshalSpec(id, &indexID)
|
||||
return indexID, err
|
||||
}
|
||||
|
||||
// ConnectionArgs is the common set of arguments to GraphQL fields that return connections (lists).
|
||||
type ConnectionArgs struct {
|
||||
First *int32 // return the first n items
|
||||
}
|
||||
|
||||
const DefaultIndexPageSize = 50
|
||||
|
||||
// makeGetIndexesOptions translates the given GraphQL arguments into options defined by the
|
||||
// store.GetIndexes operations.
|
||||
func makeGetIndexesOptions(args *LSIFRepositoryIndexesQueryArgs) (types.GetIndexesOptions, error) {
|
||||
repositoryID, err := resolveRepositoryID(args.RepositoryID)
|
||||
if err != nil {
|
||||
return types.GetIndexesOptions{}, err
|
||||
}
|
||||
|
||||
offset, err := graphqlutil.DecodeIntCursor(args.After)
|
||||
if err != nil {
|
||||
return types.GetIndexesOptions{}, err
|
||||
}
|
||||
|
||||
return types.GetIndexesOptions{
|
||||
RepositoryID: repositoryID,
|
||||
State: strings.ToLower(derefString(args.State, "")),
|
||||
Term: derefString(args.Query, ""),
|
||||
Limit: derefInt32(args.First, DefaultIndexPageSize),
|
||||
Offset: offset,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// resolveRepositoryByID gets a repository's internal identifier from a GraphQL identifier.
|
||||
func resolveRepositoryID(id graphql.ID) (int, error) {
|
||||
if id == "" {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
repoID, err := UnmarshalRepositoryID(id)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return int(repoID), nil
|
||||
}
|
||||
|
||||
func UnmarshalRepositoryID(id graphql.ID) (repo api.RepoID, err error) {
|
||||
err = relay.UnmarshalSpec(id, &repo)
|
||||
return
|
||||
}
|
||||
|
||||
// EncodeIntCursor creates a PageInfo object from the given new offset value. If the
|
||||
// new offset value, then an object indicating the end of the result set is returned.
|
||||
// The cursor is base64 encoded for transfer, and should be decoded using the function
|
||||
// decodeIntCursor.
|
||||
func EncodeIntCursor(val *int32) *PageInfo {
|
||||
if val == nil {
|
||||
return EncodeCursor(nil)
|
||||
}
|
||||
|
||||
str := strconv.FormatInt(int64(*val), 10)
|
||||
return EncodeCursor(&str)
|
||||
}
|
||||
|
||||
// DecodeIntCursor decodes the given integer cursor value. It is assumed to be a value
|
||||
// previously returned from the function encodeIntCursor. The zero value is returned if
|
||||
// no cursor is supplied. Invalid cursors return errors.
|
||||
func DecodeIntCursor(val *string) (int, error) {
|
||||
cursor, err := DecodeCursor(val)
|
||||
if err != nil || cursor == "" {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return strconv.Atoi(cursor)
|
||||
}
|
||||
|
||||
// DecodeCursor decodes the given cursor value. It is assumed to be a value previously
|
||||
// returned from the function encodeCursor. An empty string is returned if no cursor is
|
||||
// supplied. Invalid cursors return errors.
|
||||
func DecodeCursor(val *string) (string, error) {
|
||||
if val == nil {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
decoded, err := base64.StdEncoding.DecodeString(*val)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(decoded), nil
|
||||
}
|
||||
|
||||
// toInt32 translates the given int pointer into an int32 pointer.
|
||||
func toInt32(val *int) *int32 {
|
||||
if val == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
v := int32(*val)
|
||||
return &v
|
||||
}
|
||||
|
||||
// derefString returns the underlying value in the given pointer.
|
||||
// If the pointer is nil, the default value is returned.
|
||||
func derefString(val *string, defaultValue string) string {
|
||||
if val != nil {
|
||||
return *val
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
// derefInt32 returns the underlying value in the given pointer.
|
||||
// If the pointer is nil, the default value is returned.
|
||||
func derefInt32(val *int32, defaultValue int) int {
|
||||
if val != nil {
|
||||
return int(*val)
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
// intPtr creates a pointer to the given value.
|
||||
func intPtr(val int32) *int32 {
|
||||
return &val
|
||||
}
|
||||
|
||||
// PageInfo implements the GraphQL type PageInfo.
|
||||
type PageInfo struct {
|
||||
endCursor *string
|
||||
hasNextPage bool
|
||||
}
|
||||
|
||||
// HasNextPage returns a new PageInfo with the given hasNextPage value.
|
||||
func HasNextPage(hasNextPage bool) *PageInfo {
|
||||
return &PageInfo{hasNextPage: hasNextPage}
|
||||
}
|
||||
|
||||
// NextPageCursor returns a new PageInfo indicating there is a next page with
|
||||
// the given end cursor.
|
||||
func NextPageCursor(endCursor string) *PageInfo {
|
||||
return &PageInfo{endCursor: &endCursor, hasNextPage: true}
|
||||
}
|
||||
|
||||
func (r *PageInfo) EndCursor() *string { return r.endCursor }
|
||||
func (r *PageInfo) HasNextPage() bool { return r.hasNextPage }
|
||||
|
||||
// EncodeCursor creates a PageInfo object from the given cursor. If the cursor is not
|
||||
// defined, then an object indicating the end of the result set is returned. The cursor
|
||||
// is base64 encoded for transfer, and should be decoded using the function decodeCursor.
|
||||
func EncodeCursor(val *string) *PageInfo {
|
||||
if val != nil {
|
||||
return NextPageCursor(base64.StdEncoding.EncodeToString([]byte(*val)))
|
||||
}
|
||||
|
||||
return HasNextPage(false)
|
||||
}
|
||||
174
internal/codeintel/autoindexing/transport/graphql/utils_test.go
Normal file
174
internal/codeintel/autoindexing/transport/graphql/utils_test.go
Normal file
@ -0,0 +1,174 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/graph-gophers/graphql-go"
|
||||
|
||||
codeinteltypes "github.com/sourcegraph/sourcegraph/internal/codeintel/types"
|
||||
)
|
||||
|
||||
func TestMakeGetIndexesOptions(t *testing.T) {
|
||||
opts, err := makeGetIndexesOptions(&LSIFRepositoryIndexesQueryArgs{
|
||||
LSIFIndexesQueryArgs: &LSIFIndexesQueryArgs{
|
||||
ConnectionArgs: ConnectionArgs{
|
||||
First: intPtr(5),
|
||||
},
|
||||
Query: strPtr("q"),
|
||||
State: strPtr("s"),
|
||||
After: EncodeIntCursor(intPtr(25)).EndCursor(),
|
||||
},
|
||||
RepositoryID: graphql.ID(base64.StdEncoding.EncodeToString([]byte("Repo:50"))),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error making options: %s", err)
|
||||
}
|
||||
|
||||
expected := codeinteltypes.GetIndexesOptions{
|
||||
RepositoryID: 50,
|
||||
State: "s",
|
||||
Term: "q",
|
||||
Limit: 5,
|
||||
Offset: 25,
|
||||
}
|
||||
if diff := cmp.Diff(expected, opts); diff != "" {
|
||||
t.Errorf("unexpected opts (-want +got):\n%s", diff)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMakeGetIndexesOptionsDefaults(t *testing.T) {
|
||||
opts, err := makeGetIndexesOptions(&LSIFRepositoryIndexesQueryArgs{
|
||||
LSIFIndexesQueryArgs: &LSIFIndexesQueryArgs{},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error making options: %s", err)
|
||||
}
|
||||
|
||||
expected := codeinteltypes.GetIndexesOptions{
|
||||
RepositoryID: 0,
|
||||
State: "",
|
||||
Term: "",
|
||||
Limit: DefaultIndexPageSize,
|
||||
Offset: 0,
|
||||
}
|
||||
if diff := cmp.Diff(expected, opts); diff != "" {
|
||||
t.Errorf("unexpected opts (-want +got):\n%s", diff)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCursor(t *testing.T) {
|
||||
expected := "test"
|
||||
pageInfo := EncodeCursor(&expected)
|
||||
|
||||
if !pageInfo.HasNextPage() {
|
||||
t.Fatalf("expected next page")
|
||||
}
|
||||
if pageInfo.EndCursor() == nil {
|
||||
t.Fatalf("unexpected nil cursor")
|
||||
}
|
||||
|
||||
value, err := DecodeCursor(pageInfo.EndCursor())
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error decoding cursor: %s", err)
|
||||
}
|
||||
if value != expected {
|
||||
t.Errorf("unexpected decoded cursor. want=%s have=%s", expected, value)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCursorEmpty(t *testing.T) {
|
||||
pageInfo := EncodeCursor(nil)
|
||||
|
||||
if pageInfo.HasNextPage() {
|
||||
t.Errorf("unexpected next page")
|
||||
}
|
||||
if pageInfo.EndCursor() != nil {
|
||||
t.Errorf("unexpected encoded cursor: %s", *pageInfo.EndCursor())
|
||||
}
|
||||
|
||||
value, err := DecodeCursor(nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error decoding cursor: %s", err)
|
||||
}
|
||||
if value != "" {
|
||||
t.Errorf("unexpected decoded cursor: %s", value)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntCursor(t *testing.T) {
|
||||
expected := 42
|
||||
pageInfo := EncodeIntCursor(toInt32(&expected))
|
||||
|
||||
if !pageInfo.HasNextPage() {
|
||||
t.Fatalf("expected next page")
|
||||
}
|
||||
if pageInfo.EndCursor() == nil {
|
||||
t.Fatalf("unexpected nil cursor")
|
||||
}
|
||||
|
||||
value, err := DecodeIntCursor(pageInfo.EndCursor())
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error decoding cursor: %s", err)
|
||||
}
|
||||
if value != expected {
|
||||
t.Errorf("unexpected decoded cursor. want=%d have=%d", expected, value)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntCursorEmpty(t *testing.T) {
|
||||
pageInfo := EncodeIntCursor(nil)
|
||||
|
||||
if pageInfo.HasNextPage() {
|
||||
t.Errorf("unexpected next page")
|
||||
}
|
||||
if pageInfo.EndCursor() != nil {
|
||||
t.Errorf("unexpected encoded cursor: %s", *pageInfo.EndCursor())
|
||||
}
|
||||
|
||||
value, err := DecodeIntCursor(nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error decoding cursor: %s", err)
|
||||
}
|
||||
if value != 0 {
|
||||
t.Errorf("unexpected decoded cursor: %d", value)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIndexID(t *testing.T) {
|
||||
expected := int64(42)
|
||||
value, err := unmarshalLSIFIndexGQLID(marshalLSIFIndexGQLID(expected))
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error marshalling id: %s", err)
|
||||
}
|
||||
if value != expected {
|
||||
t.Errorf("unexpected id. have=%d want=%d", expected, value)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDerefInt32(t *testing.T) {
|
||||
expected := 42
|
||||
expected32 := int32(expected)
|
||||
|
||||
if val := derefInt32(nil, expected); val != expected {
|
||||
t.Errorf("unexpected value. want=%d have=%d", expected, val)
|
||||
}
|
||||
if val := derefInt32(&expected32, expected); val != expected {
|
||||
t.Errorf("unexpected value. want=%d have=%d", expected, val)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDerefString(t *testing.T) {
|
||||
expected := "foo"
|
||||
|
||||
if val := derefString(nil, expected); val != expected {
|
||||
t.Errorf("unexpected value. want=%s have=%s", expected, val)
|
||||
}
|
||||
if val := derefString(&expected, ""); val != expected {
|
||||
t.Errorf("unexpected value. want=%s have=%s", expected, val)
|
||||
}
|
||||
if val := derefString(&expected, expected); val != expected {
|
||||
t.Errorf("unexpected value. want=%s have=%s", expected, val)
|
||||
}
|
||||
}
|
||||
@ -10,7 +10,8 @@ import (
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/types"
|
||||
sgtypes "github.com/sourcegraph/sourcegraph/internal/types"
|
||||
)
|
||||
|
||||
// GitTreeTranslator translates a position within a git tree at a source commit into the
|
||||
@ -26,14 +27,14 @@ type GitTreeTranslator interface {
|
||||
// target commit. The target commit's path and position are returned, along with a boolean flag
|
||||
// indicating that the translation was successful. If revese is true, then the source and
|
||||
// target commits are swapped.
|
||||
GetTargetCommitPositionFromSourcePosition(ctx context.Context, commit string, px shared.Position, reverse bool) (string, shared.Position, bool, error)
|
||||
GetTargetCommitPositionFromSourcePosition(ctx context.Context, commit string, px types.Position, reverse bool) (string, types.Position, bool, error)
|
||||
// AdjustPosition
|
||||
|
||||
// GetTargetCommitRangeFromSourceRange translates the given range from the source commit into the given target
|
||||
// commit. The target commit's path and range are returned, along with a boolean flag indicating
|
||||
// that the translation was successful. If revese is true, then the source and target commits
|
||||
// are swapped.
|
||||
GetTargetCommitRangeFromSourceRange(ctx context.Context, commit, path string, rx shared.Range, reverse bool) (string, shared.Range, bool, error)
|
||||
GetTargetCommitRangeFromSourceRange(ctx context.Context, commit, path string, rx types.Range, reverse bool) (string, types.Range, bool, error)
|
||||
}
|
||||
|
||||
type gitTreeTranslator struct {
|
||||
@ -43,7 +44,7 @@ type gitTreeTranslator struct {
|
||||
}
|
||||
|
||||
type requestArgs struct {
|
||||
repo *types.Repo
|
||||
repo *sgtypes.Repo
|
||||
commit string
|
||||
path string
|
||||
}
|
||||
@ -92,10 +93,10 @@ func (g *gitTreeTranslator) GetTargetCommitPathFromSourcePath(ctx context.Contex
|
||||
// indicating that the translation was successful. If revese is true, then the source and
|
||||
// target commits are swapped.
|
||||
// TODO: No todo just letting me know that I updated path just on this one. Need to do it like that.
|
||||
func (g *gitTreeTranslator) GetTargetCommitPositionFromSourcePosition(ctx context.Context, commit string, px shared.Position, reverse bool) (string, shared.Position, bool, error) {
|
||||
func (g *gitTreeTranslator) GetTargetCommitPositionFromSourcePosition(ctx context.Context, commit string, px types.Position, reverse bool) (string, types.Position, bool, error) {
|
||||
hunks, err := g.readCachedHunks(ctx, g.localRequestArgs.repo, g.localRequestArgs.commit, commit, g.localRequestArgs.path, reverse)
|
||||
if err != nil {
|
||||
return "", shared.Position{}, false, err
|
||||
return "", types.Position{}, false, err
|
||||
}
|
||||
|
||||
commitPosition, ok := translatePosition(hunks, px)
|
||||
@ -106,10 +107,10 @@ func (g *gitTreeTranslator) GetTargetCommitPositionFromSourcePosition(ctx contex
|
||||
// commit. The target commit path and range are returned, along with a boolean flag indicating
|
||||
// that the translation was successful. If revese is true, then the source and target commits
|
||||
// are swapped.
|
||||
func (g *gitTreeTranslator) GetTargetCommitRangeFromSourceRange(ctx context.Context, commit, path string, rx shared.Range, reverse bool) (string, shared.Range, bool, error) {
|
||||
func (g *gitTreeTranslator) GetTargetCommitRangeFromSourceRange(ctx context.Context, commit, path string, rx types.Range, reverse bool) (string, types.Range, bool, error) {
|
||||
hunks, err := g.readCachedHunks(ctx, g.localRequestArgs.repo, g.localRequestArgs.commit, commit, path, reverse)
|
||||
if err != nil {
|
||||
return "", shared.Range{}, false, err
|
||||
return "", types.Range{}, false, err
|
||||
}
|
||||
|
||||
commitRange, ok := translateRange(hunks, rx)
|
||||
@ -121,7 +122,7 @@ func (g *gitTreeTranslator) GetTargetCommitRangeFromSourceRange(ctx context.Cont
|
||||
// source and target commits are swapped. If the git tree translator has a hunk cache, it
|
||||
// will read from it before attempting to contact a remote server, and populate the cache
|
||||
// with new results
|
||||
func (g *gitTreeTranslator) readCachedHunks(ctx context.Context, repo *types.Repo, sourceCommit, targetCommit, path string, reverse bool) ([]*diff.Hunk, error) {
|
||||
func (g *gitTreeTranslator) readCachedHunks(ctx context.Context, repo *sgtypes.Repo, sourceCommit, targetCommit, path string, reverse bool) ([]*diff.Hunk, error) {
|
||||
if sourceCommit == targetCommit {
|
||||
return nil, nil
|
||||
}
|
||||
@ -154,7 +155,7 @@ func (g *gitTreeTranslator) readCachedHunks(ctx context.Context, repo *types.Rep
|
||||
|
||||
// readHunks returns a position-ordered slice of changes (additions or deletions) of
|
||||
// the given path between the given source and target commits.
|
||||
func (g *gitTreeTranslator) readHunks(ctx context.Context, repo *types.Repo, sourceCommit, targetCommit, path string) ([]*diff.Hunk, error) {
|
||||
func (g *gitTreeTranslator) readHunks(ctx context.Context, repo *sgtypes.Repo, sourceCommit, targetCommit, path string) ([]*diff.Hunk, error) {
|
||||
return g.client.DiffPath(ctx, authz.DefaultSubRepoPermsChecker, repo.Name, sourceCommit, targetCommit, path)
|
||||
}
|
||||
|
||||
@ -174,31 +175,31 @@ func findHunk(hunks []*diff.Hunk, line int) *diff.Hunk {
|
||||
// translateRange translates the given range by calling translatePosition on both of the range's
|
||||
// endpoints. This function returns a boolean flag indicating that the translation was
|
||||
// successful (which occurs when both endpoints of the range can be translated).
|
||||
func translateRange(hunks []*diff.Hunk, r shared.Range) (shared.Range, bool) {
|
||||
func translateRange(hunks []*diff.Hunk, r types.Range) (types.Range, bool) {
|
||||
start, ok := translatePosition(hunks, r.Start)
|
||||
if !ok {
|
||||
return shared.Range{}, false
|
||||
return types.Range{}, false
|
||||
}
|
||||
|
||||
end, ok := translatePosition(hunks, r.End)
|
||||
if !ok {
|
||||
return shared.Range{}, false
|
||||
return types.Range{}, false
|
||||
}
|
||||
|
||||
return shared.Range{Start: start, End: end}, true
|
||||
return types.Range{Start: start, End: end}, true
|
||||
}
|
||||
|
||||
// translatePosition translates the given position by setting the line number based on the
|
||||
// number of additions and deletions that occur before that line. This function returns a
|
||||
// boolean flag indicating that the translation is successful. A translation fails when the
|
||||
// line indicated by the position has been edited.
|
||||
func translatePosition(hunks []*diff.Hunk, pos shared.Position) (shared.Position, bool) {
|
||||
func translatePosition(hunks []*diff.Hunk, pos types.Position) (types.Position, bool) {
|
||||
line, ok := translateLineNumbers(hunks, pos.Line)
|
||||
if !ok {
|
||||
return shared.Position{}, false
|
||||
return types.Position{}, false
|
||||
}
|
||||
|
||||
return shared.Position{Line: line, Character: pos.Character}, true
|
||||
return types.Position{Line: line, Character: pos.Character}, true
|
||||
}
|
||||
|
||||
// translateLineNumbers translates the given line number based on the number of additions and deletions
|
||||
|
||||
@ -10,19 +10,19 @@ import (
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/sourcegraph/go-diff/diff"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/shared"
|
||||
codeintelgitserver "github.com/sourcegraph/sourcegraph/internal/codeintel/stores/gitserver"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/types"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
"github.com/sourcegraph/sourcegraph/internal/types"
|
||||
sgtypes "github.com/sourcegraph/sourcegraph/internal/types"
|
||||
)
|
||||
|
||||
var client = codeintelgitserver.New(database.NewMockDB(), NewMockDBStore(), &observation.TestContext)
|
||||
|
||||
func TestGetTargetCommitPathFromSourcePath(t *testing.T) {
|
||||
args := &requestArgs{
|
||||
repo: &types.Repo{ID: 50},
|
||||
repo: &sgtypes.Repo{ID: 50},
|
||||
commit: "deadbeef1",
|
||||
path: "/foo/bar.go",
|
||||
}
|
||||
@ -53,10 +53,10 @@ func TestGetTargetCommitPositionFromSourcePosition(t *testing.T) {
|
||||
return io.NopCloser(bytes.NewReader([]byte(hugoDiff))), nil
|
||||
}
|
||||
|
||||
posIn := shared.Position{Line: 302, Character: 15}
|
||||
posIn := types.Position{Line: 302, Character: 15}
|
||||
|
||||
args := &requestArgs{
|
||||
repo: &types.Repo{ID: 50},
|
||||
repo: &sgtypes.Repo{ID: 50},
|
||||
commit: "deadbeef1",
|
||||
path: "/foo/bar.go",
|
||||
}
|
||||
@ -73,7 +73,7 @@ func TestGetTargetCommitPositionFromSourcePosition(t *testing.T) {
|
||||
t.Errorf("unexpected path. want=%s have=%s", "/foo/bar.go", path)
|
||||
}
|
||||
|
||||
expectedPos := shared.Position{Line: 294, Character: 15}
|
||||
expectedPos := types.Position{Line: 294, Character: 15}
|
||||
if diff := cmp.Diff(expectedPos, posOut); diff != "" {
|
||||
t.Errorf("unexpected position (-want +got):\n%s", diff)
|
||||
}
|
||||
@ -87,10 +87,10 @@ func TestGetTargetCommitPositionFromSourcePositionEmptyDiff(t *testing.T) {
|
||||
return io.NopCloser(bytes.NewReader(nil)), nil
|
||||
}
|
||||
|
||||
posIn := shared.Position{Line: 10, Character: 15}
|
||||
posIn := types.Position{Line: 10, Character: 15}
|
||||
|
||||
args := &requestArgs{
|
||||
repo: &types.Repo{ID: 50},
|
||||
repo: &sgtypes.Repo{ID: 50},
|
||||
commit: "deadbeef1",
|
||||
path: "/foo/bar.go",
|
||||
}
|
||||
@ -124,10 +124,10 @@ func TestGetTargetCommitPositionFromSourcePositionReverse(t *testing.T) {
|
||||
return io.NopCloser(bytes.NewReader([]byte(hugoDiff))), nil
|
||||
}
|
||||
|
||||
posIn := shared.Position{Line: 302, Character: 15}
|
||||
posIn := types.Position{Line: 302, Character: 15}
|
||||
|
||||
args := &requestArgs{
|
||||
repo: &types.Repo{ID: 50},
|
||||
repo: &sgtypes.Repo{ID: 50},
|
||||
commit: "deadbeef1",
|
||||
path: "/foo/bar.go",
|
||||
}
|
||||
@ -144,7 +144,7 @@ func TestGetTargetCommitPositionFromSourcePositionReverse(t *testing.T) {
|
||||
t.Errorf("unexpected path. want=%s have=%s", "/foo/bar.go", path)
|
||||
}
|
||||
|
||||
expectedPos := shared.Position{Line: 294, Character: 15}
|
||||
expectedPos := types.Position{Line: 294, Character: 15}
|
||||
if diff := cmp.Diff(expectedPos, posOut); diff != "" {
|
||||
t.Errorf("unexpected position (-want +got):\n%s", diff)
|
||||
}
|
||||
@ -163,13 +163,13 @@ func TestGetTargetCommitRangeFromSourceRange(t *testing.T) {
|
||||
return io.NopCloser(bytes.NewReader([]byte(hugoDiff))), nil
|
||||
}
|
||||
|
||||
rIn := shared.Range{
|
||||
Start: shared.Position{Line: 302, Character: 15},
|
||||
End: shared.Position{Line: 305, Character: 20},
|
||||
rIn := types.Range{
|
||||
Start: types.Position{Line: 302, Character: 15},
|
||||
End: types.Position{Line: 305, Character: 20},
|
||||
}
|
||||
|
||||
args := &requestArgs{
|
||||
repo: &types.Repo{ID: 50},
|
||||
repo: &sgtypes.Repo{ID: 50},
|
||||
commit: "deadbeef1",
|
||||
path: "/foo/bar.go",
|
||||
}
|
||||
@ -186,9 +186,9 @@ func TestGetTargetCommitRangeFromSourceRange(t *testing.T) {
|
||||
t.Errorf("unexpected path. want=%s have=%s", "/foo/bar.go", path)
|
||||
}
|
||||
|
||||
expectedRange := shared.Range{
|
||||
Start: shared.Position{Line: 294, Character: 15},
|
||||
End: shared.Position{Line: 297, Character: 20},
|
||||
expectedRange := types.Range{
|
||||
Start: types.Position{Line: 294, Character: 15},
|
||||
End: types.Position{Line: 297, Character: 20},
|
||||
}
|
||||
if diff := cmp.Diff(expectedRange, rOut); diff != "" {
|
||||
t.Errorf("unexpected position (-want +got):\n%s", diff)
|
||||
@ -203,13 +203,13 @@ func TestGetTargetCommitRangeFromSourceRangeEmptyDiff(t *testing.T) {
|
||||
return io.NopCloser(bytes.NewReader(nil)), nil
|
||||
}
|
||||
|
||||
rIn := shared.Range{
|
||||
Start: shared.Position{Line: 302, Character: 15},
|
||||
End: shared.Position{Line: 305, Character: 20},
|
||||
rIn := types.Range{
|
||||
Start: types.Position{Line: 302, Character: 15},
|
||||
End: types.Position{Line: 305, Character: 20},
|
||||
}
|
||||
|
||||
args := &requestArgs{
|
||||
repo: &types.Repo{ID: 50},
|
||||
repo: &sgtypes.Repo{ID: 50},
|
||||
commit: "deadbeef1",
|
||||
path: "/foo/bar.go",
|
||||
}
|
||||
@ -243,13 +243,13 @@ func TestGetTargetCommitRangeFromSourceRangeReverse(t *testing.T) {
|
||||
return io.NopCloser(bytes.NewReader([]byte(hugoDiff))), nil
|
||||
}
|
||||
|
||||
rIn := shared.Range{
|
||||
Start: shared.Position{Line: 302, Character: 15},
|
||||
End: shared.Position{Line: 305, Character: 20},
|
||||
rIn := types.Range{
|
||||
Start: types.Position{Line: 302, Character: 15},
|
||||
End: types.Position{Line: 305, Character: 20},
|
||||
}
|
||||
|
||||
args := &requestArgs{
|
||||
repo: &types.Repo{ID: 50},
|
||||
repo: &sgtypes.Repo{ID: 50},
|
||||
commit: "deadbeef1",
|
||||
path: "/foo/bar.go",
|
||||
}
|
||||
@ -266,9 +266,9 @@ func TestGetTargetCommitRangeFromSourceRangeReverse(t *testing.T) {
|
||||
t.Errorf("unexpected path. want=%s have=%s", "/foo/bar.go", path)
|
||||
}
|
||||
|
||||
expectedRange := shared.Range{
|
||||
Start: shared.Position{Line: 294, Character: 15},
|
||||
End: shared.Position{Line: 297, Character: 20},
|
||||
expectedRange := types.Range{
|
||||
Start: types.Position{Line: 294, Character: 15},
|
||||
End: types.Position{Line: 297, Character: 20},
|
||||
}
|
||||
if diff := cmp.Diff(expectedRange, rOut); diff != "" {
|
||||
t.Errorf("unexpected position (-want +got):\n%s", diff)
|
||||
@ -399,7 +399,7 @@ func TestRawGetTargetCommitPositionFromSourcePosition(t *testing.T) {
|
||||
}
|
||||
hunks := diff.Hunks
|
||||
|
||||
pos := shared.Position{
|
||||
pos := types.Position{
|
||||
Line: testCase.line - 1, // 1-index -> 0-index
|
||||
Character: 10,
|
||||
}
|
||||
|
||||
@ -8,15 +8,15 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/stores/gitserver"
|
||||
uploads "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/types"
|
||||
"github.com/sourcegraph/sourcegraph/lib/codeintel/precise"
|
||||
)
|
||||
|
||||
type UploadService interface {
|
||||
GetDumpsWithDefinitionsForMonikers(ctx context.Context, monikers []precise.QualifiedMonikerData) (_ []uploads.Dump, err error)
|
||||
GetDumpsWithDefinitionsForMonikers(ctx context.Context, monikers []precise.QualifiedMonikerData) (_ []types.Dump, err error)
|
||||
GetUploadIDsWithReferences(ctx context.Context, orderedMonikers []precise.QualifiedMonikerData, ignoreIDs []int, repositoryID int, commit string, limit int, offset int) (ids []int, recordsScanned int, totalCount int, err error)
|
||||
GetDumpsByIDs(ctx context.Context, ids []int) (_ []uploads.Dump, err error)
|
||||
InferClosestUploads(ctx context.Context, repositoryID int, commit, path string, exactPath bool, indexer string) (_ []uploads.Dump, err error)
|
||||
GetDumpsByIDs(ctx context.Context, ids []int) (_ []types.Dump, err error)
|
||||
InferClosestUploads(ctx context.Context, repositoryID int, commit, path string, exactPath bool, indexer string) (_ []types.Dump, err error)
|
||||
}
|
||||
|
||||
type GitserverClient interface {
|
||||
|
||||
@ -12,7 +12,6 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/internal/store"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
"github.com/sourcegraph/sourcegraph/internal/symbols"
|
||||
"github.com/sourcegraph/sourcegraph/internal/trace"
|
||||
)
|
||||
|
||||
@ -23,7 +22,7 @@ var (
|
||||
|
||||
// GetService creates or returns an already-initialized symbols service. If the service is
|
||||
// new, it will use the given database handle.
|
||||
func GetService(db, codeIntelDB database.DB, uploadSvc UploadService, gitserver GitserverClient, symbolsClient *symbols.Client) *Service {
|
||||
func GetService(db, codeIntelDB database.DB, uploadSvc UploadService, gitserver GitserverClient) *Service {
|
||||
svcOnce.Do(func() {
|
||||
oc := func(name string) *observation.Context {
|
||||
return &observation.Context{
|
||||
@ -35,7 +34,7 @@ func GetService(db, codeIntelDB database.DB, uploadSvc UploadService, gitserver
|
||||
|
||||
store := store.New(db, oc("store"))
|
||||
lsifstore := lsifstore.New(codeIntelDB, oc("lsifstore"))
|
||||
svc = newService(store, lsifstore, uploadSvc, gitserver, symbolsClient, oc("service"))
|
||||
svc = newService(store, lsifstore, uploadSvc, gitserver, oc("service"))
|
||||
})
|
||||
|
||||
return svc
|
||||
|
||||
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/types"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/basestore"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
@ -12,7 +13,7 @@ import (
|
||||
|
||||
type LsifStore interface {
|
||||
// Hover
|
||||
GetHover(ctx context.Context, bundleID int, path string, line, character int) (string, shared.Range, bool, error)
|
||||
GetHover(ctx context.Context, bundleID int, path string, line, character int) (string, types.Range, bool, error)
|
||||
|
||||
// References
|
||||
GetReferenceLocations(ctx context.Context, uploadID int, path string, line, character, limit, offset int) (_ []shared.Location, _ int, err error)
|
||||
@ -34,7 +35,7 @@ type LsifStore interface {
|
||||
GetDiagnostics(ctx context.Context, bundleID int, prefix string, limit, offset int) (_ []shared.Diagnostic, _ int, err error)
|
||||
|
||||
// Stencil
|
||||
GetStencil(ctx context.Context, bundleID int, path string) (_ []shared.Range, err error)
|
||||
GetStencil(ctx context.Context, bundleID int, path string) (_ []types.Range, err error)
|
||||
|
||||
// Ranges
|
||||
GetRanges(ctx context.Context, bundleID int, path string, startLine, endLine int) (_ []shared.CodeIntelligenceRange, err error)
|
||||
|
||||
@ -6,13 +6,13 @@ import (
|
||||
"github.com/keegancsmith/sqlf"
|
||||
"github.com/opentracing/opentracing-go/log"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/types"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
"github.com/sourcegraph/sourcegraph/lib/codeintel/precise"
|
||||
)
|
||||
|
||||
// GetHover returns the hover text of the symbol at the given position.
|
||||
func (s *store) GetHover(ctx context.Context, bundleID int, path string, line, character int) (_ string, _ shared.Range, _ bool, err error) {
|
||||
func (s *store) GetHover(ctx context.Context, bundleID int, path string, line, character int) (_ string, _ types.Range, _ bool, err error) {
|
||||
ctx, trace, endObservation := s.operations.getHover.With(ctx, &err, observation.Args{LogFields: []log.Field{
|
||||
log.Int("bundleID", bundleID),
|
||||
log.String("path", path),
|
||||
@ -23,7 +23,7 @@ func (s *store) GetHover(ctx context.Context, bundleID int, path string, line, c
|
||||
|
||||
documentData, exists, err := s.scanFirstDocumentData(s.db.Query(ctx, sqlf.Sprintf(hoverDocumentQuery, bundleID, path)))
|
||||
if err != nil || !exists {
|
||||
return "", shared.Range{}, false, err
|
||||
return "", types.Range{}, false, err
|
||||
}
|
||||
|
||||
trace.Log(log.Int("numRanges", len(documentData.Document.Ranges)))
|
||||
@ -36,7 +36,7 @@ func (s *store) GetHover(ctx context.Context, bundleID int, path string, line, c
|
||||
}
|
||||
}
|
||||
|
||||
return "", shared.Range{}, false, nil
|
||||
return "", types.Range{}, false, nil
|
||||
}
|
||||
|
||||
const hoverDocumentQuery = `
|
||||
|
||||
@ -11,6 +11,7 @@ import (
|
||||
"github.com/opentracing/opentracing-go/log"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/types"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/basestore"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
"github.com/sourcegraph/sourcegraph/lib/codeintel/precise"
|
||||
@ -339,13 +340,13 @@ func (s *store) readRangesFromDocument(bundleID int, rangeIDsByResultID map[prec
|
||||
return totalCount
|
||||
}
|
||||
|
||||
func newRange(startLine, startCharacter, endLine, endCharacter int) shared.Range {
|
||||
return shared.Range{
|
||||
Start: shared.Position{
|
||||
func newRange(startLine, startCharacter, endLine, endCharacter int) types.Range {
|
||||
return types.Range{
|
||||
Start: types.Position{
|
||||
Line: startLine,
|
||||
Character: startCharacter,
|
||||
},
|
||||
End: shared.Position{
|
||||
End: types.Position{
|
||||
Line: endLine,
|
||||
Character: endCharacter,
|
||||
},
|
||||
@ -364,7 +365,7 @@ func sortLocations(locations []shared.Location) {
|
||||
}
|
||||
|
||||
// compareBundleRanges returns true if r1's start position occurs before r2's start position.
|
||||
func compareBundleRanges(r1, r2 shared.Range) bool {
|
||||
func compareBundleRanges(r1, r2 types.Range) bool {
|
||||
cmp := r1.Start.Line - r2.Start.Line
|
||||
if cmp == 0 {
|
||||
cmp = r1.Start.Character - r2.Start.Character
|
||||
|
||||
@ -6,12 +6,12 @@ import (
|
||||
"github.com/keegancsmith/sqlf"
|
||||
"github.com/opentracing/opentracing-go/log"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/types"
|
||||
"github.com/sourcegraph/sourcegraph/internal/observation"
|
||||
)
|
||||
|
||||
// Stencil returns all ranges within a single document.
|
||||
func (s *store) GetStencil(ctx context.Context, bundleID int, path string) (_ []shared.Range, err error) {
|
||||
func (s *store) GetStencil(ctx context.Context, bundleID int, path string) (_ []types.Range, err error) {
|
||||
ctx, trace, endObservation := s.operations.getStencil.With(ctx, &err, observation.Args{LogFields: []log.Field{
|
||||
log.Int("bundleID", bundleID),
|
||||
log.String("path", path),
|
||||
@ -25,7 +25,7 @@ func (s *store) GetStencil(ctx context.Context, bundleID int, path string) (_ []
|
||||
|
||||
trace.Log(log.Int("numRanges", len(documentData.Document.Ranges)))
|
||||
|
||||
ranges := make([]shared.Range, 0, len(documentData.Document.Ranges))
|
||||
ranges := make([]types.Range, 0, len(documentData.Document.Ranges))
|
||||
for _, r := range documentData.Document.Ranges {
|
||||
ranges = append(ranges, newRange(r.StartLine, r.StartCharacter, r.EndLine, r.EndCharacter))
|
||||
}
|
||||
|
||||
@ -8,8 +8,8 @@ import (
|
||||
)
|
||||
|
||||
type operations struct {
|
||||
getLanguagesRequestedBy *observation.Operation
|
||||
setRequestLanguageSupport *observation.Operation
|
||||
// noop is a no-op operation to keep the newOperation scaffolding.
|
||||
noop *observation.Operation
|
||||
}
|
||||
|
||||
func newOperations(observationContext *observation.Context) *operations {
|
||||
@ -29,7 +29,6 @@ func newOperations(observationContext *observation.Context) *operations {
|
||||
}
|
||||
|
||||
return &operations{
|
||||
getLanguagesRequestedBy: op("GetLanguagesRequestedBy"),
|
||||
setRequestLanguageSupport: op("SetRequestLanguageSupport"),
|
||||
noop: op("noop"),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/keegancsmith/sqlf"
|
||||
logger "github.com/sourcegraph/log"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/basestore"
|
||||
@ -12,13 +10,13 @@ import (
|
||||
|
||||
// Store provides the interface for codenav storage.
|
||||
type Store interface {
|
||||
GetLanguagesRequestedBy(ctx context.Context, userID int) (_ []string, err error)
|
||||
SetRequestLanguageSupport(ctx context.Context, userID int, language string) (err error)
|
||||
GetUnsafeDB() database.DB
|
||||
}
|
||||
|
||||
// store manages the codenav store.
|
||||
type store struct {
|
||||
db *basestore.Store
|
||||
logger logger.Logger
|
||||
operations *operations
|
||||
}
|
||||
|
||||
@ -26,35 +24,13 @@ type store struct {
|
||||
func New(db database.DB, observationContext *observation.Context) Store {
|
||||
return &store{
|
||||
db: basestore.NewWithHandle(db.Handle()),
|
||||
logger: logger.Scoped("codenav.store", ""),
|
||||
operations: newOperations(observationContext),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *store) GetLanguagesRequestedBy(ctx context.Context, userID int) (_ []string, err error) {
|
||||
ctx, _, endObservation := s.operations.getLanguagesRequestedBy.With(ctx, &err, observation.Args{})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
return basestore.ScanStrings(s.db.Query(ctx, sqlf.Sprintf(languagesRequestedByQuery, userID)))
|
||||
// GetUnsafeDB returns the underlying database handle. This is used by the
|
||||
// resolvers that have the old convention of using the database handle directly.
|
||||
func (s *store) GetUnsafeDB() database.DB {
|
||||
return database.NewDBWith(s.logger, s.db)
|
||||
}
|
||||
|
||||
const languagesRequestedByQuery = `
|
||||
-- source: internal/codeintel/codenav/internal/store/store.go:GetLanguagesRequestedBy
|
||||
SELECT language_id
|
||||
FROM codeintel_langugage_support_requests
|
||||
WHERE user_id = %s
|
||||
ORDER BY language_id
|
||||
`
|
||||
|
||||
func (s *store) SetRequestLanguageSupport(ctx context.Context, userID int, language string) (err error) {
|
||||
ctx, _, endObservation := s.operations.setRequestLanguageSupport.With(ctx, &err, observation.Args{})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
return s.db.Exec(ctx, sqlf.Sprintf(requestLanguageSupportQuery, userID, language))
|
||||
}
|
||||
|
||||
const requestLanguageSupportQuery = `
|
||||
-- source: internal/codeintel/codenav/internal/store/store.go:SetRequestLanguageSupport
|
||||
INSERT INTO codeintel_langugage_support_requests (user_id, language_id)
|
||||
VALUES (%s, %s)
|
||||
ON CONFLICT DO NOTHING
|
||||
`
|
||||
|
||||
@ -17,7 +17,8 @@ import (
|
||||
store "github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/internal/store"
|
||||
shared "github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/shared"
|
||||
gitserver "github.com/sourcegraph/sourcegraph/internal/codeintel/stores/gitserver"
|
||||
shared1 "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared"
|
||||
types "github.com/sourcegraph/sourcegraph/internal/codeintel/types"
|
||||
database "github.com/sourcegraph/sourcegraph/internal/database"
|
||||
precise "github.com/sourcegraph/sourcegraph/lib/codeintel/precise"
|
||||
)
|
||||
|
||||
@ -26,26 +27,17 @@ import (
|
||||
// github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/internal/store)
|
||||
// used for unit testing.
|
||||
type MockStore struct {
|
||||
// GetLanguagesRequestedByFunc is an instance of a mock function object
|
||||
// controlling the behavior of the method GetLanguagesRequestedBy.
|
||||
GetLanguagesRequestedByFunc *StoreGetLanguagesRequestedByFunc
|
||||
// SetRequestLanguageSupportFunc is an instance of a mock function
|
||||
// object controlling the behavior of the method
|
||||
// SetRequestLanguageSupport.
|
||||
SetRequestLanguageSupportFunc *StoreSetRequestLanguageSupportFunc
|
||||
// GetUnsafeDBFunc is an instance of a mock function object controlling
|
||||
// the behavior of the method GetUnsafeDB.
|
||||
GetUnsafeDBFunc *StoreGetUnsafeDBFunc
|
||||
}
|
||||
|
||||
// NewMockStore creates a new mock of the Store interface. All methods
|
||||
// return zero values for all results, unless overwritten.
|
||||
func NewMockStore() *MockStore {
|
||||
return &MockStore{
|
||||
GetLanguagesRequestedByFunc: &StoreGetLanguagesRequestedByFunc{
|
||||
defaultHook: func(context.Context, int) (r0 []string, r1 error) {
|
||||
return
|
||||
},
|
||||
},
|
||||
SetRequestLanguageSupportFunc: &StoreSetRequestLanguageSupportFunc{
|
||||
defaultHook: func(context.Context, int, string) (r0 error) {
|
||||
GetUnsafeDBFunc: &StoreGetUnsafeDBFunc{
|
||||
defaultHook: func() (r0 database.DB) {
|
||||
return
|
||||
},
|
||||
},
|
||||
@ -56,14 +48,9 @@ func NewMockStore() *MockStore {
|
||||
// panic on invocation, unless overwritten.
|
||||
func NewStrictMockStore() *MockStore {
|
||||
return &MockStore{
|
||||
GetLanguagesRequestedByFunc: &StoreGetLanguagesRequestedByFunc{
|
||||
defaultHook: func(context.Context, int) ([]string, error) {
|
||||
panic("unexpected invocation of MockStore.GetLanguagesRequestedBy")
|
||||
},
|
||||
},
|
||||
SetRequestLanguageSupportFunc: &StoreSetRequestLanguageSupportFunc{
|
||||
defaultHook: func(context.Context, int, string) error {
|
||||
panic("unexpected invocation of MockStore.SetRequestLanguageSupport")
|
||||
GetUnsafeDBFunc: &StoreGetUnsafeDBFunc{
|
||||
defaultHook: func() database.DB {
|
||||
panic("unexpected invocation of MockStore.GetUnsafeDB")
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -73,154 +60,40 @@ func NewStrictMockStore() *MockStore {
|
||||
// methods delegate to the given implementation, unless overwritten.
|
||||
func NewMockStoreFrom(i store.Store) *MockStore {
|
||||
return &MockStore{
|
||||
GetLanguagesRequestedByFunc: &StoreGetLanguagesRequestedByFunc{
|
||||
defaultHook: i.GetLanguagesRequestedBy,
|
||||
},
|
||||
SetRequestLanguageSupportFunc: &StoreSetRequestLanguageSupportFunc{
|
||||
defaultHook: i.SetRequestLanguageSupport,
|
||||
GetUnsafeDBFunc: &StoreGetUnsafeDBFunc{
|
||||
defaultHook: i.GetUnsafeDB,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// StoreGetLanguagesRequestedByFunc describes the behavior when the
|
||||
// GetLanguagesRequestedBy method of the parent MockStore instance is
|
||||
// invoked.
|
||||
type StoreGetLanguagesRequestedByFunc struct {
|
||||
defaultHook func(context.Context, int) ([]string, error)
|
||||
hooks []func(context.Context, int) ([]string, error)
|
||||
history []StoreGetLanguagesRequestedByFuncCall
|
||||
// StoreGetUnsafeDBFunc describes the behavior when the GetUnsafeDB method
|
||||
// of the parent MockStore instance is invoked.
|
||||
type StoreGetUnsafeDBFunc struct {
|
||||
defaultHook func() database.DB
|
||||
hooks []func() database.DB
|
||||
history []StoreGetUnsafeDBFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// GetLanguagesRequestedBy delegates to the next hook function in the queue
|
||||
// and stores the parameter and result values of this invocation.
|
||||
func (m *MockStore) GetLanguagesRequestedBy(v0 context.Context, v1 int) ([]string, error) {
|
||||
r0, r1 := m.GetLanguagesRequestedByFunc.nextHook()(v0, v1)
|
||||
m.GetLanguagesRequestedByFunc.appendCall(StoreGetLanguagesRequestedByFuncCall{v0, v1, r0, r1})
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// SetDefaultHook sets function that is called when the
|
||||
// GetLanguagesRequestedBy method of the parent MockStore instance is
|
||||
// invoked and the hook queue is empty.
|
||||
func (f *StoreGetLanguagesRequestedByFunc) SetDefaultHook(hook func(context.Context, int) ([]string, error)) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
// PushHook adds a function to the end of hook queue. Each invocation of the
|
||||
// GetLanguagesRequestedBy method of the parent MockStore instance invokes
|
||||
// the hook at the front of the queue and discards it. After the queue is
|
||||
// empty, the default hook function is invoked for any future action.
|
||||
func (f *StoreGetLanguagesRequestedByFunc) PushHook(hook func(context.Context, int) ([]string, error)) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
}
|
||||
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *StoreGetLanguagesRequestedByFunc) SetDefaultReturn(r0 []string, r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, int) ([]string, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *StoreGetLanguagesRequestedByFunc) PushReturn(r0 []string, r1 error) {
|
||||
f.PushHook(func(context.Context, int) ([]string, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
func (f *StoreGetLanguagesRequestedByFunc) nextHook() func(context.Context, int) ([]string, error) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
if len(f.hooks) == 0 {
|
||||
return f.defaultHook
|
||||
}
|
||||
|
||||
hook := f.hooks[0]
|
||||
f.hooks = f.hooks[1:]
|
||||
return hook
|
||||
}
|
||||
|
||||
func (f *StoreGetLanguagesRequestedByFunc) appendCall(r0 StoreGetLanguagesRequestedByFuncCall) {
|
||||
f.mutex.Lock()
|
||||
f.history = append(f.history, r0)
|
||||
f.mutex.Unlock()
|
||||
}
|
||||
|
||||
// History returns a sequence of StoreGetLanguagesRequestedByFuncCall
|
||||
// objects describing the invocations of this function.
|
||||
func (f *StoreGetLanguagesRequestedByFunc) History() []StoreGetLanguagesRequestedByFuncCall {
|
||||
f.mutex.Lock()
|
||||
history := make([]StoreGetLanguagesRequestedByFuncCall, len(f.history))
|
||||
copy(history, f.history)
|
||||
f.mutex.Unlock()
|
||||
|
||||
return history
|
||||
}
|
||||
|
||||
// StoreGetLanguagesRequestedByFuncCall is an object that describes an
|
||||
// invocation of method GetLanguagesRequestedBy on an instance of MockStore.
|
||||
type StoreGetLanguagesRequestedByFuncCall struct {
|
||||
// Arg0 is the value of the 1st argument passed to this method
|
||||
// invocation.
|
||||
Arg0 context.Context
|
||||
// Arg1 is the value of the 2nd argument passed to this method
|
||||
// invocation.
|
||||
Arg1 int
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// invocation.
|
||||
Result0 []string
|
||||
// Result1 is the value of the 2nd result returned from this method
|
||||
// invocation.
|
||||
Result1 error
|
||||
}
|
||||
|
||||
// Args returns an interface slice containing the arguments of this
|
||||
// invocation.
|
||||
func (c StoreGetLanguagesRequestedByFuncCall) Args() []interface{} {
|
||||
return []interface{}{c.Arg0, c.Arg1}
|
||||
}
|
||||
|
||||
// Results returns an interface slice containing the results of this
|
||||
// invocation.
|
||||
func (c StoreGetLanguagesRequestedByFuncCall) Results() []interface{} {
|
||||
return []interface{}{c.Result0, c.Result1}
|
||||
}
|
||||
|
||||
// StoreSetRequestLanguageSupportFunc describes the behavior when the
|
||||
// SetRequestLanguageSupport method of the parent MockStore instance is
|
||||
// invoked.
|
||||
type StoreSetRequestLanguageSupportFunc struct {
|
||||
defaultHook func(context.Context, int, string) error
|
||||
hooks []func(context.Context, int, string) error
|
||||
history []StoreSetRequestLanguageSupportFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// SetRequestLanguageSupport delegates to the next hook function in the
|
||||
// queue and stores the parameter and result values of this invocation.
|
||||
func (m *MockStore) SetRequestLanguageSupport(v0 context.Context, v1 int, v2 string) error {
|
||||
r0 := m.SetRequestLanguageSupportFunc.nextHook()(v0, v1, v2)
|
||||
m.SetRequestLanguageSupportFunc.appendCall(StoreSetRequestLanguageSupportFuncCall{v0, v1, v2, r0})
|
||||
// GetUnsafeDB delegates to the next hook function in the queue and stores
|
||||
// the parameter and result values of this invocation.
|
||||
func (m *MockStore) GetUnsafeDB() database.DB {
|
||||
r0 := m.GetUnsafeDBFunc.nextHook()()
|
||||
m.GetUnsafeDBFunc.appendCall(StoreGetUnsafeDBFuncCall{r0})
|
||||
return r0
|
||||
}
|
||||
|
||||
// SetDefaultHook sets function that is called when the
|
||||
// SetRequestLanguageSupport method of the parent MockStore instance is
|
||||
// invoked and the hook queue is empty.
|
||||
func (f *StoreSetRequestLanguageSupportFunc) SetDefaultHook(hook func(context.Context, int, string) error) {
|
||||
// SetDefaultHook sets function that is called when the GetUnsafeDB method
|
||||
// of the parent MockStore instance is invoked and the hook queue is empty.
|
||||
func (f *StoreGetUnsafeDBFunc) SetDefaultHook(hook func() database.DB) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
// PushHook adds a function to the end of hook queue. Each invocation of the
|
||||
// SetRequestLanguageSupport method of the parent MockStore instance invokes
|
||||
// the hook at the front of the queue and discards it. After the queue is
|
||||
// empty, the default hook function is invoked for any future action.
|
||||
func (f *StoreSetRequestLanguageSupportFunc) PushHook(hook func(context.Context, int, string) error) {
|
||||
// GetUnsafeDB method of the parent MockStore instance invokes the hook at
|
||||
// the front of the queue and discards it. After the queue is empty, the
|
||||
// default hook function is invoked for any future action.
|
||||
func (f *StoreGetUnsafeDBFunc) PushHook(hook func() database.DB) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
@ -228,20 +101,20 @@ func (f *StoreSetRequestLanguageSupportFunc) PushHook(hook func(context.Context,
|
||||
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *StoreSetRequestLanguageSupportFunc) SetDefaultReturn(r0 error) {
|
||||
f.SetDefaultHook(func(context.Context, int, string) error {
|
||||
func (f *StoreGetUnsafeDBFunc) SetDefaultReturn(r0 database.DB) {
|
||||
f.SetDefaultHook(func() database.DB {
|
||||
return r0
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *StoreSetRequestLanguageSupportFunc) PushReturn(r0 error) {
|
||||
f.PushHook(func(context.Context, int, string) error {
|
||||
func (f *StoreGetUnsafeDBFunc) PushReturn(r0 database.DB) {
|
||||
f.PushHook(func() database.DB {
|
||||
return r0
|
||||
})
|
||||
}
|
||||
|
||||
func (f *StoreSetRequestLanguageSupportFunc) nextHook() func(context.Context, int, string) error {
|
||||
func (f *StoreGetUnsafeDBFunc) nextHook() func() database.DB {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
@ -254,50 +127,40 @@ func (f *StoreSetRequestLanguageSupportFunc) nextHook() func(context.Context, in
|
||||
return hook
|
||||
}
|
||||
|
||||
func (f *StoreSetRequestLanguageSupportFunc) appendCall(r0 StoreSetRequestLanguageSupportFuncCall) {
|
||||
func (f *StoreGetUnsafeDBFunc) appendCall(r0 StoreGetUnsafeDBFuncCall) {
|
||||
f.mutex.Lock()
|
||||
f.history = append(f.history, r0)
|
||||
f.mutex.Unlock()
|
||||
}
|
||||
|
||||
// History returns a sequence of StoreSetRequestLanguageSupportFuncCall
|
||||
// objects describing the invocations of this function.
|
||||
func (f *StoreSetRequestLanguageSupportFunc) History() []StoreSetRequestLanguageSupportFuncCall {
|
||||
// History returns a sequence of StoreGetUnsafeDBFuncCall objects describing
|
||||
// the invocations of this function.
|
||||
func (f *StoreGetUnsafeDBFunc) History() []StoreGetUnsafeDBFuncCall {
|
||||
f.mutex.Lock()
|
||||
history := make([]StoreSetRequestLanguageSupportFuncCall, len(f.history))
|
||||
history := make([]StoreGetUnsafeDBFuncCall, len(f.history))
|
||||
copy(history, f.history)
|
||||
f.mutex.Unlock()
|
||||
|
||||
return history
|
||||
}
|
||||
|
||||
// StoreSetRequestLanguageSupportFuncCall is an object that describes an
|
||||
// invocation of method SetRequestLanguageSupport on an instance of
|
||||
// MockStore.
|
||||
type StoreSetRequestLanguageSupportFuncCall struct {
|
||||
// Arg0 is the value of the 1st argument passed to this method
|
||||
// invocation.
|
||||
Arg0 context.Context
|
||||
// Arg1 is the value of the 2nd argument passed to this method
|
||||
// invocation.
|
||||
Arg1 int
|
||||
// Arg2 is the value of the 3rd argument passed to this method
|
||||
// invocation.
|
||||
Arg2 string
|
||||
// StoreGetUnsafeDBFuncCall is an object that describes an invocation of
|
||||
// method GetUnsafeDB on an instance of MockStore.
|
||||
type StoreGetUnsafeDBFuncCall struct {
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// invocation.
|
||||
Result0 error
|
||||
Result0 database.DB
|
||||
}
|
||||
|
||||
// Args returns an interface slice containing the arguments of this
|
||||
// invocation.
|
||||
func (c StoreSetRequestLanguageSupportFuncCall) Args() []interface{} {
|
||||
return []interface{}{c.Arg0, c.Arg1, c.Arg2}
|
||||
func (c StoreGetUnsafeDBFuncCall) Args() []interface{} {
|
||||
return []interface{}{}
|
||||
}
|
||||
|
||||
// Results returns an interface slice containing the results of this
|
||||
// invocation.
|
||||
func (c StoreSetRequestLanguageSupportFuncCall) Results() []interface{} {
|
||||
func (c StoreGetUnsafeDBFuncCall) Results() []interface{} {
|
||||
return []interface{}{c.Result0}
|
||||
}
|
||||
|
||||
@ -362,7 +225,7 @@ func NewMockLsifStore() *MockLsifStore {
|
||||
},
|
||||
},
|
||||
GetHoverFunc: &LsifStoreGetHoverFunc{
|
||||
defaultHook: func(context.Context, int, string, int, int) (r0 string, r1 shared.Range, r2 bool, r3 error) {
|
||||
defaultHook: func(context.Context, int, string, int, int) (r0 string, r1 types.Range, r2 bool, r3 error) {
|
||||
return
|
||||
},
|
||||
},
|
||||
@ -397,7 +260,7 @@ func NewMockLsifStore() *MockLsifStore {
|
||||
},
|
||||
},
|
||||
GetStencilFunc: &LsifStoreGetStencilFunc{
|
||||
defaultHook: func(context.Context, int, string) (r0 []shared.Range, r1 error) {
|
||||
defaultHook: func(context.Context, int, string) (r0 []types.Range, r1 error) {
|
||||
return
|
||||
},
|
||||
},
|
||||
@ -424,7 +287,7 @@ func NewStrictMockLsifStore() *MockLsifStore {
|
||||
},
|
||||
},
|
||||
GetHoverFunc: &LsifStoreGetHoverFunc{
|
||||
defaultHook: func(context.Context, int, string, int, int) (string, shared.Range, bool, error) {
|
||||
defaultHook: func(context.Context, int, string, int, int) (string, types.Range, bool, error) {
|
||||
panic("unexpected invocation of MockLsifStore.GetHover")
|
||||
},
|
||||
},
|
||||
@ -459,7 +322,7 @@ func NewStrictMockLsifStore() *MockLsifStore {
|
||||
},
|
||||
},
|
||||
GetStencilFunc: &LsifStoreGetStencilFunc{
|
||||
defaultHook: func(context.Context, int, string) ([]shared.Range, error) {
|
||||
defaultHook: func(context.Context, int, string) ([]types.Range, error) {
|
||||
panic("unexpected invocation of MockLsifStore.GetStencil")
|
||||
},
|
||||
},
|
||||
@ -884,15 +747,15 @@ func (c LsifStoreGetDiagnosticsFuncCall) Results() []interface{} {
|
||||
// LsifStoreGetHoverFunc describes the behavior when the GetHover method of
|
||||
// the parent MockLsifStore instance is invoked.
|
||||
type LsifStoreGetHoverFunc struct {
|
||||
defaultHook func(context.Context, int, string, int, int) (string, shared.Range, bool, error)
|
||||
hooks []func(context.Context, int, string, int, int) (string, shared.Range, bool, error)
|
||||
defaultHook func(context.Context, int, string, int, int) (string, types.Range, bool, error)
|
||||
hooks []func(context.Context, int, string, int, int) (string, types.Range, bool, error)
|
||||
history []LsifStoreGetHoverFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// GetHover delegates to the next hook function in the queue and stores the
|
||||
// parameter and result values of this invocation.
|
||||
func (m *MockLsifStore) GetHover(v0 context.Context, v1 int, v2 string, v3 int, v4 int) (string, shared.Range, bool, error) {
|
||||
func (m *MockLsifStore) GetHover(v0 context.Context, v1 int, v2 string, v3 int, v4 int) (string, types.Range, bool, error) {
|
||||
r0, r1, r2, r3 := m.GetHoverFunc.nextHook()(v0, v1, v2, v3, v4)
|
||||
m.GetHoverFunc.appendCall(LsifStoreGetHoverFuncCall{v0, v1, v2, v3, v4, r0, r1, r2, r3})
|
||||
return r0, r1, r2, r3
|
||||
@ -900,7 +763,7 @@ func (m *MockLsifStore) GetHover(v0 context.Context, v1 int, v2 string, v3 int,
|
||||
|
||||
// SetDefaultHook sets function that is called when the GetHover method of
|
||||
// the parent MockLsifStore instance is invoked and the hook queue is empty.
|
||||
func (f *LsifStoreGetHoverFunc) SetDefaultHook(hook func(context.Context, int, string, int, int) (string, shared.Range, bool, error)) {
|
||||
func (f *LsifStoreGetHoverFunc) SetDefaultHook(hook func(context.Context, int, string, int, int) (string, types.Range, bool, error)) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
@ -908,7 +771,7 @@ func (f *LsifStoreGetHoverFunc) SetDefaultHook(hook func(context.Context, int, s
|
||||
// GetHover method of the parent MockLsifStore instance invokes the hook at
|
||||
// the front of the queue and discards it. After the queue is empty, the
|
||||
// default hook function is invoked for any future action.
|
||||
func (f *LsifStoreGetHoverFunc) PushHook(hook func(context.Context, int, string, int, int) (string, shared.Range, bool, error)) {
|
||||
func (f *LsifStoreGetHoverFunc) PushHook(hook func(context.Context, int, string, int, int) (string, types.Range, bool, error)) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
@ -916,20 +779,20 @@ func (f *LsifStoreGetHoverFunc) PushHook(hook func(context.Context, int, string,
|
||||
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *LsifStoreGetHoverFunc) SetDefaultReturn(r0 string, r1 shared.Range, r2 bool, r3 error) {
|
||||
f.SetDefaultHook(func(context.Context, int, string, int, int) (string, shared.Range, bool, error) {
|
||||
func (f *LsifStoreGetHoverFunc) SetDefaultReturn(r0 string, r1 types.Range, r2 bool, r3 error) {
|
||||
f.SetDefaultHook(func(context.Context, int, string, int, int) (string, types.Range, bool, error) {
|
||||
return r0, r1, r2, r3
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *LsifStoreGetHoverFunc) PushReturn(r0 string, r1 shared.Range, r2 bool, r3 error) {
|
||||
f.PushHook(func(context.Context, int, string, int, int) (string, shared.Range, bool, error) {
|
||||
func (f *LsifStoreGetHoverFunc) PushReturn(r0 string, r1 types.Range, r2 bool, r3 error) {
|
||||
f.PushHook(func(context.Context, int, string, int, int) (string, types.Range, bool, error) {
|
||||
return r0, r1, r2, r3
|
||||
})
|
||||
}
|
||||
|
||||
func (f *LsifStoreGetHoverFunc) nextHook() func(context.Context, int, string, int, int) (string, shared.Range, bool, error) {
|
||||
func (f *LsifStoreGetHoverFunc) nextHook() func(context.Context, int, string, int, int) (string, types.Range, bool, error) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
@ -982,7 +845,7 @@ type LsifStoreGetHoverFuncCall struct {
|
||||
Result0 string
|
||||
// Result1 is the value of the 2nd result returned from this method
|
||||
// invocation.
|
||||
Result1 shared.Range
|
||||
Result1 types.Range
|
||||
// Result2 is the value of the 3rd result returned from this method
|
||||
// invocation.
|
||||
Result2 bool
|
||||
@ -1728,15 +1591,15 @@ func (c LsifStoreGetReferenceLocationsFuncCall) Results() []interface{} {
|
||||
// LsifStoreGetStencilFunc describes the behavior when the GetStencil method
|
||||
// of the parent MockLsifStore instance is invoked.
|
||||
type LsifStoreGetStencilFunc struct {
|
||||
defaultHook func(context.Context, int, string) ([]shared.Range, error)
|
||||
hooks []func(context.Context, int, string) ([]shared.Range, error)
|
||||
defaultHook func(context.Context, int, string) ([]types.Range, error)
|
||||
hooks []func(context.Context, int, string) ([]types.Range, error)
|
||||
history []LsifStoreGetStencilFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// GetStencil delegates to the next hook function in the queue and stores
|
||||
// the parameter and result values of this invocation.
|
||||
func (m *MockLsifStore) GetStencil(v0 context.Context, v1 int, v2 string) ([]shared.Range, error) {
|
||||
func (m *MockLsifStore) GetStencil(v0 context.Context, v1 int, v2 string) ([]types.Range, error) {
|
||||
r0, r1 := m.GetStencilFunc.nextHook()(v0, v1, v2)
|
||||
m.GetStencilFunc.appendCall(LsifStoreGetStencilFuncCall{v0, v1, v2, r0, r1})
|
||||
return r0, r1
|
||||
@ -1744,7 +1607,7 @@ func (m *MockLsifStore) GetStencil(v0 context.Context, v1 int, v2 string) ([]sha
|
||||
|
||||
// SetDefaultHook sets function that is called when the GetStencil method of
|
||||
// the parent MockLsifStore instance is invoked and the hook queue is empty.
|
||||
func (f *LsifStoreGetStencilFunc) SetDefaultHook(hook func(context.Context, int, string) ([]shared.Range, error)) {
|
||||
func (f *LsifStoreGetStencilFunc) SetDefaultHook(hook func(context.Context, int, string) ([]types.Range, error)) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
@ -1752,7 +1615,7 @@ func (f *LsifStoreGetStencilFunc) SetDefaultHook(hook func(context.Context, int,
|
||||
// GetStencil method of the parent MockLsifStore instance invokes the hook
|
||||
// at the front of the queue and discards it. After the queue is empty, the
|
||||
// default hook function is invoked for any future action.
|
||||
func (f *LsifStoreGetStencilFunc) PushHook(hook func(context.Context, int, string) ([]shared.Range, error)) {
|
||||
func (f *LsifStoreGetStencilFunc) PushHook(hook func(context.Context, int, string) ([]types.Range, error)) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
@ -1760,20 +1623,20 @@ func (f *LsifStoreGetStencilFunc) PushHook(hook func(context.Context, int, strin
|
||||
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *LsifStoreGetStencilFunc) SetDefaultReturn(r0 []shared.Range, r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, int, string) ([]shared.Range, error) {
|
||||
func (f *LsifStoreGetStencilFunc) SetDefaultReturn(r0 []types.Range, r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, int, string) ([]types.Range, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *LsifStoreGetStencilFunc) PushReturn(r0 []shared.Range, r1 error) {
|
||||
f.PushHook(func(context.Context, int, string) ([]shared.Range, error) {
|
||||
func (f *LsifStoreGetStencilFunc) PushReturn(r0 []types.Range, r1 error) {
|
||||
f.PushHook(func(context.Context, int, string) ([]types.Range, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
func (f *LsifStoreGetStencilFunc) nextHook() func(context.Context, int, string) ([]shared.Range, error) {
|
||||
func (f *LsifStoreGetStencilFunc) nextHook() func(context.Context, int, string) ([]types.Range, error) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
@ -1817,7 +1680,7 @@ type LsifStoreGetStencilFuncCall struct {
|
||||
Arg2 string
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// invocation.
|
||||
Result0 []shared.Range
|
||||
Result0 []types.Range
|
||||
// Result1 is the value of the 2nd result returned from this method
|
||||
// invocation.
|
||||
Result1 error
|
||||
@ -2145,12 +2008,12 @@ func NewMockGitTreeTranslator() *MockGitTreeTranslator {
|
||||
},
|
||||
},
|
||||
GetTargetCommitPositionFromSourcePositionFunc: &GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc{
|
||||
defaultHook: func(context.Context, string, shared.Position, bool) (r0 string, r1 shared.Position, r2 bool, r3 error) {
|
||||
defaultHook: func(context.Context, string, types.Position, bool) (r0 string, r1 types.Position, r2 bool, r3 error) {
|
||||
return
|
||||
},
|
||||
},
|
||||
GetTargetCommitRangeFromSourceRangeFunc: &GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc{
|
||||
defaultHook: func(context.Context, string, string, shared.Range, bool) (r0 string, r1 shared.Range, r2 bool, r3 error) {
|
||||
defaultHook: func(context.Context, string, string, types.Range, bool) (r0 string, r1 types.Range, r2 bool, r3 error) {
|
||||
return
|
||||
},
|
||||
},
|
||||
@ -2168,12 +2031,12 @@ func NewStrictMockGitTreeTranslator() *MockGitTreeTranslator {
|
||||
},
|
||||
},
|
||||
GetTargetCommitPositionFromSourcePositionFunc: &GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc{
|
||||
defaultHook: func(context.Context, string, shared.Position, bool) (string, shared.Position, bool, error) {
|
||||
defaultHook: func(context.Context, string, types.Position, bool) (string, types.Position, bool, error) {
|
||||
panic("unexpected invocation of MockGitTreeTranslator.GetTargetCommitPositionFromSourcePosition")
|
||||
},
|
||||
},
|
||||
GetTargetCommitRangeFromSourceRangeFunc: &GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc{
|
||||
defaultHook: func(context.Context, string, string, shared.Range, bool) (string, shared.Range, bool, error) {
|
||||
defaultHook: func(context.Context, string, string, types.Range, bool) (string, types.Range, bool, error) {
|
||||
panic("unexpected invocation of MockGitTreeTranslator.GetTargetCommitRangeFromSourceRange")
|
||||
},
|
||||
},
|
||||
@ -2322,8 +2185,8 @@ func (c GitTreeTranslatorGetTargetCommitPathFromSourcePathFuncCall) Results() []
|
||||
// the behavior when the GetTargetCommitPositionFromSourcePosition method of
|
||||
// the parent MockGitTreeTranslator instance is invoked.
|
||||
type GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc struct {
|
||||
defaultHook func(context.Context, string, shared.Position, bool) (string, shared.Position, bool, error)
|
||||
hooks []func(context.Context, string, shared.Position, bool) (string, shared.Position, bool, error)
|
||||
defaultHook func(context.Context, string, types.Position, bool) (string, types.Position, bool, error)
|
||||
hooks []func(context.Context, string, types.Position, bool) (string, types.Position, bool, error)
|
||||
history []GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
@ -2331,7 +2194,7 @@ type GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc struct {
|
||||
// GetTargetCommitPositionFromSourcePosition delegates to the next hook
|
||||
// function in the queue and stores the parameter and result values of this
|
||||
// invocation.
|
||||
func (m *MockGitTreeTranslator) GetTargetCommitPositionFromSourcePosition(v0 context.Context, v1 string, v2 shared.Position, v3 bool) (string, shared.Position, bool, error) {
|
||||
func (m *MockGitTreeTranslator) GetTargetCommitPositionFromSourcePosition(v0 context.Context, v1 string, v2 types.Position, v3 bool) (string, types.Position, bool, error) {
|
||||
r0, r1, r2, r3 := m.GetTargetCommitPositionFromSourcePositionFunc.nextHook()(v0, v1, v2, v3)
|
||||
m.GetTargetCommitPositionFromSourcePositionFunc.appendCall(GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFuncCall{v0, v1, v2, v3, r0, r1, r2, r3})
|
||||
return r0, r1, r2, r3
|
||||
@ -2340,7 +2203,7 @@ func (m *MockGitTreeTranslator) GetTargetCommitPositionFromSourcePosition(v0 con
|
||||
// SetDefaultHook sets function that is called when the
|
||||
// GetTargetCommitPositionFromSourcePosition method of the parent
|
||||
// MockGitTreeTranslator instance is invoked and the hook queue is empty.
|
||||
func (f *GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc) SetDefaultHook(hook func(context.Context, string, shared.Position, bool) (string, shared.Position, bool, error)) {
|
||||
func (f *GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc) SetDefaultHook(hook func(context.Context, string, types.Position, bool) (string, types.Position, bool, error)) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
@ -2349,7 +2212,7 @@ func (f *GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc) SetDefa
|
||||
// MockGitTreeTranslator instance invokes the hook at the front of the queue
|
||||
// and discards it. After the queue is empty, the default hook function is
|
||||
// invoked for any future action.
|
||||
func (f *GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc) PushHook(hook func(context.Context, string, shared.Position, bool) (string, shared.Position, bool, error)) {
|
||||
func (f *GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc) PushHook(hook func(context.Context, string, types.Position, bool) (string, types.Position, bool, error)) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
@ -2357,20 +2220,20 @@ func (f *GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc) PushHoo
|
||||
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc) SetDefaultReturn(r0 string, r1 shared.Position, r2 bool, r3 error) {
|
||||
f.SetDefaultHook(func(context.Context, string, shared.Position, bool) (string, shared.Position, bool, error) {
|
||||
func (f *GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc) SetDefaultReturn(r0 string, r1 types.Position, r2 bool, r3 error) {
|
||||
f.SetDefaultHook(func(context.Context, string, types.Position, bool) (string, types.Position, bool, error) {
|
||||
return r0, r1, r2, r3
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc) PushReturn(r0 string, r1 shared.Position, r2 bool, r3 error) {
|
||||
f.PushHook(func(context.Context, string, shared.Position, bool) (string, shared.Position, bool, error) {
|
||||
func (f *GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc) PushReturn(r0 string, r1 types.Position, r2 bool, r3 error) {
|
||||
f.PushHook(func(context.Context, string, types.Position, bool) (string, types.Position, bool, error) {
|
||||
return r0, r1, r2, r3
|
||||
})
|
||||
}
|
||||
|
||||
func (f *GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc) nextHook() func(context.Context, string, shared.Position, bool) (string, shared.Position, bool, error) {
|
||||
func (f *GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFunc) nextHook() func(context.Context, string, types.Position, bool) (string, types.Position, bool, error) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
@ -2414,7 +2277,7 @@ type GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFuncCall struct {
|
||||
Arg1 string
|
||||
// Arg2 is the value of the 3rd argument passed to this method
|
||||
// invocation.
|
||||
Arg2 shared.Position
|
||||
Arg2 types.Position
|
||||
// Arg3 is the value of the 4th argument passed to this method
|
||||
// invocation.
|
||||
Arg3 bool
|
||||
@ -2423,7 +2286,7 @@ type GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFuncCall struct {
|
||||
Result0 string
|
||||
// Result1 is the value of the 2nd result returned from this method
|
||||
// invocation.
|
||||
Result1 shared.Position
|
||||
Result1 types.Position
|
||||
// Result2 is the value of the 3rd result returned from this method
|
||||
// invocation.
|
||||
Result2 bool
|
||||
@ -2448,8 +2311,8 @@ func (c GitTreeTranslatorGetTargetCommitPositionFromSourcePositionFuncCall) Resu
|
||||
// behavior when the GetTargetCommitRangeFromSourceRange method of the
|
||||
// parent MockGitTreeTranslator instance is invoked.
|
||||
type GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc struct {
|
||||
defaultHook func(context.Context, string, string, shared.Range, bool) (string, shared.Range, bool, error)
|
||||
hooks []func(context.Context, string, string, shared.Range, bool) (string, shared.Range, bool, error)
|
||||
defaultHook func(context.Context, string, string, types.Range, bool) (string, types.Range, bool, error)
|
||||
hooks []func(context.Context, string, string, types.Range, bool) (string, types.Range, bool, error)
|
||||
history []GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
@ -2457,7 +2320,7 @@ type GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc struct {
|
||||
// GetTargetCommitRangeFromSourceRange delegates to the next hook function
|
||||
// in the queue and stores the parameter and result values of this
|
||||
// invocation.
|
||||
func (m *MockGitTreeTranslator) GetTargetCommitRangeFromSourceRange(v0 context.Context, v1 string, v2 string, v3 shared.Range, v4 bool) (string, shared.Range, bool, error) {
|
||||
func (m *MockGitTreeTranslator) GetTargetCommitRangeFromSourceRange(v0 context.Context, v1 string, v2 string, v3 types.Range, v4 bool) (string, types.Range, bool, error) {
|
||||
r0, r1, r2, r3 := m.GetTargetCommitRangeFromSourceRangeFunc.nextHook()(v0, v1, v2, v3, v4)
|
||||
m.GetTargetCommitRangeFromSourceRangeFunc.appendCall(GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFuncCall{v0, v1, v2, v3, v4, r0, r1, r2, r3})
|
||||
return r0, r1, r2, r3
|
||||
@ -2466,7 +2329,7 @@ func (m *MockGitTreeTranslator) GetTargetCommitRangeFromSourceRange(v0 context.C
|
||||
// SetDefaultHook sets function that is called when the
|
||||
// GetTargetCommitRangeFromSourceRange method of the parent
|
||||
// MockGitTreeTranslator instance is invoked and the hook queue is empty.
|
||||
func (f *GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc) SetDefaultHook(hook func(context.Context, string, string, shared.Range, bool) (string, shared.Range, bool, error)) {
|
||||
func (f *GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc) SetDefaultHook(hook func(context.Context, string, string, types.Range, bool) (string, types.Range, bool, error)) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
@ -2475,7 +2338,7 @@ func (f *GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc) SetDefaultHoo
|
||||
// MockGitTreeTranslator instance invokes the hook at the front of the queue
|
||||
// and discards it. After the queue is empty, the default hook function is
|
||||
// invoked for any future action.
|
||||
func (f *GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc) PushHook(hook func(context.Context, string, string, shared.Range, bool) (string, shared.Range, bool, error)) {
|
||||
func (f *GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc) PushHook(hook func(context.Context, string, string, types.Range, bool) (string, types.Range, bool, error)) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
@ -2483,20 +2346,20 @@ func (f *GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc) PushHook(hook
|
||||
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc) SetDefaultReturn(r0 string, r1 shared.Range, r2 bool, r3 error) {
|
||||
f.SetDefaultHook(func(context.Context, string, string, shared.Range, bool) (string, shared.Range, bool, error) {
|
||||
func (f *GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc) SetDefaultReturn(r0 string, r1 types.Range, r2 bool, r3 error) {
|
||||
f.SetDefaultHook(func(context.Context, string, string, types.Range, bool) (string, types.Range, bool, error) {
|
||||
return r0, r1, r2, r3
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc) PushReturn(r0 string, r1 shared.Range, r2 bool, r3 error) {
|
||||
f.PushHook(func(context.Context, string, string, shared.Range, bool) (string, shared.Range, bool, error) {
|
||||
func (f *GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc) PushReturn(r0 string, r1 types.Range, r2 bool, r3 error) {
|
||||
f.PushHook(func(context.Context, string, string, types.Range, bool) (string, types.Range, bool, error) {
|
||||
return r0, r1, r2, r3
|
||||
})
|
||||
}
|
||||
|
||||
func (f *GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc) nextHook() func(context.Context, string, string, shared.Range, bool) (string, shared.Range, bool, error) {
|
||||
func (f *GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFunc) nextHook() func(context.Context, string, string, types.Range, bool) (string, types.Range, bool, error) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
@ -2543,7 +2406,7 @@ type GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFuncCall struct {
|
||||
Arg2 string
|
||||
// Arg3 is the value of the 4th argument passed to this method
|
||||
// invocation.
|
||||
Arg3 shared.Range
|
||||
Arg3 types.Range
|
||||
// Arg4 is the value of the 5th argument passed to this method
|
||||
// invocation.
|
||||
Arg4 bool
|
||||
@ -2552,7 +2415,7 @@ type GitTreeTranslatorGetTargetCommitRangeFromSourceRangeFuncCall struct {
|
||||
Result0 string
|
||||
// Result1 is the value of the 2nd result returned from this method
|
||||
// invocation.
|
||||
Result1 shared.Range
|
||||
Result1 types.Range
|
||||
// Result2 is the value of the 3rd result returned from this method
|
||||
// invocation.
|
||||
Result2 bool
|
||||
@ -2890,12 +2753,12 @@ type MockUploadService struct {
|
||||
func NewMockUploadService() *MockUploadService {
|
||||
return &MockUploadService{
|
||||
GetDumpsByIDsFunc: &UploadServiceGetDumpsByIDsFunc{
|
||||
defaultHook: func(context.Context, []int) (r0 []shared1.Dump, r1 error) {
|
||||
defaultHook: func(context.Context, []int) (r0 []types.Dump, r1 error) {
|
||||
return
|
||||
},
|
||||
},
|
||||
GetDumpsWithDefinitionsForMonikersFunc: &UploadServiceGetDumpsWithDefinitionsForMonikersFunc{
|
||||
defaultHook: func(context.Context, []precise.QualifiedMonikerData) (r0 []shared1.Dump, r1 error) {
|
||||
defaultHook: func(context.Context, []precise.QualifiedMonikerData) (r0 []types.Dump, r1 error) {
|
||||
return
|
||||
},
|
||||
},
|
||||
@ -2905,7 +2768,7 @@ func NewMockUploadService() *MockUploadService {
|
||||
},
|
||||
},
|
||||
InferClosestUploadsFunc: &UploadServiceInferClosestUploadsFunc{
|
||||
defaultHook: func(context.Context, int, string, string, bool, string) (r0 []shared1.Dump, r1 error) {
|
||||
defaultHook: func(context.Context, int, string, string, bool, string) (r0 []types.Dump, r1 error) {
|
||||
return
|
||||
},
|
||||
},
|
||||
@ -2917,12 +2780,12 @@ func NewMockUploadService() *MockUploadService {
|
||||
func NewStrictMockUploadService() *MockUploadService {
|
||||
return &MockUploadService{
|
||||
GetDumpsByIDsFunc: &UploadServiceGetDumpsByIDsFunc{
|
||||
defaultHook: func(context.Context, []int) ([]shared1.Dump, error) {
|
||||
defaultHook: func(context.Context, []int) ([]types.Dump, error) {
|
||||
panic("unexpected invocation of MockUploadService.GetDumpsByIDs")
|
||||
},
|
||||
},
|
||||
GetDumpsWithDefinitionsForMonikersFunc: &UploadServiceGetDumpsWithDefinitionsForMonikersFunc{
|
||||
defaultHook: func(context.Context, []precise.QualifiedMonikerData) ([]shared1.Dump, error) {
|
||||
defaultHook: func(context.Context, []precise.QualifiedMonikerData) ([]types.Dump, error) {
|
||||
panic("unexpected invocation of MockUploadService.GetDumpsWithDefinitionsForMonikers")
|
||||
},
|
||||
},
|
||||
@ -2932,7 +2795,7 @@ func NewStrictMockUploadService() *MockUploadService {
|
||||
},
|
||||
},
|
||||
InferClosestUploadsFunc: &UploadServiceInferClosestUploadsFunc{
|
||||
defaultHook: func(context.Context, int, string, string, bool, string) ([]shared1.Dump, error) {
|
||||
defaultHook: func(context.Context, int, string, string, bool, string) ([]types.Dump, error) {
|
||||
panic("unexpected invocation of MockUploadService.InferClosestUploads")
|
||||
},
|
||||
},
|
||||
@ -2962,15 +2825,15 @@ func NewMockUploadServiceFrom(i UploadService) *MockUploadService {
|
||||
// UploadServiceGetDumpsByIDsFunc describes the behavior when the
|
||||
// GetDumpsByIDs method of the parent MockUploadService instance is invoked.
|
||||
type UploadServiceGetDumpsByIDsFunc struct {
|
||||
defaultHook func(context.Context, []int) ([]shared1.Dump, error)
|
||||
hooks []func(context.Context, []int) ([]shared1.Dump, error)
|
||||
defaultHook func(context.Context, []int) ([]types.Dump, error)
|
||||
hooks []func(context.Context, []int) ([]types.Dump, error)
|
||||
history []UploadServiceGetDumpsByIDsFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// GetDumpsByIDs delegates to the next hook function in the queue and stores
|
||||
// the parameter and result values of this invocation.
|
||||
func (m *MockUploadService) GetDumpsByIDs(v0 context.Context, v1 []int) ([]shared1.Dump, error) {
|
||||
func (m *MockUploadService) GetDumpsByIDs(v0 context.Context, v1 []int) ([]types.Dump, error) {
|
||||
r0, r1 := m.GetDumpsByIDsFunc.nextHook()(v0, v1)
|
||||
m.GetDumpsByIDsFunc.appendCall(UploadServiceGetDumpsByIDsFuncCall{v0, v1, r0, r1})
|
||||
return r0, r1
|
||||
@ -2979,7 +2842,7 @@ func (m *MockUploadService) GetDumpsByIDs(v0 context.Context, v1 []int) ([]share
|
||||
// SetDefaultHook sets function that is called when the GetDumpsByIDs method
|
||||
// of the parent MockUploadService instance is invoked and the hook queue is
|
||||
// empty.
|
||||
func (f *UploadServiceGetDumpsByIDsFunc) SetDefaultHook(hook func(context.Context, []int) ([]shared1.Dump, error)) {
|
||||
func (f *UploadServiceGetDumpsByIDsFunc) SetDefaultHook(hook func(context.Context, []int) ([]types.Dump, error)) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
@ -2987,7 +2850,7 @@ func (f *UploadServiceGetDumpsByIDsFunc) SetDefaultHook(hook func(context.Contex
|
||||
// GetDumpsByIDs method of the parent MockUploadService instance invokes the
|
||||
// hook at the front of the queue and discards it. After the queue is empty,
|
||||
// the default hook function is invoked for any future action.
|
||||
func (f *UploadServiceGetDumpsByIDsFunc) PushHook(hook func(context.Context, []int) ([]shared1.Dump, error)) {
|
||||
func (f *UploadServiceGetDumpsByIDsFunc) PushHook(hook func(context.Context, []int) ([]types.Dump, error)) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
@ -2995,20 +2858,20 @@ func (f *UploadServiceGetDumpsByIDsFunc) PushHook(hook func(context.Context, []i
|
||||
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *UploadServiceGetDumpsByIDsFunc) SetDefaultReturn(r0 []shared1.Dump, r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, []int) ([]shared1.Dump, error) {
|
||||
func (f *UploadServiceGetDumpsByIDsFunc) SetDefaultReturn(r0 []types.Dump, r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, []int) ([]types.Dump, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *UploadServiceGetDumpsByIDsFunc) PushReturn(r0 []shared1.Dump, r1 error) {
|
||||
f.PushHook(func(context.Context, []int) ([]shared1.Dump, error) {
|
||||
func (f *UploadServiceGetDumpsByIDsFunc) PushReturn(r0 []types.Dump, r1 error) {
|
||||
f.PushHook(func(context.Context, []int) ([]types.Dump, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
func (f *UploadServiceGetDumpsByIDsFunc) nextHook() func(context.Context, []int) ([]shared1.Dump, error) {
|
||||
func (f *UploadServiceGetDumpsByIDsFunc) nextHook() func(context.Context, []int) ([]types.Dump, error) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
@ -3049,7 +2912,7 @@ type UploadServiceGetDumpsByIDsFuncCall struct {
|
||||
Arg1 []int
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// invocation.
|
||||
Result0 []shared1.Dump
|
||||
Result0 []types.Dump
|
||||
// Result1 is the value of the 2nd result returned from this method
|
||||
// invocation.
|
||||
Result1 error
|
||||
@ -3071,15 +2934,15 @@ func (c UploadServiceGetDumpsByIDsFuncCall) Results() []interface{} {
|
||||
// behavior when the GetDumpsWithDefinitionsForMonikers method of the parent
|
||||
// MockUploadService instance is invoked.
|
||||
type UploadServiceGetDumpsWithDefinitionsForMonikersFunc struct {
|
||||
defaultHook func(context.Context, []precise.QualifiedMonikerData) ([]shared1.Dump, error)
|
||||
hooks []func(context.Context, []precise.QualifiedMonikerData) ([]shared1.Dump, error)
|
||||
defaultHook func(context.Context, []precise.QualifiedMonikerData) ([]types.Dump, error)
|
||||
hooks []func(context.Context, []precise.QualifiedMonikerData) ([]types.Dump, error)
|
||||
history []UploadServiceGetDumpsWithDefinitionsForMonikersFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// GetDumpsWithDefinitionsForMonikers delegates to the next hook function in
|
||||
// the queue and stores the parameter and result values of this invocation.
|
||||
func (m *MockUploadService) GetDumpsWithDefinitionsForMonikers(v0 context.Context, v1 []precise.QualifiedMonikerData) ([]shared1.Dump, error) {
|
||||
func (m *MockUploadService) GetDumpsWithDefinitionsForMonikers(v0 context.Context, v1 []precise.QualifiedMonikerData) ([]types.Dump, error) {
|
||||
r0, r1 := m.GetDumpsWithDefinitionsForMonikersFunc.nextHook()(v0, v1)
|
||||
m.GetDumpsWithDefinitionsForMonikersFunc.appendCall(UploadServiceGetDumpsWithDefinitionsForMonikersFuncCall{v0, v1, r0, r1})
|
||||
return r0, r1
|
||||
@ -3088,7 +2951,7 @@ func (m *MockUploadService) GetDumpsWithDefinitionsForMonikers(v0 context.Contex
|
||||
// SetDefaultHook sets function that is called when the
|
||||
// GetDumpsWithDefinitionsForMonikers method of the parent MockUploadService
|
||||
// instance is invoked and the hook queue is empty.
|
||||
func (f *UploadServiceGetDumpsWithDefinitionsForMonikersFunc) SetDefaultHook(hook func(context.Context, []precise.QualifiedMonikerData) ([]shared1.Dump, error)) {
|
||||
func (f *UploadServiceGetDumpsWithDefinitionsForMonikersFunc) SetDefaultHook(hook func(context.Context, []precise.QualifiedMonikerData) ([]types.Dump, error)) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
@ -3097,7 +2960,7 @@ func (f *UploadServiceGetDumpsWithDefinitionsForMonikersFunc) SetDefaultHook(hoo
|
||||
// instance invokes the hook at the front of the queue and discards it.
|
||||
// After the queue is empty, the default hook function is invoked for any
|
||||
// future action.
|
||||
func (f *UploadServiceGetDumpsWithDefinitionsForMonikersFunc) PushHook(hook func(context.Context, []precise.QualifiedMonikerData) ([]shared1.Dump, error)) {
|
||||
func (f *UploadServiceGetDumpsWithDefinitionsForMonikersFunc) PushHook(hook func(context.Context, []precise.QualifiedMonikerData) ([]types.Dump, error)) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
@ -3105,20 +2968,20 @@ func (f *UploadServiceGetDumpsWithDefinitionsForMonikersFunc) PushHook(hook func
|
||||
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *UploadServiceGetDumpsWithDefinitionsForMonikersFunc) SetDefaultReturn(r0 []shared1.Dump, r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, []precise.QualifiedMonikerData) ([]shared1.Dump, error) {
|
||||
func (f *UploadServiceGetDumpsWithDefinitionsForMonikersFunc) SetDefaultReturn(r0 []types.Dump, r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, []precise.QualifiedMonikerData) ([]types.Dump, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *UploadServiceGetDumpsWithDefinitionsForMonikersFunc) PushReturn(r0 []shared1.Dump, r1 error) {
|
||||
f.PushHook(func(context.Context, []precise.QualifiedMonikerData) ([]shared1.Dump, error) {
|
||||
func (f *UploadServiceGetDumpsWithDefinitionsForMonikersFunc) PushReturn(r0 []types.Dump, r1 error) {
|
||||
f.PushHook(func(context.Context, []precise.QualifiedMonikerData) ([]types.Dump, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
func (f *UploadServiceGetDumpsWithDefinitionsForMonikersFunc) nextHook() func(context.Context, []precise.QualifiedMonikerData) ([]shared1.Dump, error) {
|
||||
func (f *UploadServiceGetDumpsWithDefinitionsForMonikersFunc) nextHook() func(context.Context, []precise.QualifiedMonikerData) ([]types.Dump, error) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
@ -3161,7 +3024,7 @@ type UploadServiceGetDumpsWithDefinitionsForMonikersFuncCall struct {
|
||||
Arg1 []precise.QualifiedMonikerData
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// invocation.
|
||||
Result0 []shared1.Dump
|
||||
Result0 []types.Dump
|
||||
// Result1 is the value of the 2nd result returned from this method
|
||||
// invocation.
|
||||
Result1 error
|
||||
@ -3316,15 +3179,15 @@ func (c UploadServiceGetUploadIDsWithReferencesFuncCall) Results() []interface{}
|
||||
// InferClosestUploads method of the parent MockUploadService instance is
|
||||
// invoked.
|
||||
type UploadServiceInferClosestUploadsFunc struct {
|
||||
defaultHook func(context.Context, int, string, string, bool, string) ([]shared1.Dump, error)
|
||||
hooks []func(context.Context, int, string, string, bool, string) ([]shared1.Dump, error)
|
||||
defaultHook func(context.Context, int, string, string, bool, string) ([]types.Dump, error)
|
||||
hooks []func(context.Context, int, string, string, bool, string) ([]types.Dump, error)
|
||||
history []UploadServiceInferClosestUploadsFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// InferClosestUploads delegates to the next hook function in the queue and
|
||||
// stores the parameter and result values of this invocation.
|
||||
func (m *MockUploadService) InferClosestUploads(v0 context.Context, v1 int, v2 string, v3 string, v4 bool, v5 string) ([]shared1.Dump, error) {
|
||||
func (m *MockUploadService) InferClosestUploads(v0 context.Context, v1 int, v2 string, v3 string, v4 bool, v5 string) ([]types.Dump, error) {
|
||||
r0, r1 := m.InferClosestUploadsFunc.nextHook()(v0, v1, v2, v3, v4, v5)
|
||||
m.InferClosestUploadsFunc.appendCall(UploadServiceInferClosestUploadsFuncCall{v0, v1, v2, v3, v4, v5, r0, r1})
|
||||
return r0, r1
|
||||
@ -3333,7 +3196,7 @@ func (m *MockUploadService) InferClosestUploads(v0 context.Context, v1 int, v2 s
|
||||
// SetDefaultHook sets function that is called when the InferClosestUploads
|
||||
// method of the parent MockUploadService instance is invoked and the hook
|
||||
// queue is empty.
|
||||
func (f *UploadServiceInferClosestUploadsFunc) SetDefaultHook(hook func(context.Context, int, string, string, bool, string) ([]shared1.Dump, error)) {
|
||||
func (f *UploadServiceInferClosestUploadsFunc) SetDefaultHook(hook func(context.Context, int, string, string, bool, string) ([]types.Dump, error)) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
@ -3342,7 +3205,7 @@ func (f *UploadServiceInferClosestUploadsFunc) SetDefaultHook(hook func(context.
|
||||
// invokes the hook at the front of the queue and discards it. After the
|
||||
// queue is empty, the default hook function is invoked for any future
|
||||
// action.
|
||||
func (f *UploadServiceInferClosestUploadsFunc) PushHook(hook func(context.Context, int, string, string, bool, string) ([]shared1.Dump, error)) {
|
||||
func (f *UploadServiceInferClosestUploadsFunc) PushHook(hook func(context.Context, int, string, string, bool, string) ([]types.Dump, error)) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
@ -3350,20 +3213,20 @@ func (f *UploadServiceInferClosestUploadsFunc) PushHook(hook func(context.Contex
|
||||
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *UploadServiceInferClosestUploadsFunc) SetDefaultReturn(r0 []shared1.Dump, r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, int, string, string, bool, string) ([]shared1.Dump, error) {
|
||||
func (f *UploadServiceInferClosestUploadsFunc) SetDefaultReturn(r0 []types.Dump, r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, int, string, string, bool, string) ([]types.Dump, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *UploadServiceInferClosestUploadsFunc) PushReturn(r0 []shared1.Dump, r1 error) {
|
||||
f.PushHook(func(context.Context, int, string, string, bool, string) ([]shared1.Dump, error) {
|
||||
func (f *UploadServiceInferClosestUploadsFunc) PushReturn(r0 []types.Dump, r1 error) {
|
||||
f.PushHook(func(context.Context, int, string, string, bool, string) ([]types.Dump, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
func (f *UploadServiceInferClosestUploadsFunc) nextHook() func(context.Context, int, string, string, bool, string) ([]shared1.Dump, error) {
|
||||
func (f *UploadServiceInferClosestUploadsFunc) nextHook() func(context.Context, int, string, string, bool, string) ([]types.Dump, error) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
@ -3417,7 +3280,7 @@ type UploadServiceInferClosestUploadsFuncCall struct {
|
||||
Arg5 string
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// invocation.
|
||||
Result0 []shared1.Dump
|
||||
Result0 []types.Dump
|
||||
// Result1 is the value of the 2nd result returned from this method
|
||||
// invocation.
|
||||
Result1 error
|
||||
|
||||
@ -26,8 +26,6 @@ type operations struct {
|
||||
getUploadIDsWithReferences *observation.Operation
|
||||
getDumpsByIDs *observation.Operation
|
||||
getClosestDumpsForBlob *observation.Operation
|
||||
getLanguagesRequestedBy *observation.Operation
|
||||
setRequestLanguageSupport *observation.Operation
|
||||
}
|
||||
|
||||
func newOperations(observationContext *observation.Context) *operations {
|
||||
@ -61,8 +59,6 @@ func newOperations(observationContext *observation.Context) *operations {
|
||||
getUploadIDsWithReferences: op("GetUploadIDsWithReferences"),
|
||||
getDumpsByIDs: op("GetDumpsByIDs"),
|
||||
getClosestDumpsForBlob: op("GetClosestDumpsForBlob"),
|
||||
getLanguagesRequestedBy: op("GetLanguagesRequestedBy"),
|
||||
setRequestLanguageSupport: op("SetRequestLanguageSupport"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user