Skip to content

Commit

Permalink
HdfConverter: map status to SARIF kind/level/rank correctly (#2695)
Browse files Browse the repository at this point in the history
* rank should only be output when kind=fail
* level should only be output when kind=fail
* handle kind values of passed, faild, error, and skipped

Signed-off-by: Craig Andrews <candrews@integralblue.com>
  • Loading branch information
candrews committed Jul 24, 2023
1 parent 274ed7e commit 7e9cd9d
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Sarif.Converters/HdfConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,26 @@ private static (ReportingDescriptor, IList<Result>) SarifRuleAndResultFromHdfCon
var results = new List<Result>(execJsonControl.Results.Count);
foreach (ControlResult controlResult in execJsonControl.Results)
{
ResultKind kind = controlResult.Status switch
{
ControlResultStatus.Passed => ResultKind.Pass,
ControlResultStatus.Failed => ResultKind.Fail,
ControlResultStatus.Error => ResultKind.Review,
ControlResultStatus.Skipped => ResultKind.NotApplicable,
_ => ResultKind.Fail,
};
FailureLevel level = (kind == ResultKind.Fail) ? SarifLevelFromHdfImpact(execJsonControl.Impact) : FailureLevel.None;
double rank = (kind == ResultKind.Fail) ? SarifRankFromHdfImpact(execJsonControl.Impact) : -1.0;
var result = new Result
{
RuleId = execJsonControl.Id,
Message = new Message
{
Text = AppendPeriod(string.IsNullOrWhiteSpace(controlResult.CodeDesc) ? execJsonControl.Desc : controlResult.CodeDesc),
},
Level = SarifLevelFromHdfImpact(execJsonControl.Impact),
Rank = SarifRankFromHdfImpact(execJsonControl.Impact),
Kind = kind,
Level = level,
Rank = rank,
};
results.Add(result);
}
Expand Down

0 comments on commit 7e9cd9d

Please sign in to comment.