Skip to content

feat(be): AiChat 엔티티 및 ERD 수정 (#1) #2

feat(be): AiChat 엔티티 및 ERD 수정 (#1)

feat(be): AiChat 엔티티 및 ERD 수정 (#1) #2

Workflow file for this run

name: AI PR Review
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
ai-review:
runs-on: ubuntu-latest
if: github.actor != 'dependabot[bot]'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
run: |
# Get the list of changed files
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep -E '\.(kt|kts|java|sql|yml|yaml|properties|md)$' | head -20)
echo "files<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGED_FILES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Read changed files content
id: file-content
run: |
CONTENT=""
if [ -n "${{ steps.changed-files.outputs.files }}" ]; then
while IFS= read -r file; do
if [ -f "$file" ] && [ -s "$file" ]; then
echo "Processing: $file"
CONTENT="$CONTENT\n\n--- File: $file ---\n"
head -c 8000 "$file" | cat >> temp_content.txt
CONTENT="$CONTENT$(cat temp_content.txt)"
rm -f temp_content.txt
fi
done <<< "${{ steps.changed-files.outputs.files }}"
fi
{
echo "content<<EOF"
echo -e "$CONTENT"
echo "EOF"
} >> $GITHUB_OUTPUT
- name: AI Code Review
id: ai-review
run: |
if [ -z "${{ steps.file-content.outputs.content }}" ]; then
echo "No relevant files changed"
echo "review=No Kotlin/configuration files were changed in this PR." >> $GITHUB_OUTPUT
exit 0
fi
REVIEW=$(curl -s -X POST "https://openrouter.ai/api/v1/chat/completions" \
-H "Authorization: Bearer ${{ secrets.OPENROUTER_API_KEY }}" \
-H "Content-Type: application/json" \
-d '{
"model": "x-ai/grok-4-fast:free",
"messages": [
{
"role": "system",
"content": "코드 리뷰어입니다. 다음 규칙만 검토하세요:\n\n## 검토 항목\n1. **글로벌 익셉션 처리**: @ControllerAdvice 사용, 표준 에러 응답\n2. **ApiResponse 사용**: 모든 API는 ApiResponse<T>로 감싸서 응답\n3. **Kotlin 최적화**: data class, null safety, when 표현식, 확장함수 등\n4. **ktlint 규칙**: 포맷팅, 네이밍 컨벤션\n\n## 응답 형식\n### ✅ 준수사항\n- [잘 지켜진 부분]\n\n### ❌ 위반사항 \n- [파일:라인] 문제점과 수정방법\n\n**점수**: X/10"
},
{
"role": "user",
"content": "다음 PR의 변경사항을 리뷰해주세요:\n\nPR 제목: ${{ github.event.pull_request.title }}\nPR 설명: ${{ github.event.pull_request.body }}\n\n변경된 파일들:\n${{ steps.file-content.outputs.content }}"
}
],
"temperature": 0.3
}')
# Extract the review content
REVIEW_CONTENT=$(echo "$REVIEW" | jq -r '.choices[0].message.content // "리뷰 생성에 실패했습니다."')
echo "review<<EOF" >> $GITHUB_OUTPUT
echo "$REVIEW_CONTENT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Post review comment
uses: actions/github-script@v7
with:
script: |
const review = `${{ steps.ai-review.outputs.review }}`;
// Find existing review comment
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.data.find(comment =>
comment.user.login === 'github-actions[bot]' &&
comment.body.includes('🤖 AI 코드 리뷰')
);
const commentBody = "## 🤖 AI 코드 리뷰\n\n" + review + "\n\n---\n<details>\n<summary>💡 리뷰 정보</summary>\n\n- 모델: Grok-4-fast\n- 리뷰 시간: " + new Date().toLocaleString('ko-KR', {timeZone: 'Asia/Seoul'}) + "\n- PR: #${{ github.event.number }}\n\n</details>";
if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: commentBody
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody
});
}