File indexing completed on 2025-12-16 09:27:47
0001
0002 """
0003 Script to create GitHub PR comments for ONNX model updates
0004 """
0005 import argparse
0006 import sys
0007 from PRfunctions import *
0008
0009
0010 parser = argparse.ArgumentParser(description='Create a PR comment with calibration update suggestions')
0011 parser.add_argument('--pr', type=str, required=True, help='Pull request number')
0012 parser.add_argument('--newURL', type=str, required=True, help='URL of the new updated calibration')
0013 parser.add_argument('--githubToken', type=str, required=True, help='GitHub token for authentication')
0014 parser.add_argument('--calibrationFile', type=str, default='calibrations/onnx/Low-Q2_Steering_Reconstruction.onnx', help='Path to the local calibration file')
0015 parser.add_argument('--xml', type=str, default='compact/calibrations.xml', help='Path to the XML configuration file')
0016 parser.add_argument('--repository', type=str, default='eic/epic', help='GitHub repository (owner/name)')
0017 parser.add_argument('--artifactsURL', type=str, default='', help='URL to job artifacts for review')
0018
0019
0020 args = parser.parse_args()
0021
0022 pr_number = args.pr
0023 new_url = args.newURL
0024 github_token = args.githubToken
0025 calibration_file = args.calibrationFile
0026 xml_file = args.xml
0027 repository = args.repository
0028 artifacts_url = args.artifactsURL
0029
0030
0031
0032
0033 repo_owner, repo_name = parse_repository(repository)
0034 if not repo_owner or not repo_name:
0035 print("Invalid repository format. Exiting.")
0036 sys.exit(1)
0037
0038
0039
0040
0041 print(f"Starting PR update for PR #{pr_number} in {repository}")
0042 pr_info = get_pr_info(repo_owner, repo_name, pr_number, github_token)
0043 if not pr_info:
0044 print("Failed to retrieve PR information. Exiting.")
0045 sys.exit(1)
0046
0047
0048
0049 content = get_file_content(repo_owner, repo_name, xml_file, pr_info['head']['sha'], github_token)
0050 if not content:
0051 print("Failed to retrieve file content. Exiting.")
0052 sys.exit(1)
0053
0054
0055
0056
0057 line_number, suggested_line = find_and_update_epic_fileloader_url(content, calibration_file, new_url)
0058
0059
0060
0061 if line_number is not None and suggested_line is not None:
0062 print(f"✅ Found URL to update in {xml_file} at line {line_number}")
0063 print(f" Suggested change: {suggested_line.strip()}")
0064
0065
0066 response = create_pr_suggestion(repo_owner, repo_name, pr_number, calibration_file, xml_file, line_number, suggested_line, pr_info['head']['sha'], github_token, artifacts_url)
0067
0068 if response:
0069 print("🎉 PR comment created successfully!")
0070 else:
0071 print("❌ Failed to create PR comment")
0072 sys.exit(1)
0073 else:
0074 print(f"❌ Failed to find URL to update in {xml_file}")
0075 sys.exit(1)
0076
0077