ComputeObjectiveValue calculates the numeric value for an issue based on its labels. Returns 0 if no labels match or if mapping is nil.
(issueLabels []string)
| 34 | // ComputeObjectiveValue calculates the numeric value for an issue based on its labels. |
| 35 | // Returns 0 if no labels match or if mapping is nil. |
| 36 | func (om *ObjectiveMapping) ComputeObjectiveValue(issueLabels []string) int { |
| 37 | if om == nil || len(om.LabelToValue) == 0 { |
| 38 | return 0 |
| 39 | } |
| 40 | |
| 41 | if len(issueLabels) == 0 { |
| 42 | return 0 |
| 43 | } |
| 44 | |
| 45 | matchingValues := []int{} |
| 46 | matchedLabels := []string{} |
| 47 | |
| 48 | for _, label := range issueLabels { |
| 49 | normalizedLabel := strings.ToLower(strings.TrimSpace(label)) |
| 50 | if val, ok := om.LabelToValue[normalizedLabel]; ok { |
| 51 | matchingValues = append(matchingValues, val) |
| 52 | matchedLabels = append(matchedLabels, label) |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | if len(matchingValues) == 0 { |
| 57 | return 0 |
| 58 | } |
| 59 | |
| 60 | logic := om.MultiLabelLogic |
| 61 | if logic == "" { |
| 62 | logic = "max" // default |
| 63 | } |
| 64 | |
| 65 | switch logic { |
| 66 | case "sum": |
| 67 | return om.computeValueSum(matchingValues, matchedLabels) |
| 68 | case "first": |
| 69 | return om.computeValueFirst(issueLabels, matchingValues, matchedLabels) |
| 70 | default: // "max" |
| 71 | return om.computeValueMax(matchingValues, matchedLabels) |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | // computeValueSum adds all matching label values and logs the result. |
| 76 | func (om *ObjectiveMapping) computeValueSum(matchingValues []int, matchedLabels []string) int { |