Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ func (b *deepCodeBundle) extendBundle(ctx context.Context, requestId string, upl
}

const (
maxFileSize = 1024 * 1024
maxUploadBatchSize = 1024*1024*4 - 1024 // subtract 1k for potential headers
jsonOverheadRequest = "{\"files\":{}}"
jsonOverHeadRequestLength = len(jsonOverheadRequest)
Expand Down
56 changes: 7 additions & 49 deletions bundle/bundle_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ package bundle
import (
"context"
"os"
"path/filepath"

"github.com/puzpuzpuz/xsync"
"github.com/rs/zerolog"
"github.com/snyk/code-client-go/internal/util/supportedfiles"

"github.com/snyk/code-client-go/internal/deepcode"
"github.com/snyk/code-client-go/internal/util"
Expand All @@ -38,8 +37,7 @@ type bundleManager struct {
errorReporter observability.ErrorReporter
logger *zerolog.Logger
trackerFactory scan.TrackerFactory
supportedExtensions *xsync.MapOf[string, bool]
supportedConfigFiles *xsync.MapOf[string, bool]
supportedFilesFilter *supportedfiles.SupportedFilesFilter
}

type BundleManager interface {
Expand Down Expand Up @@ -78,8 +76,7 @@ func NewBundleManager(
errorReporter: errorReporter,
logger: logger,
trackerFactory: trackerFactory,
supportedExtensions: xsync.NewMapOf[bool](),
supportedConfigFiles: xsync.NewMapOf[bool](),
supportedFilesFilter: supportedfiles.NewSupportedFilesFilter(deepcodeClient, logger),
}
}

Expand Down Expand Up @@ -125,22 +122,12 @@ func (b *bundleManager) create(
if ctx.Err() != nil {
return bundle, err // The cancellation error should be handled by the calling function
}
var supported bool
supported, err = b.IsSupported(span.Context(), absoluteFilePath)
if err != nil {
return bundle, err
}
if !supported {
continue
}

fileInfo, fileErr := os.Stat(absoluteFilePath)
if fileErr != nil {
b.logger.Error().Err(err).Str("filePath", absoluteFilePath).Msg("Failed to read file info")
continue
supported, filterErr := b.supportedFilesFilter.IsFileSupported(span.Context(), absoluteFilePath)
if filterErr != nil {
return bundle, filterErr
}

if fileInfo.Size() == 0 || fileInfo.Size() > maxFileSize {
if !supported {
continue
}

Expand Down Expand Up @@ -290,32 +277,3 @@ func (b *bundleManager) groupInBatches(
}
return batches
}

func (b *bundleManager) IsSupported(ctx context.Context, file string) (bool, error) {
if b.supportedExtensions.Size() == 0 && b.supportedConfigFiles.Size() == 0 {
filters, err := b.deepcodeClient.GetFilters(ctx)
if err != nil {
b.logger.Error().Err(err).Msg("could not get filters")
return false, err
}

for _, ext := range filters.Extensions {
b.supportedExtensions.Store(ext, true)
}
for _, configFile := range filters.ConfigFiles {
// .gitignore and .dcignore should not be uploaded
// (https://github.com/snyk/code-client/blob/d6f6a2ce4c14cb4b05aa03fb9f03533d8cf6ca4a/src/files.ts#L138)
if configFile == ".gitignore" || configFile == ".dcignore" {
continue
}
b.supportedConfigFiles.Store(configFile, true)
}
}

fileExtension := filepath.Ext(file)
fileName := filepath.Base(file) // Config files are compared to the file name, not just the extensions
_, isSupportedExtension := b.supportedExtensions.Load(fileExtension)
_, isSupportedConfigFile := b.supportedConfigFiles.Load(fileName)

return isSupportedExtension || isSupportedConfigFile, nil
}
82 changes: 0 additions & 82 deletions bundle/bundle_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,88 +455,6 @@ func createTempFileInDir(t *testing.T, name string, size int, temporaryDir strin
return documentURI, deepcode.BundleFile{Hash: hash, ContentSize: size}
}

func Test_IsSupported_Extensions(t *testing.T) {
ctrl := gomock.NewController(t)
mockSnykCodeClient := deepcodeMocks.NewMockDeepcodeClient(ctrl)
mockSnykCodeClient.EXPECT().GetFilters(gomock.Any()).Return(deepcode.FiltersResponse{
ConfigFiles: []string{},
Extensions: []string{".java"},
}, nil)
mockInstrumentor := mocks.NewMockInstrumentor(ctrl)
mockErrorReporter := mocks.NewMockErrorReporter(ctrl)
mockTrackerFactory := trackerMocks.NewMockTrackerFactory(ctrl)

bundler := bundle.NewBundleManager(mockSnykCodeClient, newLogger(t), mockInstrumentor, mockErrorReporter, mockTrackerFactory)

t.Run("should return true for supported languages", func(t *testing.T) {
supported, _ := bundler.IsSupported(t.Context(), "C:\\some\\path\\Test.java")
assert.True(t, supported)
})

t.Run("should return false for unsupported languages", func(t *testing.T) {
supported, _ := bundler.IsSupported(t.Context(), "C:\\some\\path\\Test.rs")
assert.False(t, supported)
})

t.Run("should cache supported extensions", func(t *testing.T) {
path := "C:\\some\\path\\Test.rs"
_, _ = bundler.IsSupported(t.Context(), path)
_, _ = bundler.IsSupported(t.Context(), path)
})
}

func Test_IsSupported_ConfigFiles(t *testing.T) {
configFilesFromFiltersEndpoint := []string{
".supportedConfigFile",
".snyk",
".dcignore",
".gitignore",
}
expectedConfigFiles := []string{ // .dcignore and .gitignore should be excluded
".supportedConfigFile",
".snyk",
}

ctrl := gomock.NewController(t)
mockSnykCodeClient := deepcodeMocks.NewMockDeepcodeClient(ctrl)
mockSnykCodeClient.EXPECT().GetFilters(gomock.Any()).Return(deepcode.FiltersResponse{
ConfigFiles: configFilesFromFiltersEndpoint,
Extensions: []string{},
}, nil)
mockInstrumentor := mocks.NewMockInstrumentor(ctrl)
mockErrorReporter := mocks.NewMockErrorReporter(ctrl)
mockTrackerFactory := trackerMocks.NewMockTrackerFactory(ctrl)

bundler := bundle.NewBundleManager(mockSnykCodeClient, newLogger(t), mockInstrumentor, mockErrorReporter, mockTrackerFactory)
dir, _ := os.Getwd()

t.Run("should return true for supported config files", func(t *testing.T) {
for _, file := range expectedConfigFiles {
path := filepath.Join(dir, file)
supported, _ := bundler.IsSupported(t.Context(), path)
assert.True(t, supported)
}
})
t.Run("should exclude .gitignore and .dcignore", func(t *testing.T) {
for _, file := range []string{".gitignore", ".dcignore"} {
path := filepath.Join(dir, file)
supported, _ := bundler.IsSupported(t.Context(), path)
assert.False(t, supported)
}
})
t.Run("should return false for unsupported config files", func(t *testing.T) {
path := "C:\\some\\path\\.unsupported"
supported, _ := bundler.IsSupported(t.Context(), path)
assert.False(t, supported)
})

t.Run("should cache supported extensions", func(t *testing.T) {
path := "C:\\some\\path\\Test.rs"
_, _ = bundler.IsSupported(t.Context(), path)
_, _ = bundler.IsSupported(t.Context(), path)
})
}

func setup(t *testing.T) string {
t.Helper()
dir := t.TempDir()
Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/puzpuzpuz/xsync v1.5.2
github.com/rs/zerolog v1.34.0
github.com/snyk/error-catalog-golang-public v0.0.0-20260205094614-116c03822905
github.com/snyk/go-application-framework v0.0.0-20260504124159-e299fb4a44a1
github.com/snyk/go-application-framework v0.8.1-0.20260727102853-16db50c1cb56
github.com/spf13/pflag v1.0.6
github.com/stretchr/testify v1.11.1
golang.org/x/net v0.55.0
Expand Down Expand Up @@ -100,13 +100,13 @@ require (
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.52.0 // indirect
golang.org/x/mod v0.35.0 // indirect
golang.org/x/crypto v0.53.0 // indirect
golang.org/x/mod v0.36.0 // indirect
golang.org/x/oauth2 v0.27.0 // indirect
golang.org/x/sync v0.20.0 // indirect
golang.org/x/sys v0.45.0 // indirect
golang.org/x/text v0.37.0 // indirect
golang.org/x/tools v0.44.0 // indirect
golang.org/x/sync v0.21.0 // indirect
golang.org/x/sys v0.46.0 // indirect
golang.org/x/text v0.38.0 // indirect
golang.org/x/tools v0.45.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250404141209-ee84b53bf3d0 // indirect
google.golang.org/grpc v1.71.0 // indirect
google.golang.org/protobuf v1.36.6 // indirect
Expand Down
34 changes: 18 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,10 @@ github.com/skeema/knownhosts v1.3.1 h1:X2osQ+RAjK76shCbvhHHHVl3ZlgDm8apHEHFqRjnB
github.com/skeema/knownhosts v1.3.1/go.mod h1:r7KTdC8l4uxWRyK2TpQZ/1o5HaSzh06ePQNxPwTcfiY=
github.com/snyk/error-catalog-golang-public v0.0.0-20260205094614-116c03822905 h1:pUe6iOWHEOFY0t4u4ssXeTqpMmZBu1xq06VBFI9zUik=
github.com/snyk/error-catalog-golang-public v0.0.0-20260205094614-116c03822905/go.mod h1:Ytttq7Pw4vOCu9NtRQaOeDU2dhBYUyNBe6kX4+nIIQ4=
github.com/snyk/go-application-framework v0.0.0-20260504124159-e299fb4a44a1 h1:yiG0VOwT292qxs+g6HTnr6O8is/sKEI+9XTUGf2tFDU=
github.com/snyk/go-application-framework v0.0.0-20260504124159-e299fb4a44a1/go.mod h1:yTGCJKf6RmqdwrNs5B9zmukL9x1D8EhfSK8mzaPB1Rk=
github.com/snyk/go-application-framework v0.8.1-0.20260727094148-7e9b94e9b8ba h1:Lo7An3bw612z3cQbGvrgcaXdrAUsKNWrsXjoYDPa+78=
github.com/snyk/go-application-framework v0.8.1-0.20260727094148-7e9b94e9b8ba/go.mod h1:0YC7xCETnFTdz6rq8OQPL0aWekMLOkBQu1FE4/cReMA=
github.com/snyk/go-application-framework v0.8.1-0.20260727102853-16db50c1cb56 h1:eY/MAu7AIqdActA/3vpnit4GYkZGv/VHXlgtMpZwU8c=
github.com/snyk/go-application-framework v0.8.1-0.20260727102853-16db50c1cb56/go.mod h1:0YC7xCETnFTdz6rq8OQPL0aWekMLOkBQu1FE4/cReMA=
github.com/snyk/go-httpauth v0.0.0-20231117135515-eb445fea7530 h1:s9PHNkL6ueYRiAKNfd8OVxlUOqU3qY0VDbgCD1f6WQY=
github.com/snyk/go-httpauth v0.0.0-20231117135515-eb445fea7530/go.mod h1:88KbbvGYlmLgee4OcQ19yr0bNpXpOr2kciOthaSzCAg=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
Expand Down Expand Up @@ -327,14 +329,14 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.52.0 h1:RMs7fP2rXdep0CftQlK8Uf+kibLm7qkCcradZWYz988=
golang.org/x/crypto v0.52.0/go.mod h1:1QgfPxDqh0T2M/elOJtp9RvuR95kVjir0e6/BvEmGbc=
golang.org/x/crypto v0.53.0 h1:QZ4Muo8THX6CizN2vPPd5fBGHyogrdK9fG4wLPFUsto=
golang.org/x/crypto v0.53.0/go.mod h1:DNLU434OwVakk9PzuwV8w62mAJpRJL3vsgcfp4Qnsio=
golang.org/x/exp v0.0.0-20260410095643-746e56fc9e2f h1:W3F4c+6OLc6H2lb//N1q4WpJkhzJCK5J6kUi1NTVXfM=
golang.org/x/exp v0.0.0-20260410095643-746e56fc9e2f/go.mod h1:J1xhfL/vlindoeF/aINzNzt2Bket5bjo9sdOYzOsU80=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.35.0 h1:Ww1D637e6Pg+Zb2KrWfHQUnH2dQRLBQyAtpr/haaJeM=
golang.org/x/mod v0.35.0/go.mod h1:+GwiRhIInF8wPm+4AoT6L0FA1QWAad3OMdTRx4tFYlU=
golang.org/x/mod v0.36.0 h1:JJjpVx6myfUsUdAzZuOSTTmRE0PfZeNWzzvKrP7amb4=
golang.org/x/mod v0.36.0/go.mod h1:moc6ELqsWcOw5Ef3xVprK5ul/MvtVvkIXLziUOICjUQ=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand All @@ -354,8 +356,8 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sync v0.21.0 h1:HLII4xRRTtCRkxYp4HNFF0Js/Og6q2i++KXbg0gHCwM=
golang.org/x/sync v0.21.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand All @@ -381,24 +383,24 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY=
golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw=
golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.43.0 h1:S4RLU2sB31O/NCl+zFN9Aru9A/Cq2aqKpTZJ6B+DwT4=
golang.org/x/term v0.43.0/go.mod h1:lrhlHNdQJHO+1qVYiHfFKVuVioJIheAc3fBSMFYEIsk=
golang.org/x/term v0.44.0 h1:0rLvDRCtNj0gZkyIXhCyOb2OAzEhLVqc4B+hrsBhrmc=
golang.org/x/term v0.44.0/go.mod h1:7ze4MdzUzLXpSAoFP1H0bOI9aXDqveSvatT5vKcFh2Y=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc=
golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38=
golang.org/x/text v0.38.0 h1:sXmwo9DwP3OK9EZ7PqAdaooSGozfl/3a6/xJcbzPRhE=
golang.org/x/text v0.38.0/go.mod h1:YXZt3QhHUKYT53r2lLKFIVi6Ao1jdzrTR/KQ09qyxF4=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.44.0 h1:UP4ajHPIcuMjT1GqzDWRlalUEoY+uzoZKnhOjbIPD2c=
golang.org/x/tools v0.44.0/go.mod h1:KA0AfVErSdxRZIsOVipbv3rQhVXTnlU6UhKxHd1seDI=
golang.org/x/tools v0.45.0 h1:18qN3FAooORvApf5XjCXgsuayZOEtXf6JK18I3+ONa8=
golang.org/x/tools v0.45.0/go.mod h1:LuUGqqaXcXMEFEruIVJVm5mgDD8vww/z/SR1gQ4uE/0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
33 changes: 23 additions & 10 deletions internal/analysis/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,22 @@ import (
//go:generate go tool github.com/golang/mock/mockgen -destination=mocks/analysis.go -source=analysis.go -package mocks

type AnalysisOrchestrator interface {
RunTest(ctx context.Context, orgId string, b bundle.Bundle, target scan.Target, reportingOptions AnalysisConfig) (*sarif.SarifResponse, *scan.ResultMetaData, error)
RunTest(ctx context.Context, orgId string, b bundle.Bundle, revisionId *string, target scan.Target, reportingOptions AnalysisConfig) (*sarif.SarifResponse, *scan.ResultMetaData, error)
RunTestRemote(ctx context.Context, orgId string, reportingOptions AnalysisConfig) (*sarif.SarifResponse, *scan.ResultMetaData, error)
RunLegacyTest(ctx context.Context, bundleHash string, shardKey string, limitToFiles []string, severity int) (*sarif.SarifResponse, scan.LegacyScanStatus, error)
}

var ErrMissingTestInput = errors.New("either a bundle or an upload revision id is required")

type AnalysisConfig struct {
Report bool
ProjectName *string
ProjectTags *[]string
TargetName *string
TargetReference *string
ProjectId *uuid.UUID
CommitId *string
Report bool
ProjectName *string
ProjectTags *[]string
TargetName *string
TargetReference *string
ProjectId *uuid.UUID
CommitId *string
UploadFileContentToFileUploadApi bool
}

type analysisOrchestrator struct {
Expand Down Expand Up @@ -233,7 +236,7 @@ func (a *analysisOrchestrator) createTestAndGetResults(ctx context.Context, orgI
return result, metadata, err
}

func (a *analysisOrchestrator) RunTest(ctx context.Context, orgId string, b bundle.Bundle, target scan.Target, reportingConfig AnalysisConfig) (*sarif.SarifResponse, *scan.ResultMetaData, error) {
func (a *analysisOrchestrator) RunTest(ctx context.Context, orgId string, b bundle.Bundle, revisionId *string, target scan.Target, reportingConfig AnalysisConfig) (*sarif.SarifResponse, *scan.ResultMetaData, error) {
var commitId *string = nil
var repoUrl *string = nil
var branchName *string = nil
Expand All @@ -252,8 +255,18 @@ func (a *analysisOrchestrator) RunTest(ctx context.Context, orgId string, b bund
}
}

var input testApi.CreateTestOption
switch {
case b != nil:
input = testApi.WithInputBundle(b.GetBundleHash(), target.GetPath(), repoUrl, b.GetLimitToFiles(), commitId, branchName)
case revisionId != nil:
input = testApi.WithInputUploadRevision(*revisionId, target.GetPath(), repoUrl)
default:
return nil, nil, ErrMissingTestInput
}

body := testApi.NewCreateTestApplicationBody(
testApi.WithInputBundle(b.GetBundleHash(), target.GetPath(), repoUrl, b.GetLimitToFiles(), commitId, branchName),
input,
testApi.WithScanType(a.testType),
testApi.WithProjectName(reportingConfig.ProjectName),
testApi.WithProjectTags(reportingConfig.ProjectTags),
Expand Down
Loading