@@ -112,26 +112,27 @@ jobs:
112112
113113 # 변경된 파일과 라인에 리뷰 코멘트를 추가
114114 commit_id = "${{ github.event.pull_request.head.sha }}"
115- line_number = file.get('patch').split('\n').index(next(line for line in file['patch'].split('\n') if line.startswith('+'))) + 1
116- comment_body = {
117- "body": review_comment,
118- "path": file_path,
119- "line": line_number,
120- "side": "RIGHT",
121- "commit_id": commit_id
122- }
123-
124- # 코멘트를 추가하기 전 파일 경로와 위치를 로그로 출력
125- print(f"Commenting on file: {file_path}, line: {line_number}")
126-
127- comment_url = f"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/comments"
128- response = requests.post(comment_url, headers=headers, data=json.dumps(comment_body))
129-
130- # 응답 상태 확인
131- if response.status_code == 201:
132- print(f"Comment posted successfully for file: {file_path}")
133- else:
134- print(f"Failed to post comment. Status code: {response.status_code}, Response: {response.text}")
115+ position = file.get('position', None) # 'position' 필드 사용
116+ if position is not None:
117+ comment_body = {
118+ "body": review_comment,
119+ "path": file_path,
120+ "position": position, # 'line' 대신 'position' 사용
121+ "side": "RIGHT",
122+ "commit_id": commit_id
123+ }
124+
125+ # 코멘트를 추가하기 전 파일 경로와 위치를 로그로 출력
126+ print(f"Commenting on file: {file_path}, position: {position}")
127+
128+ comment_url = f"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/comments"
129+ response = requests.post(comment_url, headers=headers, data=json.dumps(comment_body))
130+
131+ # 응답 상태 확인
132+ if response.status_code == 201:
133+ print(f"Comment posted successfully for file: {file_path}")
134+ else:
135+ print(f"Failed to post comment. Status code: {response.status_code}, Response: {response.text}")
135136
136137 # 각 파일을 처리한 후 파일 이름을 기록
137138 processed_files.add(file_path)
0 commit comments