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

Function LoadRepoConfig

pkg/workflow/repo_config.go:222–250  ·  view source on GitHub ↗

LoadRepoConfig loads and validates .github/workflows/aw.json from the provided git root directory. The function returns a non-nil *RepoConfig with default values when the file does not exist (the file is optional). An error is returned only when the file exists but cannot be read or fails schema va

(gitRoot string)

Source from the content-addressed store, hash-verified

220// An error is returned only when the file exists but cannot be read or fails
221// schema validation.
222func LoadRepoConfig(gitRoot string) (*RepoConfig, error) {
223 configPath := filepath.Join(gitRoot, RepoConfigFileName)
224 repoConfigLog.Printf("Loading repo config from %s", configPath)
225
226 data, err := os.ReadFile(filepath.Clean(configPath))
227 if err != nil {
228 if errors.Is(err, os.ErrNotExist) {
229 repoConfigLog.Print("Repo config file not found, using defaults")
230 return &RepoConfig{}, nil
231 }
232 return nil, fmt.Errorf("failed to read %s: %w", RepoConfigFileName, err)
233 }
234
235 // Validate against the embedded JSON schema before deserialising.
236 if err := validateRepoConfigJSON(data, configPath); err != nil {
237 return nil, err
238 }
239
240 // Deserialise into typed structs via JSON annotations.
241 var cfg RepoConfig
242 if err := json.Unmarshal(data, &cfg); err != nil {
243 return nil, fmt.Errorf("failed to parse %s: %w", RepoConfigFileName, err)
244 }
245 if err := validateRepoConfigValues(&cfg); err != nil {
246 return nil, err
247 }
248
249 return &cfg, nil
250}
251
252// validateRepoConfigJSON validates raw JSON bytes against the repo config schema.
253func validateRepoConfigJSON(data []byte, filePath string) error {

Calls 5

validateRepoConfigJSONFunction · 0.85
validateRepoConfigValuesFunction · 0.85
PrintMethod · 0.80
PrintfMethod · 0.45
ErrorfMethod · 0.45