@@ -411,10 +411,62 @@ void SnykTreeDecoder::readRoot(
411
411
pDefList = nullptr ;
412
412
}
413
413
414
+ void snykReadLocation (DefEvent *pEvt, const pt::ptree &defNode)
415
+ {
416
+ const pt::ptree *locs;
417
+ if (!findChildOf (&locs, defNode, " locations" ) || locs->empty ())
418
+ // no location info available
419
+ return ;
420
+
421
+ const pt::ptree *pl;
422
+ if (!findChildOf (&pl, locs->begin ()->second , " physicalLocation" ))
423
+ // unknown location info format
424
+ return ;
425
+
426
+ const pt::ptree *al;
427
+ if (findChildOf (&al, *pl, " artifactLocation" )) {
428
+ const auto uri = valueOf<std::string>(*al, " uri" , " " );
429
+ if (!uri.empty ())
430
+ // read file name
431
+ pEvt->fileName = uri;
432
+ }
433
+
434
+ const pt::ptree *reg;
435
+ if (findChildOf (®, *pl, " region" )) {
436
+ // read line/col if available
437
+ pEvt->line = valueOf<int >(*reg, " startLine" , 0 );
438
+ pEvt->column = valueOf<int >(*reg, " startColumn" , 0 );
439
+ }
440
+ }
441
+
414
442
bool SnykTreeDecoder::readNode (
415
443
Defect *def,
416
444
pt::ptree::const_iterator defIter)
417
445
{
418
- // TODO
419
- return false ;
446
+ // initialize the defect structure
447
+ *def = Defect (" SNYK_CODE_WARNING" );
448
+
449
+ // the current node representing a single snyk's report
450
+ const pt::ptree &defNode = defIter->second ;
451
+
452
+ // initialize the key event
453
+ const auto level = valueOf<std::string>(defNode, " level" , " warning" );
454
+ def->events .push_back (DefEvent (level));
455
+ DefEvent &keyEvent = def->events .back ();
456
+
457
+ // read "rule" that triggered the report
458
+ const auto rule = valueOf<std::string>(defNode, " ruleId" , " " );
459
+ if (!rule.empty ())
460
+ keyEvent.event += " [" + rule + " ]" ;
461
+
462
+ // read location
463
+ keyEvent.fileName = " <unknown>" ;
464
+ snykReadLocation (&keyEvent, defNode);
465
+
466
+ // read diagnostic message
467
+ const pt::ptree *msgNode;
468
+ if (findChildOf (&msgNode, defNode, " message" ))
469
+ keyEvent.msg = valueOf<std::string>(*msgNode, " text" , " <unknown>" );
470
+
471
+ return true ;
420
472
}
0 commit comments