MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / violationSummary

Function violationSummary

app/cli/cmd/workflow_workflow_run_describe.go:312–369  ·  view source on GitHub ↗

violationSummary builds a single-line description of a violation using the structured finding when present (CVE id + severity + package + fix info, or SAST rule + location, or license + component). Falls back to the first line of Message — vuln policies emit a multi-line markdown report there which

(v *action.PolicyViolation)

Source from the content-addressed store, hash-verified

310// of suppression so AFFECTED / UNDER_INVESTIGATION / etc. surface on
311// active findings too.
312func violationSummary(v *action.PolicyViolation) string {
313 statusTag := prettyAssessmentStatus(violationAssessment(v).GetEffectiveStatus())
314 if statusTag == "" && v.Suppress {
315 statusTag = "suppressed"
316 }
317
318 switch {
319 case v.Vulnerability != nil:
320 f := v.Vulnerability
321 head := f.GetExternalId()
322 if tag := joinTag(f.GetSeverity(), statusTag); tag != "" {
323 head = fmt.Sprintf("%s (%s)", head, tag)
324 }
325 if pkg := prettyPurl(f.GetPackagePurl()); pkg != "" {
326 head += " " + pkg
327 }
328 if fix := f.GetFixedVersion(); fix != "" {
329 head += " [fix: " + fix + "]"
330 }
331 return head
332 case v.Sast != nil:
333 f := v.Sast
334 out := f.GetRuleId()
335 if tag := joinTag(f.GetSeverity(), statusTag); tag != "" {
336 out = fmt.Sprintf("%s (%s)", out, tag)
337 }
338 if loc := f.GetLocation(); loc != "" {
339 if ln := f.GetLineNumber(); ln > 0 {
340 out = fmt.Sprintf("%s at %s:%d", out, loc, ln)
341 } else {
342 out = fmt.Sprintf("%s at %s", out, loc)
343 }
344 }
345 return out
346 case v.LicenseViolation != nil:
347 f := v.LicenseViolation
348 out := f.GetLicenseId()
349 if statusTag != "" {
350 out = fmt.Sprintf("%s (%s)", out, statusTag)
351 }
352 if c := f.GetComponentName(); c != "" {
353 if ver := f.GetComponentVersion(); ver != "" {
354 out = fmt.Sprintf("%s — %s@%s", out, c, ver)
355 } else {
356 out = fmt.Sprintf("%s — %s", out, c)
357 }
358 }
359 return out
360 }
361 head := strings.SplitN(strings.TrimSpace(v.Message), "\n", 2)[0]
362 if head == "" {
363 head = v.Subject
364 }
365 if statusTag != "" {
366 head = fmt.Sprintf("%s (%s)", head, statusTag)
367 }
368 return head
369}

Callers 2

policiesTableFunction · 0.85
TestViolationSummaryFunction · 0.85

Calls 15

prettyAssessmentStatusFunction · 0.85
violationAssessmentFunction · 0.85
joinTagFunction · 0.85
prettyPurlFunction · 0.85
GetEffectiveStatusMethod · 0.80
GetExternalIdMethod · 0.80
GetFixedVersionMethod · 0.80
GetRuleIdMethod · 0.80
GetLineNumberMethod · 0.80
GetLicenseIdMethod · 0.80
GetComponentNameMethod · 0.80
GetComponentVersionMethod · 0.80

Tested by 1

TestViolationSummaryFunction · 0.68