Skip to content

Commit

Permalink
✨ Add unassessed risk type and exit early for app risk status calcula…
Browse files Browse the repository at this point in the history
…tion (#623)

https://issues.redhat.com/browse/MTA-2308

Signed-off-by: Ian Bolton <ibolton@redhat.com>
  • Loading branch information
ibolton336 authored Apr 5, 2024
1 parent 5b39e71 commit 94330e1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion api/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ func (r *Application) With(m *model.Application, tags []model.ApplicationTag) {
})
r.Effort = m.Analyses[len(m.Analyses)-1].Effort
}
r.Risk = assessment.RiskUnknown
r.Risk = assessment.RiskUnassessed
}

// WithVirtualTags updates the resource with tags derived from assessments.
Expand Down
2 changes: 1 addition & 1 deletion api/archetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func (r *Archetype) With(m *model.Archetype) {
ref.With(m.Review.ID, "")
r.Review = ref
}
r.Risk = assessment.RiskUnknown
r.Risk = assessment.RiskUnassessed
}

// WithResolver uses an ArchetypeResolver to update the resource with
Expand Down
42 changes: 20 additions & 22 deletions assessment/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (

// Assessment risk
const (
RiskUnknown = "unknown"
RiskRed = "red"
RiskYellow = "yellow"
RiskGreen = "green"
RiskUnassessed = "unassessed"
RiskUnknown = "unknown"
RiskRed = "red"
RiskYellow = "yellow"
RiskGreen = "green"
)

// Assessment status
Expand Down Expand Up @@ -43,26 +44,23 @@ const (

// Risk returns the single highest risk score for a group of assessments.
func Risk(assessments []Assessment) (risk string) {
risk = RiskUnknown
// Return "unassessed" immediately if there are no assessments
if len(assessments) == 0 {
return
return RiskUnassessed
}
red := 0
yellow := 0
unknown := 0
green := 0
if len(assessments) > 0 {
for _, a := range assessments {
switch a.Risk() {
case RiskRed:
red++
case RiskYellow:
yellow++
case RiskGreen:
green++
default:
unknown++
}

red, yellow, unknown, green := 0, 0, 0, 0

for _, a := range assessments {
switch a.Risk() {
case RiskRed:
red++
case RiskYellow:
yellow++
case RiskGreen:
green++
default:
unknown++
}
}

Expand Down

0 comments on commit 94330e1

Please sign in to comment.