MCPcopy Create free account
hub / github.com/github/gh-aw / ComputeObjectiveValue

Method ComputeObjectiveValue

pkg/github/label_objective_mapping.go:36–73  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
36func (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.
76func (om *ObjectiveMapping) computeValueSum(matchingValues []int, matchedLabels []string) int {

Calls 4

computeValueSumMethod · 0.95
computeValueFirstMethod · 0.95
computeValueMaxMethod · 0.95
ToLowerMethod · 0.80