@@ -398,15 +398,53 @@ def parse_repo_url_arg(url_string):
398
398
check_run_id = run .get ('id' )
399
399
check_run_name = run .get ('name' )
400
400
401
- # Construct the command
402
- # We use final_owner and final_repo which were resolved from args or git remote
403
- command = [
404
- "scripts/print_workflow_run_errors.py" ,
405
- "--owner" , final_owner ,
406
- "--repo" , final_repo ,
407
- "--token" , "\" <YOUR_GITHUB_TOKEN_OR_USE_ENV_VAR>\" " , # Using a placeholder
408
- "--run-id" , str (check_run_id )
409
- ]
401
+ # Construct the command for print_workflow_run_errors.py
402
+ command = ["scripts/print_workflow_run_errors.py" ]
403
+
404
+ # Conditionally add --owner and --repo
405
+ owner_repo_was_cmd_line_arg = False
406
+ # A simple check: if --url is in sys.argv, or --owner or --repo.
407
+ # This doesn't perfectly check if argparse *used* these from sys.argv vs default,
408
+ # but it's a good heuristic for "user attempted to specify".
409
+ # More robust would be to compare args.url to its default, etc.
410
+ # For now, this heuristic is acceptable.
411
+ if any (arg .startswith ("--url" ) for arg in sys .argv ):
412
+ owner_repo_was_cmd_line_arg = True
413
+ if not owner_repo_was_cmd_line_arg : # only check --owner/--repo if --url wasn't specified
414
+ if any (arg .startswith ("--owner" ) for arg in sys .argv ) or \
415
+ any (arg .startswith ("--repo" ) for arg in sys .argv ):
416
+ owner_repo_was_cmd_line_arg = True
417
+
418
+ if owner_repo_was_cmd_line_arg :
419
+ command .extend (["--owner" , final_owner , "--repo" , final_repo ])
420
+ # No 'else' needed: if not explicit, print_workflow_run_errors.py should auto-detect
421
+
422
+ # Conditionally add --token
423
+ # Add only if the token was provided via the --token argument to *this* script.
424
+ # We need to know if args.token initially came from the command line vs. env/file.
425
+ # The current `args.token` is always populated if a token is found.
426
+ # We need a way to distinguish. Let's check if sys.argv contained --token.
427
+ token_was_cmd_line_arg = False
428
+ for i , arg_val in enumerate (sys .argv ):
429
+ if arg_val == "--token" :
430
+ if i + 1 < len (sys .argv ): # Ensure there's a value after --token
431
+ # Check if the value matches the one we are using.
432
+ # This isn't foolproof if token is passed as --token=$GITHUB_TOKEN,
433
+ # but it's a reasonable heuristic for direct --token <value>
434
+ if sys .argv [i + 1 ] == args .token :
435
+ token_was_cmd_line_arg = True
436
+ break # Found --token, stop checking
437
+ elif arg_val .startswith ("--token=" ):
438
+ if arg_val .split ('=' , 1 )[1 ] == args .token :
439
+ token_was_cmd_line_arg = True
440
+ break
441
+
442
+
443
+ if token_was_cmd_line_arg :
444
+ command .extend (["--token" , "\" <YOUR_EXPLICIT_TOKEN_HERE>\" " ]) # Placeholder for explicit token
445
+ # No 'else': if not explicit cmd line, print_workflow_run_errors.py should use env/file
446
+
447
+ command .extend (["--run-id" , str (check_run_id )])
410
448
411
449
# Add some optional parameters if they are set in the current script's args,
412
450
# assuming print_workflow_run_errors.py supports them or similar ones.
0 commit comments