Skip to content

Commit

Permalink
File Fingerprinting C/C++: Add flag to include repository matches
Browse files Browse the repository at this point in the history
  • Loading branch information
SuneethaSuresh authored and filip-debricked committed Nov 11, 2024
1 parent 521aa21 commit 8f046b2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 2 additions & 0 deletions internal/scan/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type DebrickedOptions struct {
CallGraphGenerateTimeout int
MinFingerprintContentLength int
TagCommitAsRelease bool
Experimental bool
}

func NewDebrickedScanner(
Expand Down Expand Up @@ -282,6 +283,7 @@ func (dScanner *DebrickedScanner) scan(options DebrickedOptions, gitMetaObject g
VersionHint: options.VersionHint,
DebrickedConfig: dScanner.getDebrickedConfig(options.Path, options.Exclusions, options.Inclusions),
TagCommitAsRelease: options.TagCommitAsRelease,
Experimental: options.Experimental,
}
result, err := (*dScanner.uploader).Upload(uploaderOptions)
if err != nil {
Expand Down
8 changes: 6 additions & 2 deletions internal/upload/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ type uploadBatch struct {
versionHint bool
debrickedConfig *DebrickedConfig // JSON Config
tagCommitAsRelease bool
experimental bool
}

func newUploadBatch(
client *client.IDebClient, fileGroups file.Groups, gitMetaObject *git.MetaObject,
integrationName string, callGraphTimeout int, versionHint bool, debrickedConfig *DebrickedConfig,
tagCommitAsRelease bool,
integrationName string, callGraphTimeout int, versionHint bool,
debrickedConfig *DebrickedConfig, tagCommitAsRelease bool, experimental bool,
) *uploadBatch {
return &uploadBatch{
client: client,
Expand All @@ -59,6 +60,7 @@ func newUploadBatch(
versionHint: versionHint,
debrickedConfig: debrickedConfig,
tagCommitAsRelease: tagCommitAsRelease,
experimental: experimental,
}
}

Expand Down Expand Up @@ -187,6 +189,7 @@ func (uploadBatch *uploadBatch) initAnalysis() error {
DebrickedConfig: uploadBatch.debrickedConfig,
DebrickedIntegration: "cli",
TagCommitAsRelease: uploadBatch.tagCommitAsRelease,
Experimental: uploadBatch.experimental,
})

if err != nil {
Expand Down Expand Up @@ -332,6 +335,7 @@ type uploadFinish struct {
VersionHint bool `json:"versionHint"`
DebrickedConfig *DebrickedConfig `json:"debrickedConfig"`
TagCommitAsRelease bool `json:"isRelease"`
Experimental bool `json:"experimental"`
}

func getRelativeFilePath(filePath string) string {
Expand Down
10 changes: 5 additions & 5 deletions internal/upload/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestUploadWithBadFiles(t *testing.T) {
clientMock.AddMockResponse(mockRes)
clientMock.AddMockResponse(mockRes)
c = clientMock
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, false)
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, true, false)
var buf bytes.Buffer
log.SetOutput(&buf)
err = batch.upload()
Expand All @@ -50,7 +50,7 @@ func TestUploadWithBadFiles(t *testing.T) {
}

func TestInitAnalysisWithoutAnyFiles(t *testing.T) {
batch := newUploadBatch(nil, file.Groups{}, nil, "CLI", 10*60, true, &DebrickedConfig{}, false)
batch := newUploadBatch(nil, file.Groups{}, nil, "CLI", 10*60, true, &DebrickedConfig{}, true, false)
err := batch.initAnalysis()

assert.ErrorContains(t, err, "failed to find dependency files")
Expand All @@ -73,7 +73,7 @@ func TestWaitWithPollingTerminatedError(t *testing.T) {
}
clientMock.AddMockResponse(mockRes)
c = clientMock
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, false)
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, true, false)

uploadResult, err := batch.wait()

Expand All @@ -98,7 +98,7 @@ func TestInitUploadBadFile(t *testing.T) {
clientMock.AddMockResponse(mockRes)

var c client.IDebClient = clientMock
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, false)
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, true, false)

files, err := batch.initUpload()

Expand All @@ -120,7 +120,7 @@ func TestInitUploadFingerprintsFree(t *testing.T) {
clientMock := testdata.NewDebClientMock()
clientMock.SetEnterpriseCustomer(false)
var c client.IDebClient = clientMock
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, false)
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, true, false)

files, err := batch.initUpload()

Expand Down
2 changes: 2 additions & 0 deletions internal/upload/uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type DebrickedOptions struct {
VersionHint bool
DebrickedConfig *DebrickedConfig
TagCommitAsRelease bool
Experimental bool
}

type IUploader interface {
Expand Down Expand Up @@ -47,6 +48,7 @@ func (uploader *Uploader) Upload(o IOptions) (*UploadResult, error) {
dOptions.VersionHint,
dOptions.DebrickedConfig,
dOptions.TagCommitAsRelease,
dOptions.Experimental,
)

err := batch.upload()
Expand Down

0 comments on commit 8f046b2

Please sign in to comment.