AI 기반 자동 GitHub Pull Request 코드 리뷰 시스템
이 프로젝트는 GitHub Actions와 Google Gemini AI를 활용하여 Pull Request에 대한 자동 코드 리뷰를 수행하는 Spring Boot 애플리케이션입니다.
- 🔍 자동 코드 리뷰: PR이 생성되거나 업데이트될 때 자동으로 코드 분석
- 🤖 AI 기반 분석: Google Gemini를 활용한 지능형 코드 리뷰
- 💬 GitHub 통합: 리뷰 결과를 PR 코멘트로 직접 작성
- 🏷️ 자동 라벨링: 리뷰 상태에 따른 자동 라벨 관리
- ⚙️ 커스터마이징 가능: 파일 타입, 크기, 리뷰 범위 설정 가능
- Java 17 이상
- Gradle 8.5 이상
- GitHub Repository
- Google Gemini API Key
- Google AI Studio 접속
- "Get API key" 클릭
- 프로젝트 선택 또는 새 프로젝트 생성
- API 키 생성 및 복사
- GitHub > Settings > Developer settings > Personal access tokens
- "Generate new token (classic)" 클릭
- 필요 권한 선택:
repo(전체 리포지토리 액세스)write:discussion(PR 코멘트 작성)
- 토큰 생성 및 복사
- Repository Fork 또는 Clone
git clone https://github.com/your-org/github-code-reviewer.git
cd github-code-reviewer- GitHub Secrets 설정
Repository Settings > Secrets and variables > Actions에서 다음 시크릿 추가:
GEMINI_API_KEY: Google Gemini API 키 (여기서 발급)
- GitHub Actions Workflow 추가
.github/workflows/code-review.yml 파일을 대상 repository에 복사
- 로컬 테스트
# 환경 변수 설정
export GITHUB_TOKEN=your-github-token
export GEMINI_API_KEY=your-gemini-key
export GITHUB_REPOSITORY=owner/repo
export PR_NUMBER=1
# 빌드 및 실행
./gradlew build
./gradlew runReview# Swagger UI와 함께 웹 서버 실행
./gradlew runWeb
# 또는 환경 변수와 함께 실행
export GITHUB_TOKEN=your-github-token
export GEMINI_API_KEY=your-gemini-key
export GITHUB_REPOSITORY=owner/repo
./gradlew runWeb브라우저에서 http://localhost:8080/swagger-ui.html 접속
POST /api/review/pr/{prNumber}- 특정 PR 리뷰POST /api/review/manual- 수동 코드 리뷰GET /api/review/health- 서비스 상태 확인
github-code-reviewer/
├── src/main/java/com/seevis/codereview/
│ ├── GitHubCodeReviewerApplication.java # 메인 애플리케이션
│ ├── service/
│ │ ├── GitHubService.java # GitHub API 연동
│ │ ├── AIReviewService.java # AI 리뷰 서비스
│ │ └── CodeReviewOrchestrator.java # 리뷰 오케스트레이터
│ └── model/
│ ├── PullRequest.java # PR 모델
│ ├── CodeChange.java # 코드 변경 모델
│ ├── ReviewComment.java # 리뷰 코멘트 모델
│ ├── ReviewResult.java # 리뷰 결과 모델
│ └── ReviewIssue.java # 리뷰 이슈 모델
├── .github/workflows/
│ └── code-review.yml # GitHub Actions workflow
├── build.gradle # Gradle 빌드 설정
└── src/main/resources/
└── application.yml # 애플리케이션 설정
# AI 모델 설정 (Gemini)
gemini:
model: gemini-1.5-flash # 사용할 AI 모델 (gemini-1.5-flash, gemini-1.5-pro)
temperature: 0.3 # 창의성 레벨 (0.0-1.0)
max-tokens: 2048 # 최대 토큰 수
# 코드 리뷰 설정
code-review:
max-files: 50 # 리뷰할 최대 파일 수
max-file-size-kb: 500 # 최대 파일 크기 (KB)
max-comments-per-review: 20 # PR당 최대 코멘트 수- 프로그래밍 언어: Java, Kotlin, JavaScript, TypeScript, Python, Go, Rust, C/C++, C#, Ruby, PHP, Swift, Scala
- 설정 파일: XML, YAML, JSON, Properties, Gradle
- 기타: SQL, Shell Scripts, Dockerfile
AI는 다음 항목들을 중점적으로 검토합니다:
- 🐛 버그 가능성: 잠재적 버그 및 로직 오류
- 🔒 보안 취약점: SQL Injection, XSS 등 보안 이슈
- ⚡ 성능 문제: 비효율적인 알고리즘, 메모리 누수
- 🎨 코드 품질: 명명 규칙, 가독성, 중복 코드
- ✨ 베스트 프랙티스: 언어별 관례 및 모범 사례
🤖 **AI Code Review Complete**
Found 3 issues in UserService.java:
🟡 **WARNING** 🔒
**Issue:** Potential SQL injection vulnerability
**Line:** 45
**Suggestion:** Use parameterized queries instead of string concatenation
🔵 **INFO** ✨
**Issue:** Method could be simplified using Stream API
**Line:** 78
**Suggestion:** Consider using stream().filter().collect() pattern더 안전하고 확장 가능한 인증을 위해 GitHub App을 사용할 수 있습니다:
- GitHub App 생성 (Settings > Developer settings > GitHub Apps)
- 필요 권한 설정:
- Pull requests: Read & Write
- Contents: Read
- Issues: Write
- App ID와 Private Key 설정
다른 AI 서비스(OpenAI, Claude 등)를 사용하려면 AIReviewService.java를 수정하세요.
프로젝트 개선을 위한 기여를 환영합니다!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
이 프로젝트는 MIT 라이선스 하에 배포됩니다.
문제가 발생하거나 질문이 있으시면 Issues를 통해 문의해주세요.
- Built with Spring Boot & Gradle
- Powered by Google Gemini AI
- GitHub API integration using kohsuke/github-api
Made with ❤️ by Seevis Team