@@ -17,41 +17,59 @@ func configAgentNames(agents []config.AgentEntry) []string {
1717 return names
1818}
1919
20- // tryLoadOrgConfig attempts to load org config from the given path.
21- // Returns nil without error when the file is absent (best-effort).
22- // Logs warnings via printer for non-ENOENT read errors and parse errors.
23- func tryLoadOrgConfig (path string , printer * ui.Printer ) * config.OrgConfig {
20+ // tryLoadConfig attempts to load config from the given path, accepting both
21+ // OrgConfig (per-org) and PerRepoConfig (per-repo) YAML formats. Returns nil
22+ // without error when the file is absent (best-effort). Per-repo config is
23+ // adapted to OrgConfig via OrgConfigFromPerRepo so callers see a unified type.
24+ func tryLoadConfig (path string , printer * ui.Printer ) * config.OrgConfig {
2425 data , err := os .ReadFile (path )
2526 if err != nil {
2627 if ! os .IsNotExist (err ) {
27- printer .StepWarn ("Org config unreadable (remote resource allowlist unavailable): " + err .Error ())
28+ printer .StepWarn ("Config unreadable (remote resource allowlist unavailable): " + err .Error ())
2829 }
2930 return nil
3031 }
3132 cfg , parseErr := config .ParseOrgConfig (data )
32- if parseErr != nil {
33- printer .StepWarn ("Org config malformed (remote resource allowlist unavailable): " + parseErr .Error ())
33+ if parseErr == nil {
34+ return cfg
35+ }
36+ perRepo , perRepoErr := config .ParsePerRepoConfig (data )
37+ if perRepoErr != nil {
38+ printer .StepWarn ("Config malformed (remote resource allowlist unavailable): " + parseErr .Error ())
3439 return nil
3540 }
36- return cfg
41+ return config . OrgConfigFromPerRepo ( perRepo )
3742}
3843
39- // requireOrgConfig loads org config from the given path with strict error
40- // handling. Returns differentiated errors for missing files, unreadable
41- // files, and parse failures.
42- func requireOrgConfig (path string , printer * ui.Printer ) (* config.OrgConfig , error ) {
44+ // tryLoadOrgConfig is an alias for tryLoadConfig, kept for backward
45+ // compatibility with callers that use the original name.
46+ var tryLoadOrgConfig = tryLoadConfig
47+
48+ // requireConfig loads config from the given path with strict error handling.
49+ // Accepts both OrgConfig and PerRepoConfig YAML; the latter is adapted via
50+ // OrgConfigFromPerRepo. Returns differentiated errors for missing files,
51+ // unreadable files, and parse failures.
52+ func requireConfig (path string , printer * ui.Printer ) (* config.OrgConfig , error ) {
4353 data , err := os .ReadFile (path )
4454 if err != nil {
45- printer .StepFail ("Failed to load org config" )
55+ printer .StepFail ("Failed to load config" )
4656 if os .IsNotExist (err ) {
47- return nil , fmt .Errorf ("URL-referenced resources require an org-level config.yaml with allowed_remote_resources (expected at %s)" , path )
57+ return nil , fmt .Errorf ("URL-referenced resources require a config.yaml with allowed_remote_resources (expected at %s)" , path )
4858 }
49- return nil , fmt .Errorf ("reading org config for remote resource validation: %w" , err )
59+ return nil , fmt .Errorf ("reading config for remote resource validation: %w" , err )
5060 }
5161 cfg , parseErr := config .ParseOrgConfig (data )
52- if parseErr != nil {
53- printer .StepFail ("Failed to parse org config" )
54- return nil , fmt .Errorf ("parsing org config: %w" , parseErr )
62+ if parseErr == nil {
63+ return cfg , nil
5564 }
56- return cfg , nil
65+ perRepo , perRepoErr := config .ParsePerRepoConfig (data )
66+ if perRepoErr != nil {
67+ printer .StepFail ("Failed to parse config" )
68+ return nil , fmt .Errorf ("parsing config: %w" , parseErr )
69+ }
70+ return config .OrgConfigFromPerRepo (perRepo ), nil
5771}
72+
73+ // requireOrgConfig is an alias for requireConfig, kept for backward
74+ // compatibility with callers that use the original name.
75+ var requireOrgConfig = requireConfig
0 commit comments