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
17 changes: 14 additions & 3 deletions pkg/models/priority.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,29 @@ const (
PriorityUrgent string = "URGENT"
PriorityImportant string = "IMPORTANT"
PriorityInformational string = "INFORMATIONAL"
PriorityUnknown string = "UNKNOWN"
)

var priorityToInt = map[string]int{
PriorityInformational: 0,
PriorityImportant: 1,
PriorityUrgent: 2,
PriorityUnknown: 0,
PriorityInformational: 1,
PriorityImportant: 2,
PriorityUrgent: 3,
}

func ComparePriority(priority1, priority2 string) int {
val1, ok1 := priorityToInt[priority1]
val2, ok2 := priorityToInt[priority2]

// If priority1 is NONE and priority2 is not in the map, treat them as equal
if priority1 == PriorityUnknown && !ok2 {
return 0
}
// If priority2 is NONE and priority1 is not in the map, treat them as equal
if priority2 == PriorityUnknown && !ok1 {
return 0
}

if !ok1 && !ok2 {
return 0
} else if !ok1 {
Expand Down
4 changes: 4 additions & 0 deletions pkg/models/priority_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func TestComparePriority(t *testing.T) {
{"INFORMATIONAL", "INFORMATIONAL", 0},
{"IMPORTANT", "IMPORTANT", 0},
{"URGENT", "URGENT", 0},
{"NONE", "INVALID", 0},
{"NONE", "UNKNOWN", 0},
{"UNKNOWN", "", 0},
{"", "UNKNOWN", 0},
}

for _, test := range tests {
Expand Down