@@ -66,7 +66,7 @@ type analysisOrchestrator struct {
6666 logger * zerolog.Logger
6767 trackerFactory scan.TrackerFactory
6868 config config.Config
69- testType testModels.Scan
69+ testType testModels.ResultType
7070}
7171
7272var _ AnalysisOrchestrator = (* analysisOrchestrator )(nil )
@@ -97,7 +97,7 @@ func WithTrackerFactory(factory scan.TrackerFactory) func(*analysisOrchestrator)
9797 }
9898}
9999
100- func WithResultType (t testModels.Scan ) func (* analysisOrchestrator ) {
100+ func WithResultType (t testModels.ResultType ) func (* analysisOrchestrator ) {
101101 return func (a * analysisOrchestrator ) {
102102 a .testType = t
103103 }
@@ -237,8 +237,9 @@ func (a *analysisOrchestrator) RunTest(ctx context.Context, orgId string, b bund
237237 repoUrl = & tmp
238238 }
239239
240+ commitId := target .GetCommitId ()
240241 body := testApi .NewCreateTestApplicationBody (
241- testApi .WithInputBundle (b .GetBundleHash (), target .GetPath (), repoUrl , b .GetLimitToFiles ()),
242+ testApi .WithInputBundle (b .GetBundleHash (), target .GetPath (), repoUrl , b .GetLimitToFiles (), & commitId ),
242243 testApi .WithScanType (a .testType ),
243244 testApi .WithProjectName (reportingConfig .ProjectName ),
244245 testApi .WithTargetName (reportingConfig .TargetName ),
@@ -300,11 +301,11 @@ func (a *analysisOrchestrator) retrieveTestURL(ctx context.Context, client *test
300301 logger := a .logger .With ().Str ("method" , method ).Logger ()
301302 logger .Debug ().Msg ("retrieving Test URL" )
302303
303- httpResponse , err := client .GetTestResult (
304+ httpResponse , err := client .GetComponents (
304305 ctx ,
305306 org ,
306307 testId ,
307- & testApi.GetTestResultParams {Version : testApi .ApiVersion },
308+ & testApi.GetComponentsParams {Version : testApi .ApiVersion },
308309 )
309310 if err != nil {
310311 logger .Err (err ).Str ("testId" , testId .String ()).Msg ("error requesting the ScanJobResult" )
@@ -317,50 +318,50 @@ func (a *analysisOrchestrator) retrieveTestURL(ctx context.Context, client *test
317318 }
318319 }()
319320
320- parsedResponse , err := testApi .ParseGetTestResultResponse (httpResponse )
321+ parsedResponse , err := testApi .ParseGetComponentsResponse (httpResponse )
321322 if err != nil {
322323 return nil , false , err
323324 }
324325
325326 switch parsedResponse .StatusCode () {
326327 case 200 :
327- stateDiscriminator , stateError := parsedResponse .ApplicationvndApiJSON200 .Data .Attributes .Discriminator ()
328- if stateError != nil {
329- return nil , false , stateError
328+ data := parsedResponse .ApplicationvndApiJSON200 .Data
329+ var sastComponent * testModels.GetComponentsResponseItem
330+ for _ , component := range data {
331+ if component .Attributes .Type == "sast" {
332+ a .logger .Debug ().Msgf ("inner component: %+v" , component )
333+ sastComponent = & component
334+ break
335+ }
330336 }
331-
332- switch stateDiscriminator {
333- case string (testModels .TestAcceptedStateStatusAccepted ):
334- fallthrough
335- case string (testModels .TestInProgressStateStatusInProgress ):
337+ if sastComponent == nil {
338+ a .logger .Debug ().Msg ("no sast component found" )
336339 return nil , false , nil
337- case string (testModels .TestCompletedStateStatusCompleted ):
338- testCompleted , stateCompleteError := parsedResponse .ApplicationvndApiJSON200 .Data .Attributes .AsTestCompletedState ()
339- if stateCompleteError != nil {
340- return nil , false , stateCompleteError
341- }
340+ }
342341
343- findingsUrl := a .host (true ) + testCompleted .Documents .EnrichedSarif + "?version=" + testApi .DocumentApiVersion
344- result := & scan.ResultMetaData {
345- FindingsUrl : findingsUrl ,
346- }
342+ result := & scan.ResultMetaData {}
343+ attributes := sastComponent .Attributes
344+
345+ if attributes .FindingsDocumentType != nil && * attributes .FindingsDocumentType == testModels .Sarif {
346+ // TODO: adjustedUrl is a workaround for the fact that a breaking change was introduced to the findings document path
347+ // see https://github.com/snyk/test-service/pull/683
348+ adjustedUrl := strings .Split (* attributes .FindingsDocumentPath , "v2" )[0 ]
349+ findingsUrl := a .host (true ) + adjustedUrl + "documents/enriched-findings/blob?version=" + testApi .DocumentApiVersion
350+ result .FindingsUrl = findingsUrl
347351
348- if testCompleted . Results .Webui != nil {
349- if testCompleted . Results .Webui .Link != nil {
350- result .WebUiUrl = * testCompleted . Results .Webui .Link
352+ if attributes .Webui != nil {
353+ if attributes .Webui .Link != nil {
354+ result .WebUiUrl = * attributes .Webui .Link
351355 }
352- if testCompleted . Results .Webui .ProjectId != nil {
353- result .ProjectId = testCompleted . Results .Webui .ProjectId .String ()
356+ if attributes .Webui .ProjectId != nil {
357+ result .ProjectId = attributes .Webui .ProjectId .String ()
354358 }
355- if testCompleted . Results .Webui .SnapshotId != nil {
356- result .SnapshotId = testCompleted . Results .Webui .SnapshotId .String ()
359+ if attributes .Webui .SnapshotId != nil {
360+ result .SnapshotId = attributes .Webui .SnapshotId .String ()
357361 }
358362 }
359-
360- return result , true , nil
361- default :
362- return nil , false , fmt .Errorf ("unexpected test status \" %s\" " , stateDiscriminator )
363363 }
364+ return result , true , nil
364365 default :
365366 return nil , false , fmt .Errorf ("unexpected response status \" %d\" " , parsedResponse .StatusCode ())
366367 }
0 commit comments