@@ -73,15 +73,15 @@ def _load_sdk_configs() -> dict[str, dict]:
7373
7474## Context
7575
76- The root `proto/` directory has changed and the {display_name} SDK's generated bindings are out of sync . The drifted files are: {drifted_names}.
76+ The {display_name} SDK's proto drift check detected drift . The drifted files are: {drifted_names}.
7777{build_context}
7878
7979## Steps
8080
81811. **Regenerate bindings**: Run `mise run {proto_task}` to regenerate language-specific bindings from the updated protos.
82- 2. **Fix compilation errors**: Read the build log above . Update the SDK source code to handle new/changed/removed proto fields:
82+ 2. **Fix compilation errors, if any **: Consult the build log if available . Update the SDK source code as needed to handle new/changed/removed proto fields:
8383{source_dirs}
84- 3. **Fix test failures**: Update tests that assert on proto types that changed shape.
84+ 3. **Fix test failures, if any **: Update tests that assert on proto types that changed shape.
85854. **Verify**: Run `mise run {build_task}` and `mise run {test_task}` until both pass.
86865. **Create a PR**: Commit all changes and create a PR referencing this issue.
8787
@@ -165,6 +165,19 @@ def _render_agent_section(
165165 "The build log above shows the exact error. Your job is to fix the "
166166 f"{ display_name } SDK code so it compiles and passes tests with the updated protos."
167167 )
168+ elif build_report and build_report .get ("success" ) is True :
169+ if sdk == "go" :
170+ build_context = (
171+ "\n Regeneration, build, and tests passed in CI, but the "
172+ "committed bindings still need to be regenerated and committed."
173+ )
174+ else :
175+ build_context = (
176+ "\n The subsequent regeneration, typecheck, and tests passed in CI. "
177+ "Generated TypeScript bindings are gitignored; rerun "
178+ f"`mise run { paths ['drift_task' ]} ` to confirm compatibility "
179+ "before changing SDK source."
180+ )
168181 else :
169182 build_context = "\n The SDK build status is unknown. Check if it compiles after regeneration."
170183
@@ -205,26 +218,59 @@ def _run_cmd(
205218
206219
207220def _ensure_label (repo : str , label : str , description : str ) -> None :
208- check = _run_cmd (["gh" , "label" , "view" , label , "--repo" , repo ], capture = True )
221+ check = _run_cmd (
222+ [
223+ "gh" ,
224+ "label" ,
225+ "list" ,
226+ "--repo" ,
227+ repo ,
228+ "--search" ,
229+ label ,
230+ "--limit" ,
231+ "20" ,
232+ "--json" ,
233+ "name" ,
234+ ],
235+ capture = True ,
236+ )
209237 if check .returncode != 0 :
210- result = _run_cmd (
211- [
212- "gh" ,
213- "label" ,
214- "create" ,
215- label ,
216- "--repo" ,
217- repo ,
218- "--description" ,
219- description ,
220- "--color" ,
221- "D93F0B" ,
222- ],
223- capture = True ,
238+ details = check .stderr .strip () or "unknown error"
239+ raise RuntimeError (f"Failed to look up label '{ label } ' in { repo } : { details } " )
240+ try :
241+ labels = json .loads (check .stdout )
242+ except json .JSONDecodeError as error :
243+ raise RuntimeError (f"Invalid label list for { repo } : { error .msg } " ) from error
244+ if not isinstance (labels , list ) or any (
245+ not isinstance (item , dict ) or not isinstance (item .get ("name" ), str )
246+ for item in labels
247+ ):
248+ raise RuntimeError (f"Invalid label list for { repo } : expected label names" )
249+ # GitHub's search is fuzzy; similar SDK labels do not establish existence.
250+ if any (item ["name" ].casefold () == label .casefold () for item in labels ):
251+ return
252+ if len (labels ) >= 20 :
253+ raise RuntimeError (
254+ f"Label search for '{ label } ' in { repo } was truncated; cannot confirm absence"
224255 )
225- if result .returncode != 0 :
226- details = result .stderr .strip () or "unknown error"
227- raise RuntimeError (f"Failed to create label '{ label } ': { details } " )
256+ result = _run_cmd (
257+ [
258+ "gh" ,
259+ "label" ,
260+ "create" ,
261+ label ,
262+ "--repo" ,
263+ repo ,
264+ "--description" ,
265+ description ,
266+ "--color" ,
267+ "D93F0B" ,
268+ ],
269+ capture = True ,
270+ )
271+ if result .returncode != 0 :
272+ details = result .stderr .strip () or "unknown error"
273+ raise RuntimeError (f"Failed to create label '{ label } ': { details } " )
228274
229275
230276def _find_open_issue (repo : str , label : str ) -> dict | None :
@@ -239,20 +285,44 @@ def _find_open_issue(repo: str, label: str) -> dict | None:
239285 label ,
240286 "--state" ,
241287 "open" ,
288+ "--limit" ,
289+ "1" ,
242290 "--json" ,
243291 "url,number" ,
244- "--jq" ,
245- ".[0]" ,
246292 ],
247293 capture = True ,
248294 )
249- if result .returncode == 0 and result .stdout .strip ():
250- try :
251- data = json .loads (result .stdout .strip ())
252- return {"url" : data ["url" ], "number" : str (data ["number" ])}
253- except (json .JSONDecodeError , KeyError , TypeError ):
254- pass
255- return None
295+ context = f"for { repo } with label '{ label } '"
296+ if result .returncode != 0 :
297+ details = result .stderr .strip () or "no stderr"
298+ raise RuntimeError (
299+ f"Failed to list open issues { context } "
300+ f"(exit code { result .returncode } ): { details } "
301+ )
302+ try :
303+ issues = json .loads (result .stdout )
304+ except json .JSONDecodeError as error :
305+ raise RuntimeError (
306+ f"Invalid issue list { context } : expected JSON array ({ error .msg } )"
307+ ) from error
308+ if not isinstance (issues , list ):
309+ raise RuntimeError (f"Invalid issue list { context } : expected JSON array" )
310+ if not issues :
311+ return None
312+
313+ issue = issues [0 ]
314+ if not isinstance (issue , dict ):
315+ raise RuntimeError (f"Invalid issue list { context } : expected issue object" )
316+ url = issue .get ("url" )
317+ number = issue .get ("number" )
318+ if (
319+ not isinstance (url , str )
320+ or not url .strip ()
321+ or type (number ) is not int
322+ or number <= 0
323+ ):
324+ raise RuntimeError (f"Invalid issue list { context } : invalid issue URL or number" )
325+ return {"url" : url , "number" : str (number )}
256326
257327
258328# --- public functions ---
@@ -348,18 +418,23 @@ def _manage_issue(
348418# --- CLI ---
349419
350420
351- def _load_json_arg (value : str ) -> dict | list :
352- if value == "-" :
353- return json .load (sys .stdin )
354- return json .loads (value )
421+ def _load_json_arg (value : str ) -> dict :
422+ report = json .load (sys .stdin ) if value == "-" else json .loads (value )
423+ if not isinstance (report , dict ):
424+ raise ValueError ("Expected report to be a JSON object" )
425+ return report
355426
356427
357428def cmd_manage_issue (args : argparse .Namespace ) -> int :
358- drift_report = _load_json_arg (args .drift_report )
359- build_report = None
360- if args .build_report :
361- build_report = _load_json_arg (args .build_report )
362- result = manage_issue (drift_report , build_report , args .sdk , args .repo , args .label )
429+ try :
430+ drift_report = _load_json_arg (args .drift_report )
431+ build_report = _load_json_arg (args .build_report ) if args .build_report else None
432+ except ValueError as error :
433+ result = {"issue_url" : "" , "action" : "error" , "reason" : str (error )}
434+ else :
435+ result = manage_issue (
436+ drift_report , build_report , args .sdk , args .repo , args .label
437+ )
363438 print (json .dumps (result ))
364439 return 1 if result .get ("action" ) == "error" else 0
365440
0 commit comments