@@ -116,22 +116,42 @@ def get_llm_response(prompt, api_key, model_name="gpt-4o"): # 或 "gemini-pro"
116116 llm_api_key = os .environ .get ('LLM_API_KEY' ) # 统一使用 LLM_API_KEY 环境变量
117117 llm_model_name = os .environ .get ('LLM_MODEL_NAME' , 'gpt-4o' ) # 默认为 gpt-4o
118118
119+ # <-- 新增的调试输出 -->
120+ print (f"--- Python Script Init Debug ---" )
121+ print (f"Read GITHUB_BASE_REF: { base_ref } " )
122+ print (f"Read GITHUB_HEAD_REF: { head_ref } " )
123+ print (f"Read GITHUB_PR_NUMBER: { pull_request_number } " )
124+ print (f"Read GITHUB_REPOSITORY: { repo_name } " )
125+ print (f"LLM_API_KEY is { 'present' if llm_api_key else 'MISSING' } " )
126+ print (f"--- End Python Script Init Debug ---" )
127+ # <-- 结束新增的调试输出 -->
128+
119129 if not all ([base_ref , head_ref , pull_request_number , repo_name , llm_api_key ]):
120130 print ("Missing required environment variables." )
131+ # 更详细的缺失信息
132+ missing_vars = []
133+ if not base_ref : missing_vars .append ("GITHUB_BASE_REF" )
134+ if not head_ref : missing_vars .append ("GITHUB_HEAD_REF" )
135+ if not pull_request_number : missing_vars .append ("GITHUB_PR_NUMBER" )
136+ if not repo_name : missing_vars .append ("GITHUB_REPOSITORY" )
137+ if not llm_api_key : missing_vars .append ("LLM_API_KEY" )
138+ print (f"Specifically missing: { ', ' .join (missing_vars )} " )
121139 sys .exit (1 )
122140
123141 print (f"Reviewing PR #{ pull_request_number } for { repo_name } ..." )
124142 print (f"Base Ref: { base_ref } , Head Ref: { head_ref } " )
125143
126144 # 切换到 base_ref 以便正确获取 diff
127- subprocess .run (f"git fetch origin { base_ref } " , shell = True , check = True )
128- subprocess .run (f"git checkout { base_ref } " , shell = True , check = True )
145+ # subprocess.run(f"git fetch origin {base_ref}", shell=True, check=True)
146+ # subprocess.run(f"git checkout {base_ref}", shell=True, check=True)
129147
130148 # 获取所有变更的 .java 文件路径
131149 changed_java_files_command = f"git diff --name-only { base_ref } { head_ref } | grep '\\ .java$'"
150+ print (f"Executing git diff command: { changed_java_files_command } " ) # <-- 新增调试:打印实际执行的命令
132151 changed_java_files = subprocess .check_output (changed_java_files_command , shell = True , text = True , encoding = 'utf-8' ).strip ()
133152 changed_files_list = changed_java_files .split ('\n ' ) if changed_java_files else []
134153
154+
135155 if not changed_java_files :
136156 print ("No Java files changed in this PR. Skipping AI review." )
137157 # 在 GitHub Actions 中,如果不想让这一步失败,可以 exit 0 或不输出任何内容
0 commit comments