Skip to content

Commit

Permalink
Support line numbers in filesystem source (#1297)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyanshak committed May 9, 2023
1 parent fad34d4 commit 584db86
Show file tree
Hide file tree
Showing 4 changed files with 299 additions and 284 deletions.
11 changes: 7 additions & 4 deletions pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,9 @@ func (e *Engine) detectorWorker(ctx context.Context) {
}
}

// gitSources is a list of sources that utilize the Git source. It is stored this way because slice consts are not
// supported.
func gitSources() []sourcespb.SourceType {
// lineNumberSupportedSources is a list of sources that support line numbers.
// It is stored this way because slice consts are not supported.
func lineNumberSupportedSources() []sourcespb.SourceType {
return []sourcespb.SourceType{
sourcespb.SourceType_SOURCE_TYPE_GIT,
sourcespb.SourceType_SOURCE_TYPE_GITHUB,
Expand All @@ -352,12 +352,13 @@ func gitSources() []sourcespb.SourceType {
sourcespb.SourceType_SOURCE_TYPE_GERRIT,
sourcespb.SourceType_SOURCE_TYPE_GITHUB_UNAUTHENTICATED_ORG,
sourcespb.SourceType_SOURCE_TYPE_PUBLIC_GIT,
sourcespb.SourceType_SOURCE_TYPE_FILESYSTEM,
}
}

// SupportsLineNumbers determines if a line number can be found for a source type.
func SupportsLineNumbers(sourceType sourcespb.SourceType) bool {
for _, i := range gitSources() {
for _, i := range lineNumberSupportedSources() {
if i == sourceType {
return true
}
Expand Down Expand Up @@ -391,6 +392,8 @@ func FragmentFirstLine(chunk *sources.Chunk) (int64, *int64) {
fragmentStart = &metadata.Bitbucket.Line
case *source_metadatapb.MetaData_Gerrit:
fragmentStart = &metadata.Gerrit.Line
case *source_metadatapb.MetaData_Filesystem:
fragmentStart = &metadata.Filesystem.Line
default:
return 0, nil
}
Expand Down
Loading

0 comments on commit 584db86

Please sign in to comment.