@@ -17,6 +17,9 @@ def run_gh_command(args):
1717 )
1818 return result .stdout .strip ()
1919 except subprocess .CalledProcessError as e :
20+ if "--json" in args :
21+ # For JSON commands, return empty JSON array/object
22+ return "[]" if "list" in args else "{}"
2023 print (f"❌ GitHub CLI error: { e .stderr } " )
2124 return ""
2225 except FileNotFoundError :
@@ -26,50 +29,66 @@ def run_gh_command(args):
2629
2730def get_status_issue ():
2831 """Get or create the status issue"""
29- # Check if status issue exists
30- output = run_gh_command (
31- [
32- "issue" ,
33- "list" ,
34- "-l" ,
35- "conductor:status" ,
36- "--state" ,
37- "open" ,
38- "--limit" ,
39- "1" ,
40- "--json" ,
41- "number,title" ,
42- ]
43- )
44-
45- if output :
46- try :
47- issues = json .loads (output )
48- if issues :
49- return issues [0 ]["number" ]
50- except json .JSONDecodeError :
51- pass
52-
53- # Create new status issue if it doesn't exist
54- print ("📝 Creating new status issue..." )
55- output = run_gh_command (
56- [
57- "issue" ,
58- "create" ,
59- "--title" ,
60- "🏥 Code-Conductor System Status" ,
61- "--body" ,
62- "This issue tracks the system status and health metrics "
63- "for Code-Conductor." ,
64- "--label" ,
65- "conductor:status" ,
66- ]
67- )
32+ max_retries = 3
33+ for attempt in range (max_retries ):
34+ # Check if status issue exists
35+ output = run_gh_command (
36+ [
37+ "issue" ,
38+ "list" ,
39+ "-l" ,
40+ "conductor:status" ,
41+ "--state" ,
42+ "open" ,
43+ "--limit" ,
44+ "10" , # Get more to handle duplicates
45+ "--json" ,
46+ "number,title,createdAt" ,
47+ ]
48+ )
6849
69- # Extract issue number from output
70- if output and "#" in output :
71- issue_number = output .split ("#" )[1 ].split ()[0 ]
72- return int (issue_number )
50+ if output :
51+ try :
52+ issues = json .loads (output )
53+ if issues :
54+ # Return the most recent one
55+ issues .sort (key = lambda x : x ["createdAt" ], reverse = True )
56+ return issues [0 ]["number" ]
57+ except json .JSONDecodeError :
58+ if attempt < max_retries - 1 :
59+ print ("⚠️ Failed to parse issues, retrying..." )
60+ continue
61+
62+ # Only create if we're sure there isn't one
63+ if attempt == max_retries - 1 :
64+ print ("📝 Creating new status issue..." )
65+ try :
66+ output = run_gh_command (
67+ [
68+ "issue" ,
69+ "create" ,
70+ "--title" ,
71+ "🏥 Code-Conductor System Status" ,
72+ "--body" ,
73+ "This issue tracks the system status and health metrics "
74+ "for Code-Conductor." ,
75+ "--label" ,
76+ "conductor:status" ,
77+ ]
78+ )
79+
80+ # Extract issue number from output
81+ if output and "#" in output :
82+ issue_number = output .split ("#" )[1 ].split ()[0 ]
83+ return int (issue_number )
84+ except Exception as e :
85+ print (f"❌ Failed to create issue: { e } " )
86+
87+ # Wait before retry
88+ if attempt < max_retries - 1 :
89+ import time
90+
91+ time .sleep (2 )
7392
7493 return None
7594
0 commit comments