@@ -18,6 +18,7 @@ import (
1818 "github.com/snyk/go-application-framework/pkg/configuration"
1919 "github.com/snyk/go-application-framework/pkg/local_workflows/local_models"
2020 "github.com/snyk/go-application-framework/pkg/runtimeinfo"
21+ "github.com/snyk/go-application-framework/pkg/utils"
2122 "github.com/snyk/go-application-framework/pkg/utils/sarif"
2223)
2324
@@ -237,6 +238,7 @@ func hasSuppression(finding local_models.FindingResource) bool {
237238
238239func getSarifTemplateFuncMap () template.FuncMap {
239240 fnMap := template.FuncMap {}
241+ // SeverityToSarifLevel is for local_models types (local_finding.sarif.tmpl)
240242 fnMap ["SeverityToSarifLevel" ] = func (s local_models.TypesFindingRatingSeverityValue ) string {
241243 return sarif .SeverityToSarifLevel (string (s ))
242244 }
@@ -250,8 +252,18 @@ func getSarifTemplateFuncMap() template.FuncMap {
250252 return fmt .Sprintf ("Snyk/%s/%s%s" , driverName , projectName , time .Now ().UTC ().Format (time .RFC3339 ))
251253 }
252254 fnMap ["convertTypeToDriverName" ] = sarif .ConvertTypeToDriverName
253- fnMap ["getRulesFromTestResult" ] = sarif .GetRulesFromTestResult
254- fnMap ["getResultsFromTestResult" ] = sarif .GetResultsFromTestResult
255+ // severityToSarifLevel is for string types (ufm.sarif.tmpl)
256+ fnMap ["severityToSarifLevel" ] = sarif .SeverityToSarifLevel
257+ // SARIF building functions
258+ fnMap ["buildRuleShortDescription" ] = sarif .BuildRuleShortDescription
259+ fnMap ["buildRuleFullDescription" ] = sarif .BuildRuleFullDescription
260+ fnMap ["buildRuleHelpMarkdown" ] = sarif .BuildHelpMarkdown
261+ fnMap ["buildRuleTags" ] = sarif .BuildRuleTags
262+ fnMap ["getRuleCVSSScore" ] = sarif .GetRuleCVSSScore
263+ fnMap ["buildLocationFromIssue" ] = sarif .BuildLocation
264+ fnMap ["buildFixesFromIssue" ] = sarif .BuildFixesFromIssue
265+ fnMap ["formatIssueMessage" ] = sarif .FormatIssueMessage
266+ fnMap ["getManifestPath" ] = getManifestPathFromTestResult
255267 return fnMap
256268}
257269
@@ -317,7 +329,9 @@ func getDefaultTemplateFuncMap(config configuration.Configuration, ri runtimeinf
317329 return strings .ReplaceAll (str , old , replaceWith )
318330 }
319331 defaultMap ["getFindingTypesFromTestResult" ] = getFindingTypesFromTestResult
320- defaultMap ["getFindingsFromTestResult" ] = getFindingsFromTestResult
332+ defaultMap ["getIssuesFromTestResult" ] = func (testResults testapi.TestResult , findingType testapi.FindingType ) []testapi.Issue {
333+ return utils .ValueOf (testapi .GetIssuesFromTestResult (testResults , findingType ))
334+ }
321335
322336 return defaultMap
323337}
@@ -390,10 +404,21 @@ func getFindingTypesFromTestResult(testResults testapi.TestResult) []testapi.Fin
390404 return slices .Collect (maps .Keys (findingTypes ))
391405}
392406
393- func getFindingsFromTestResult (testResults testapi.TestResult ) []testapi.FindingData {
394- findings , _ , err := testResults .Findings (context .Background ())
407+ // getManifestPathFromTestResult extracts the manifest file path from test result
408+ func getManifestPathFromTestResult (testResults testapi.TestResult ) string {
409+ // Get the test subject
410+ testSubject := testResults .GetTestSubject ()
411+
412+ // Try to extract as DepGraphSubject
413+ depGraph , err := testSubject .AsDepGraphSubject ()
395414 if err != nil {
396- return []testapi. FindingData {}
415+ return "package.json" // Default fallback
397416 }
398- return findings
417+
418+ // Get the first path from locator
419+ if len (depGraph .Locator .Paths ) > 0 {
420+ return depGraph .Locator .Paths [0 ]
421+ }
422+
423+ return "package.json" // Default fallback
399424}
0 commit comments