Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions pkg/models/priority.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}
49 changes: 49 additions & 0 deletions pkg/models/priority_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
})
}
}