1919from .config import (
2020 SUBMODULE_REPOS ,
2121 get_data_dir ,
22- get_factory_repo ,
2322 get_github_username ,
24- get_local_repo ,
2523 get_overlay_repo ,
24+ get_repo ,
2625 list_submodule_repos ,
2726 save_github_username ,
2827 setup_submodule ,
@@ -97,89 +96,45 @@ def cmd_status(fmt: OutputFormatter, _args: argparse.Namespace) -> int:
9796 next_steps : list [str ] = []
9897 needs_setup = False
9998
100- # Check overlay repo
101- overlay_repo = get_overlay_repo ()
102- if overlay_repo :
103- branch = get_git_branch (overlay_repo )
104- status = "uncommitted" if has_uncommitted_changes (overlay_repo ) else "clean"
105- checks .append (
106- {
107- "name" : "overlay_repo" ,
108- "status" : "pass" ,
109- "message" : f"{ overlay_repo } ({ branch } , { status } )" ,
110- "path" : str (overlay_repo ),
111- "branch" : branch ,
112- "clean" : status == "clean" ,
113- }
114- )
115- fmt .log_ok (f"overlay repo: { overlay_repo } ({ branch } , { status } )" )
116- else :
117- checks .append (
118- {
119- "name" : "overlay_repo" ,
120- "status" : "fail" ,
121- "message" : "not found" ,
122- }
123- )
124- fmt .log_fail ("overlay repo: not found" )
125- needs_setup = True
126-
127- # Check rhdh-local
128- local_repo = get_local_repo ()
129- if local_repo :
130- # Check if running (podman)
131- running = False
132- if check_tool ("podman" ):
133- rc , stdout , _ = run_command (["podman" , "ps" , "--format" , "{{.Names}}" ])
134- running = rc == 0 and "rhdh" in stdout
135-
136- status_msg = "running" if running else "not running"
137- check_status = "pass" if running else "warn"
138- checks .append (
139- {
140- "name" : "rhdh_local" ,
141- "status" : check_status ,
142- "message" : f"{ local_repo } ({ status_msg } )" ,
143- "path" : str (local_repo ),
144- "running" : running ,
145- }
146- )
147- if running :
148- fmt .log_ok (f"rhdh-local: { local_repo } (running)" )
149- else :
150- fmt .log_warn (f"rhdh-local: { local_repo } (not running)" )
151- else :
152- checks .append (
153- {
154- "name" : "rhdh_local" ,
155- "status" : "fail" ,
156- "message" : "not found" ,
157- }
158- )
159- fmt .log_fail ("rhdh-local: not found" )
160- needs_setup = True
99+ # Check all configured repos
100+ for repo_name , info in SUBMODULE_REPOS .items ():
101+ config_key = info ["config_key" ]
102+ required = info ["required" ]
103+ repo_path = get_repo (config_key )
161104
162- # Check factory (optional)
163- factory_repo = get_factory_repo ()
164- if factory_repo :
165- checks .append (
166- {
167- "name" : "factory" ,
168- "status" : "pass" ,
169- "message" : str (factory_repo ),
170- "path" : str (factory_repo ),
171- }
172- )
173- fmt .log_ok (f"factory: { factory_repo } " )
174- else :
175- checks .append (
176- {
177- "name" : "factory" ,
178- "status" : "info" ,
179- "message" : "not configured (optional)" ,
180- }
181- )
182- fmt .log_info ("factory: not configured (optional)" )
105+ if repo_path :
106+ branch = get_git_branch (repo_path )
107+ status = "uncommitted" if has_uncommitted_changes (repo_path ) else "clean"
108+ checks .append (
109+ {
110+ "name" : config_key ,
111+ "status" : "pass" ,
112+ "message" : f"{ repo_path } ({ branch } , { status } )" ,
113+ "path" : str (repo_path ),
114+ "branch" : branch ,
115+ "clean" : status == "clean" ,
116+ }
117+ )
118+ fmt .log_ok (f"{ config_key } : { repo_path } ({ branch } , { status } )" )
119+ elif required :
120+ checks .append (
121+ {
122+ "name" : config_key ,
123+ "status" : "fail" ,
124+ "message" : "not found" ,
125+ }
126+ )
127+ fmt .log_fail (f"{ config_key } : not found" )
128+ needs_setup = True
129+ else :
130+ checks .append (
131+ {
132+ "name" : config_key ,
133+ "status" : "info" ,
134+ "message" : "not configured (optional)" ,
135+ }
136+ )
137+ fmt .log_info (f"{ config_key } : not configured (optional)" )
183138
184139 # Check tools
185140 fmt .header ("Tools" )
@@ -279,56 +234,38 @@ def cmd_doctor(fmt: OutputFormatter, _args: argparse.Namespace) -> int:
279234 checks : list [dict [str , Any ]] = []
280235 issues : list [str ] = []
281236
282- # Check repos
283- overlay_repo = get_overlay_repo ()
284- if overlay_repo :
285- checks . append ({ "name" : "overlay_repo" , "status" : "pass" , "message" : str ( overlay_repo )})
286- fmt . log_ok ( f"Overlay repo found: { overlay_repo } " )
237+ # Check all repos
238+ for repo_name , info in SUBMODULE_REPOS . items ():
239+ config_key = info [ "config_key" ]
240+ required = info [ "required" ]
241+ repo_path = get_repo ( config_key )
287242
288- # Check it's a git repo
289- rc , _ , _ = run_command (["git" , "rev-parse" , "--git-dir" ], cwd = overlay_repo )
290- if rc == 0 :
291- checks .append ({"name" : "overlay_git" , "status" : "pass" , "message" : "valid" })
292- fmt .log_ok (" Git repository valid" )
293- else :
294- checks .append ({"name" : "overlay_git" , "status" : "fail" , "message" : "invalid" })
295- fmt .log_fail (" Not a valid git repository" )
296- issues .append ("Overlay repo is not a git repository" )
243+ if repo_path :
244+ checks .append ({"name" : config_key , "status" : "pass" , "message" : str (repo_path )})
245+ fmt .log_ok (f"{ config_key } found: { repo_path } " )
297246
298- # Check remote
299- rc , stdout , _ = run_command (["git" , "remote " , "get-url" , "origin" ], cwd = overlay_repo )
300- if rc == 0 :
301- remote = stdout . strip ()
302- if "rhdh-plugin-export-overlays" in remote :
303- checks . append ({ "name" : "overlay_remote" , "status" : "pass" , "message" : remote } )
304- fmt .log_ok (f " Remote: { remote } " )
247+ # Check it's a git repo
248+ rc , _ , _ = run_command (["git" , "rev-parse " , "--git-dir" ], cwd = repo_path )
249+ if rc == 0 :
250+ checks . append (
251+ { "name" : f" { config_key } _git" , "status" : "pass" , "message" : "valid" }
252+ )
253+ fmt .log_ok (" Git repository valid " )
305254 else :
306- checks .append ({"name" : "overlay_remote" , "status" : "warn" , "message" : remote })
307- fmt .log_warn (f" Remote may be incorrect: { remote } " )
308- else :
309- checks .append ({"name" : "overlay_repo" , "status" : "fail" , "message" : "not found" })
310- fmt .log_fail ("Overlay repo not found" )
311- issues .append ("Configure overlay repo: rhdh config set overlay /path/to/repo" )
312-
313- local_repo = get_local_repo ()
314- if local_repo :
315- checks .append ({"name" : "rhdh_local" , "status" : "pass" , "message" : str (local_repo )})
316- fmt .log_ok (f"rhdh-local found: { local_repo } " )
317-
318- # Check compose file exists
319- has_compose = (local_repo / "compose.yaml" ).exists () or (
320- local_repo / "docker-compose.yaml"
321- ).exists ()
322- if has_compose :
323- checks .append ({"name" : "compose_file" , "status" : "pass" , "message" : "found" })
324- fmt .log_ok (" Compose file found" )
255+ checks .append (
256+ {"name" : f"{ config_key } _git" , "status" : "fail" , "message" : "invalid" }
257+ )
258+ fmt .log_fail (" Not a valid git repository" )
259+ issues .append (f"{ config_key } is not a git repository" )
260+ elif required :
261+ checks .append ({"name" : config_key , "status" : "fail" , "message" : "not found" })
262+ fmt .log_fail (f"{ config_key } not found" )
263+ issues .append (f"Configure { config_key } : rhdh config set { config_key } /path/to/repo" )
325264 else :
326- checks .append ({"name" : "compose_file" , "status" : "warn" , "message" : "not found" })
327- fmt .log_warn (" No compose file found" )
328- else :
329- checks .append ({"name" : "rhdh_local" , "status" : "fail" , "message" : "not found" })
330- fmt .log_fail ("rhdh-local not found" )
331- issues .append ("Configure rhdh-local: rhdh config set local /path/to/repo" )
265+ checks .append (
266+ {"name" : config_key , "status" : "info" , "message" : "not configured (optional)" }
267+ )
268+ fmt .log_info (f"{ config_key } : not configured (optional)" )
332269
333270 fmt .header ("GitHub CLI" )
334271
@@ -479,14 +416,14 @@ def cmd_config_init(fmt: OutputFormatter, args: argparse.Namespace) -> int:
479416 fmt .log_ok (f"Created: { data .get ('created' , '' )} " )
480417 config = data .get ("config" , {})
481418 repos = config .get ("repos" , {})
482- if repos . get ( "overlay" ):
483- fmt . log_ok ( f"Auto-detected overlay: { repos [ 'overlay' ] } " )
484- else :
485- fmt .log_info ( "overlay: not found (configure with: rhdh config set repos.overlay /path) " )
486- if repos . get ( "local" ) :
487- fmt .log_ok ( f"Auto-detected local: { repos [ 'local' ] } " )
488- else :
489- fmt . log_info ( "local: not found (configure with: rhdh config set repos.local /path)" )
419+ for info in SUBMODULE_REPOS . values ( ):
420+ key = info [ "config_key" ]
421+ if repos . get ( key ) :
422+ fmt .log_ok ( f"Auto-detected { key } : { repos [ key ] } " )
423+ elif info [ "required" ] :
424+ fmt .log_info (
425+ f" { key } : not found (configure with: rhdh config set { key } /path)"
426+ )
490427 fmt .success (data , next_steps = next_steps )
491428 return 0
492429 else :
@@ -511,18 +448,14 @@ def cmd_config_show(fmt: OutputFormatter, args: argparse.Namespace) -> int:
511448
512449 fmt .header ("Resolved Paths" )
513450 resolved = data .get ("resolved" , {})
514- if resolved .get ("overlay" ):
515- fmt .log_ok (f"overlay: { resolved ['overlay' ]} " )
516- else :
517- fmt .log_fail ("overlay: not found" )
518- if resolved .get ("local" ):
519- fmt .log_ok (f"local: { resolved ['local' ]} " )
520- else :
521- fmt .log_fail ("local: not found" )
522- if resolved .get ("factory" ):
523- fmt .log_ok (f"factory: { resolved ['factory' ]} " )
524- else :
525- fmt .log_info ("factory: not configured" )
451+ for info in SUBMODULE_REPOS .values ():
452+ key = info ["config_key" ]
453+ if resolved .get (key ):
454+ fmt .log_ok (f"{ key } : { resolved [key ]} " )
455+ elif info ["required" ]:
456+ fmt .log_fail (f"{ key } : not found" )
457+ else :
458+ fmt .log_info (f"{ key } : not configured" )
526459
527460 fmt .success (data , next_steps = next_steps )
528461 return 0
0 commit comments