@@ -222,7 +222,12 @@ def _render_command(components: list[str], use_all: bool = False) -> str:
222222 return f"azldev component render { ' ' .join (components )} "
223223
224224
225- def format_comment (report : dict , artifacts_url : str | None = None ) -> str :
225+ def format_comment (
226+ report : dict ,
227+ artifacts_url : str | None = None ,
228+ run_id : str | None = None ,
229+ repo : str | None = None ,
230+ ) -> str :
226231 content_diffs = report .get ("content_diffs" , [])
227232 extra_files = report .get ("extra_files" , [])
228233 missing_files = report .get ("missing_files" , [])
@@ -265,14 +270,17 @@ def format_comment(report: dict, artifacts_url: str | None = None) -> str:
265270 ]
266271
267272 if artifacts_url :
268- lines .append (
269- "Or download and apply the fix patch from the "
270- f"[workflow artifacts]({ artifacts_url } #artifacts):"
271- )
273+ lines .append (f"Or [download the fix patch]({ artifacts_url } ) and apply it:" )
272274 lines .append ("" )
273- lines .append (
274- "```bash\n # Download 'rendered-specs.patch' from the link above, then:\n git apply rendered-specs.patch\n ```"
275- )
275+ if run_id and repo :
276+ lines .append (
277+ "```bash\n "
278+ f"gh run download { run_id } -R { repo } -n rendered-specs-patch\n "
279+ "git apply rendered-specs.patch\n "
280+ "```"
281+ )
282+ else :
283+ lines .append ("```bash\n git apply rendered-specs.patch\n ```" )
276284 lines .append ("" )
277285
278286 lines .extend (
@@ -393,7 +401,12 @@ def generate_patch(
393401 continue
394402 lines = text .splitlines (keepends = True )
395403 n = len (lines )
396- diff_body = "" .join (f"+{ line } " if line .endswith ("\n " ) else f"+{ line } \n \\ No newline at end of file\n " for line in lines )
404+ diff_body = "" .join (
405+ f"+{ line } "
406+ if line .endswith ("\n " )
407+ else f"+{ line } \n \\ No newline at end of file\n "
408+ for line in lines
409+ )
397410 parts .append (
398411 f"diff --git a/{ path_str } b/{ path_str } \n "
399412 f"new file mode 100644\n "
@@ -408,7 +421,8 @@ def generate_patch(
408421 try :
409422 committed_bytes = subprocess .run (
410423 ["git" , "show" , f"HEAD:{ path_str } " ],
411- capture_output = True , check = True ,
424+ capture_output = True ,
425+ check = True ,
412426 ).stdout
413427 except subprocess .CalledProcessError :
414428 continue
@@ -423,7 +437,12 @@ def generate_patch(
423437 continue
424438 lines = text .splitlines (keepends = True )
425439 n = len (lines )
426- diff_body = "" .join (f"-{ line } " if line .endswith ("\n " ) else f"-{ line } \n \\ No newline at end of file\n " for line in lines )
440+ diff_body = "" .join (
441+ f"-{ line } "
442+ if line .endswith ("\n " )
443+ else f"-{ line } \n \\ No newline at end of file\n "
444+ for line in lines
445+ )
427446 parts .append (
428447 f"diff --git a/{ path_str } b/{ path_str } \n "
429448 f"deleted file mode 100644\n "
@@ -535,6 +554,11 @@ def main() -> int:
535554 default = None ,
536555 help = "URL to the workflow run artifacts (linked in PR comment)" ,
537556 )
557+ parser .add_argument (
558+ "--run-id" ,
559+ default = None ,
560+ help = "GitHub Actions run ID (for gh run download command in PR comment)" ,
561+ )
538562 args = parser .parse_args ()
539563
540564 if bool (args .repo ) != bool (args .pr ):
@@ -578,15 +602,22 @@ def main() -> int:
578602 if total == 0 :
579603 delete_comment_if_exists (args .repo , args .pr )
580604 else :
581- body = format_comment (report , artifacts_url = args .artifacts_url )
605+ body = format_comment (
606+ report ,
607+ artifacts_url = args .artifacts_url ,
608+ run_id = args .run_id ,
609+ repo = args .repo ,
610+ )
582611 post_or_update_comment (args .repo , args .pr , body )
583612 except (subprocess .CalledProcessError , OSError ) as exc :
584613 print (f"Warning: failed to post/update PR comment: { exc } " , file = sys .stderr )
585614
586615 # 5. Write to GitHub step summary if available
587616 summary_file = os .environ .get ("GITHUB_STEP_SUMMARY" )
588617 if summary_file and total > 0 :
589- summary_body = format_comment (report , artifacts_url = args .artifacts_url )
618+ summary_body = format_comment (
619+ report , artifacts_url = args .artifacts_url , run_id = args .run_id , repo = args .repo
620+ )
590621 if len (summary_body ) <= MAX_STEP_SUMMARY :
591622 with open (summary_file , "a" , encoding = "utf-8" ) as sf :
592623 sf .write (summary_body )
0 commit comments