@@ -43,10 +43,11 @@ jobs:
4343 # 시스템 프롬프트 및 모델명 가져오기
4444 system_prompt = """${{ secrets.SYSTEM_PROMPT }}"""
4545 model_name = "${{ secrets.OPENAI_MODEL }}"
46+ summary_system_prompt = """${{ secrets.SUMMARY_SYSTEM_PROMPT }}"""
4647
4748 # 처리된 파일과 라인 기록 (중복 방지)
4849 processed_files = set() # 각 파일을 기록
49- processed_lines = {} # 각 파일별로 라인을 기록하기 위한 딕셔너리로 수정
50+ review_history = [] # 각 파일의 리뷰 기록을 저장
5051
5152 # GitHub API 호출 로그
5253 print("Fetching changed files from GitHub API...")
99100 {"role": "system", "content": system_prompt},
100101 {"role": "user", "content": f"Here is the code diff for context:\n{patch}"}
101102 ],
103+ max_tokens=500,
102104 timeout=30
103105 )
104106 except Exception as e:
@@ -109,6 +111,9 @@ jobs:
109111 print(f"GPT response received for file: {file_path}")
110112 print(f"Review comment: {review_comment}")
111113
114+ # 리뷰 히스토리 기록
115+ review_history.append(f"File: {file_path}\nReview: {review_comment}")
116+
112117 # 변경된 파일과 라인에 리뷰 코멘트를 추가
113118 commit_id = "${{ github.event.pull_request.head.sha }}"
114119 line_number = file.get('patch').split('\n').index(next(line for line in file['patch'].split('\n') if line.startswith('+'))) + 1
@@ -135,14 +140,34 @@ jobs:
135140 # 각 파일을 처리한 후 파일 이름을 기록
136141 processed_files.add(file_path)
137142
143+ # 최종 요약 요청
144+ review_history_text = "\n\n".join(review_history)
145+ print("Requesting final review summary from GPT...")
146+ try:
147+ final_review_response = openai.chat.completions.create(
148+ model=model_name,
149+ messages=[
150+ {"role": "system", "content": summary_system_prompt},
151+ {"role": "user", "content": review_history_text}
152+ ],
153+ max_tokens=1000,
154+ timeout=60 # 타임아웃을 60초로 설정
155+ )
156+ except Exception as e:
157+ print(f"Error in GPT summary request: {e}")
158+ exit(1)
159+
160+ final_review_comment = final_review_response.choices[0].message.content
161+ print(f"Final review comment received: {final_review_comment}")
162+
163+ # 최종 요약 코멘트 추가
164+ comment_url = f"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments"
165+ requests.post(comment_url, headers=headers, data=json.dumps({"body": final_review_comment}))
166+ print("Final review comment posted.")
167+
138168 else:
139169 print(f"Unexpected status code: {response.status_code}")
140170 exit(1)
141171
142- # 최종 리뷰 요약 코멘트 추가
143- final_comment = "### 최종 리뷰 요약: .java 파일에 대한 모든 변경 사항을 검토 완료했습니다."
144- comment_url = f"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments"
145- requests.post(comment_url, headers=headers, data=json.dumps({"body": final_comment}))
146- print("Final review comment posted.")
147172 exit(0)
148173 EOF
0 commit comments