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

Function LoadObjectiveMappingFromConfig

pkg/github/label_objective_mapping.go:148–189  ·  view source on GitHub ↗

LoadObjectiveMappingFromConfig loads the mapping from environment, config file, or defaults. Precedence: 1. OBJECTIVE_MAPPING_JSON environment variable 2. .github/objective-mapping.json file 3. Built-in defaults

()

Source from the content-addressed store, hash-verified

146// 2. .github/objective-mapping.json file
147// 3. Built-in defaults
148func LoadObjectiveMappingFromConfig() *ObjectiveMapping {
149 labelObjectiveMappingLog.Print("Loading objective mapping configuration")
150
151 // Try loading from OBJECTIVE_MAPPING_JSON env var
152 if mappingJSON := os.Getenv("OBJECTIVE_MAPPING_JSON"); mappingJSON != "" { //nolint:osgetenvlibrary
153 labelObjectiveMappingLog.Print("Attempting to load from OBJECTIVE_MAPPING_JSON env var")
154 var om ObjectiveMapping
155 if err := json.Unmarshal([]byte(mappingJSON), &om); err == nil {
156 labelObjectiveMappingLog.Printf("Loaded mapping from env var JSON: %d labels", len(om.LabelToValue))
157 return &om
158 } else {
159 labelObjectiveMappingLog.Printf("Failed to parse OBJECTIVE_MAPPING_JSON as JSON: %v", err)
160 }
161
162 // If it's not valid JSON, treat it as a file path.
163 if data, err := os.ReadFile(mappingJSON); err == nil {
164 if err := json.Unmarshal(data, &om); err == nil {
165 labelObjectiveMappingLog.Printf("Loaded mapping from env var file %q: %d labels", mappingJSON, len(om.LabelToValue))
166 return &om
167 }
168 labelObjectiveMappingLog.Printf("Failed to parse OBJECTIVE_MAPPING_JSON file %q: %v", mappingJSON, err)
169 } else {
170 labelObjectiveMappingLog.Printf("Could not read OBJECTIVE_MAPPING_JSON as file %q: %v", mappingJSON, err)
171 }
172 }
173
174 configPath := filepath.Join(".github", "objective-mapping.json")
175 if data, err := os.ReadFile(configPath); err == nil {
176 labelObjectiveMappingLog.Printf("Attempting to load from %s", configPath)
177 var om ObjectiveMapping
178 if err := json.Unmarshal(data, &om); err == nil {
179 labelObjectiveMappingLog.Printf("Loaded mapping from config file: %d labels", len(om.LabelToValue))
180 return &om
181 }
182 labelObjectiveMappingLog.Printf("Failed to parse config file: %v", err)
183 }
184
185 // Return default mapping
186 defaults := DefaultObjectiveMapping()
187 labelObjectiveMappingLog.Printf("Using default mapping: %d labels", len(defaults.LabelToValue))
188 return defaults
189}
190
191// GetObjectiveLabels returns the subset of issue labels that have objective values.
192// Also returns the labels in the order they appear in the issue's label list.

Calls 4

DefaultObjectiveMappingFunction · 0.85
PrintMethod · 0.80
GetenvMethod · 0.80
PrintfMethod · 0.45