diff --git a/pkg/models/priority.go b/pkg/models/priority.go index c081ef5..c1b054e 100644 --- a/pkg/models/priority.go +++ b/pkg/models/priority.go @@ -5,13 +5,25 @@ const ( PriorityImportant string = "IMPORTANT" PriorityInformational string = "INFORMATIONAL" PriorityUnknown string = "UNKNOWN" + + // To be deprecated + PriorityNegligible string = "NEGIGIBLE" + PriorityLow string = "LOW" + PriorityMedium string = "MEDIUM" + // important is repeated + // urgent is repeated ) var priorityToInt = map[string]int{ PriorityUnknown: 0, PriorityInformational: 1, - PriorityImportant: 2, - PriorityUrgent: 3, + PriorityImportant: 3, + PriorityUrgent: 4, + + // To be deprecated + PriorityNegligible: 1, + PriorityLow: 1, + PriorityMedium: 2, } func ComparePriority(priority1, priority2 string) int { @@ -43,3 +55,16 @@ func ComparePriority(priority1, priority2 string) int { return 0 } } + +func SeverityToPriority(severity string) string { + switch severity { + case "CRITICAL": + return PriorityUrgent + case "HIGH", "MEDIUM": + return PriorityImportant + case "LOW": + return PriorityInformational + default: + return PriorityInformational + } +} diff --git a/pkg/models/priority_test.go b/pkg/models/priority_test.go index 78281d9..d2c8a0c 100644 --- a/pkg/models/priority_test.go +++ b/pkg/models/priority_test.go @@ -24,6 +24,32 @@ func TestComparePriority(t *testing.T) { {"NONE", "UNKNOWN", 0}, {"UNKNOWN", "", 0}, {"", "UNKNOWN", 0}, + + // To be deprecated, for backwards compatibility + {"NEGIGIBLE", "URGENT", -1}, + {"NEGIGIBLE", "IMPORTANT", -1}, + {"NEGIGIBLE", "INFORMATIONAL", 0}, + {"NEGIGIBLE", "UNKNOWN", 1}, + {"NEGIGIBLE", "NONE", 1}, + {"NEGIGIBLE", "", 1}, + {"", "NEGIGIBLE", -1}, + {"NEGIGIBLE", "NEGIGIBLE", 0}, + {"LOW", "URGENT", -1}, + {"LOW", "IMPORTANT", -1}, + {"LOW", "INFORMATIONAL", 0}, + {"LOW", "UNKNOWN", 1}, + {"LOW", "NONE", 1}, + {"LOW", "", 1}, + {"", "LOW", -1}, + {"LOW", "LOW", 0}, + {"MEDIUM", "URGENT", -1}, + {"MEDIUM", "IMPORTANT", -1}, + {"MEDIUM", "INFORMATIONAL", 1}, + {"MEDIUM", "UNKNOWN", 1}, + {"MEDIUM", "NONE", 1}, + {"MEDIUM", "", 1}, + {"", "MEDIUM", -1}, + {"MEDIUM", "MEDIUM", 0}, } for _, test := range tests { @@ -34,3 +60,26 @@ func TestComparePriority(t *testing.T) { } } } + +func TestSeverityToPriority(t *testing.T) { + tests := []struct { + name string + severity string + want string + }{ + {"Critical to Urgent", SeverityCritical, PriorityUrgent}, + {"High to Important", SeverityHigh, PriorityImportant}, + {"Medium to Important", SeverityMedium, PriorityImportant}, + {"Low to Informational", SeverityLow, PriorityInformational}, + {"Unknown to Informational", SeverityUnknown, PriorityInformational}, + {"Empty to Informational", "", PriorityInformational}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := SeverityToPriority(tt.severity); got != tt.want { + t.Errorf("SeverityToPriority() = %v, want %v", got, tt.want) + } + }) + } +}