社内向けに作ったのをこちらで公開します。
概要
現代の開発プロジェクトでは、複数の AI ベースコードレビューツールを活用することで、コード品質の向上とレビュー効率化を実現できます。このガイドでは、主要な AI レビューツール(Gemini Code Assist、CodeRabbit、GitHub Copilot)のカスタマイズ方法を解説します。
1. Gemini Code Assist
概要
Google が提供する AI ベースのコードレビューツールで、プルリクエスト(PR)に対して自動的にコードレビューを実行します。
カスタマイズ設定ファイル
.github/gemini_code_assist.md
カスタマイズ可能な項目
1. コーディング規約
プロジェクト固有のコーディングスタイルや命名規則を指定できます。
例:
## Coding Standards
- Use PascalCase for Vue component names
- No magic numbers - always use named constants
- Prefer async/await over Promise chains
2. レビュー重点項目
特に注意してチェックしてほしい項目を明示できます。
例:
## Review Focus Areas
1. Security vulnerabilities (SQL injection, XSS, CSRF)
2. Type safety in TypeScript code
3. Error handling completeness
4. API endpoint authentication
3. フレームワーク・ライブラリ固有のルール
使用しているフレームワークのベストプラクティスを指定できます。
例:
## Vue.js Rules
- Always use `<script setup>` syntax
- Components must have proper TypeScript props definitions
- Use PrimeVue components instead of custom UI implementations
4. 除外項目
レビュー対象外とするファイルやパターンを指定できます。
例:
## Exclusions
- Auto-generated files in `dist/` directory
- Migration scripts (database schema changes)
- Third-party library code
レビュープロセス
- PR 作成 → Gemini Code Assist が自動トリガー
-
自動レビュー実行 →
.github/gemini_code_assist.mdに基づく解析 - フィードバック投稿 → PR コメントとして投稿
- 開発者の対応 → 修正をコミット&プッシュ
-
再レビュー → 必ず
@gemini-code-assistをメンション
重要な注意事項
✅ レビュアーへのメンションは必須
修正後は必ず以下の形式でコメントしてください:
@gemini-code-assist
## Review Feedback Addressed ✅
I have addressed all feedback points.
### Changes Made
| Feedback | Resolution |
|----------|------------|
| [Issue 1] | [Fix description] |
### Commits
- `abc1234` - Fix commit message
Please re-review when you have a chance.
2. CodeRabbit
概要
CodeRabbit は、AI を活用した高度なコードレビュー自動化ツールで、コンテキストを理解した詳細なレビューを提供します。YAML 形式の設定ファイルで細かくカスタマイズ可能です。
カスタマイズ設定ファイル
.coderabbit.yaml
または
.github/.coderabbit.yaml
設定ファイルの構造
# CodeRabbit Configuration
language: "ja" # レビューコメントの言語(en, ja, etc.)
reviews:
# レビューの詳細レベル
level: "detailed" # "quick", "standard", "detailed"
# 自動レビューの有効化
auto_review: true
# レビュー対象の変更サイズ制限(行数)
max_files: 50
max_lines: 1000
# レビューのトーン
tone: "professional" # "friendly", "professional", "concise"
# レビュー重点項目
focus_areas:
- security
- performance
- best_practices
- error_handling
- testing
- documentation
# プロジェクト固有のルール
custom_rules:
- name: "No magic numbers"
description: "すべての数値リテラルは名前付き定数として定義すること"
severity: "error"
- name: "DRY principle"
description: "重複コードは関数やモジュールに抽出すること"
severity: "warning"
- name: "Type annotations"
description: "すべての関数には型アノテーションを付けること"
severity: "error"
# ファイルパターンごとの設定
file_patterns:
- pattern: "**/*.vue"
rules:
- "Use <script setup> syntax"
- "PrimeVue components preferred"
- "Tailwind for layout, PrimeVue variables for colors"
- pattern: "**/*.py"
rules:
- "Use async/await for I/O operations"
- "Proper error handling with try-except"
- "Type hints on all function signatures"
- pattern: "**/*.ts"
rules:
- "Strict TypeScript mode enabled"
- "No 'any' type usage"
- "Proper error handling"
# 除外パターン
exclude:
- "dist/**"
- "node_modules/**"
- "**/*.min.js"
- "**/migrations/**"
- "**/__pycache__/**"
- "*.lock"
# セキュリティチェック
security:
enabled: true
checks:
- "sql_injection"
- "xss"
- "csrf"
- "hardcoded_secrets"
- "insecure_dependencies"
# パフォーマンスチェック
performance:
enabled: true
checks:
- "n_plus_one_queries"
- "inefficient_loops"
- "memory_leaks"
- "blocking_operations"
# テストカバレッジ
testing:
require_tests: true
min_coverage: 80
check_test_quality: true
# コメント設定
comments:
# インラインコメントの最小重要度
min_severity: "warning" # "info", "warning", "error"
# サマリーコメントを投稿
post_summary: true
# 解決済みコメントの自動クローズ
auto_resolve: true
# ラベル自動付与
labels:
enable: true
rules:
- condition: "security issues found"
label: "security"
- condition: "performance issues found"
label: "performance"
- condition: "needs tests"
label: "needs-tests"
CodeRabbit の主要機能
1. コンテキスト理解レビュー
変更の意図や影響範囲を理解した上でレビューを実行します。
2. 段階的レビュー
- Quick: 基本的なチェックのみ(構文、スタイル)
- Standard: 標準的なレビュー(ロジック、エラーハンドリング)
- Detailed: 詳細レビュー(セキュリティ、パフォーマンス、アーキテクチャ)
3. 対話的レビュー
レビューコメントに返信することで、追加の説明や代替案を要求できます。
@coderabbit この変更がパフォーマンスに与える影響を詳しく教えてください
4. 学習機能
過去のレビューから学習し、プロジェクト固有のパターンを認識します。
CodeRabbit のベストプラクティス
1. 言語設定
チームの主要言語を設定することで、理解しやすいフィードバックを得られます。
language: "ja"
2. レビューレベルの使い分け
- 小規模な変更:
quick - 通常の機能追加:
standard - 重要な変更やリファクタリング:
detailed
3. カスタムルールの定義
プロジェクト固有のアンチパターンをルールとして定義します。
custom_rules:
- name: "No hardcoded colors"
description: "Use PrimeVue CSS variables instead"
severity: "error"
pattern: "(#[0-9a-fA-F]{3,6}|rgba?\\()"
3. GitHub Copilot for Pull Requests
概要
GitHub Copilot の PR レビュー機能は、GitHub の公式 AI アシスタントとして、リポジトリのコンテキストを深く理解したレビューを提供します。
カスタマイズ設定ファイル
.github/copilot-instructions.md
設定ファイルの記述方法
# GitHub Copilot Instructions
## Project Context
This is a commercial RAG chatbot service built with FastAPI and Vue.js.
## Code Review Guidelines
### General Rules
- Follow DRY (Don't Repeat Yourself) principle
- No magic numbers - use named constants
- All functions must have proper type annotations
- Comprehensive error handling required
### Security Focus
- Check for OWASP Top 10 vulnerabilities
- Validate all user inputs
- No hardcoded secrets or credentials
- Proper authentication on all API endpoints
### Framework-Specific Rules
#### Vue.js / TypeScript
- Use `<script setup>` syntax
- Proper TypeScript props definitions
- PrimeVue components preferred over custom UI
- Tailwind for layout, PrimeVue CSS variables for colors
- No hardcoded colors (`#ffffff`, `rgba()`)
#### FastAPI / Python
- Use async/await for all I/O operations
- Proper error handling with try-except
- Type hints on all function signatures
- RESTful naming conventions
- Security middleware on protected routes
### Testing Requirements
- Unit tests for all new functions
- Minimum 80% code coverage
- Integration tests for API endpoints
- E2E tests for critical user flows
### Review Priorities
1. **Critical**: Security vulnerabilities, type errors, data leaks
2. **Important**: Missing error handling, unused imports, performance issues
3. **Quality**: Magic numbers, naming conventions, documentation
### File-Specific Rules
#### `*.vue` files
- Must use `<script setup>` with TypeScript
- Props must have TypeScript interfaces
- Emits must be typed
- `<style scoped>` section < 50 lines
#### `*.py` files
- All functions must have docstrings
- Type hints required (no `Any` usage)
- Async functions for database operations
- Proper exception handling
#### `*.ts` files
- Strict mode enabled
- No `any` type usage
- Proper error types defined
- Comprehensive JSDoc for public APIs
### Exclusions
Do not review:
- Files in `dist/` or `node_modules/`
- Auto-generated files (`*.min.js`, `*.d.ts`)
- Database migration files
- Lock files (`package-lock.json`, `poetry.lock`)
### Review Tone
- Professional but friendly
- Provide specific examples
- Suggest concrete improvements
- Reference official documentation when relevant
GitHub Copilot の特徴
1. リポジトリ全体のコンテキスト理解
既存のコードベース、過去の PR、Issue などを参照してレビューします。
2. PR 説明文の自動生成
変更内容を分析し、適切な PR 説明文を自動生成します。
<!-- Copilot が生成する例 -->
## Summary
Implements user authentication with JWT tokens
## Changes
- Added JWT middleware for protected routes
- Implemented login/logout endpoints
- Added user session management
## Testing
- Unit tests for auth service
- Integration tests for login flow
3. インライン会話
特定のコード行について質問したり、代替案を提案してもらえます。
@github-copilot この実装は非同期処理に対応していますか?
4. セキュリティスキャン統合
GitHub Advanced Security と連携し、セキュリティ脆弱性を自動検出します。
GitHub Copilot の使い方
1. PR 作成時の自動レビュー
PR を作成すると、自動的に Copilot がレビューを開始します。
2. 手動レビューのトリガー
コメントで Copilot を呼び出すことができます。
@github-copilot このファイルをレビューしてください
3. 特定の観点でのレビュー依頼
@github-copilot セキュリティの観点からこのコードをレビューしてください
4. コード改善の提案依頼
@github-copilot このコードのパフォーマンスを改善する方法を教えてください
GitHub Copilot のベストプラクティス
1. 明確な指示を記述
.github/copilot-instructions.md に具体的な例を含めることで、より正確なレビューが可能になります。
2. ファイルタイプごとのルール定義
言語やフレームワークごとに異なるルールを明記します。
3. 優先度の明確化
レビューポイントの重要度を3段階(Critical/Important/Quality)で分類します。
4. チーム合意
Copilot の指示内容はチーム全体で合意を取ってから設定します。
3ツールの比較と使い分け
| 特徴 | Gemini Code Assist | CodeRabbit | GitHub Copilot |
|---|---|---|---|
| 設定ファイル | .github/gemini_code_assist.md |
.coderabbit.yaml |
.github/copilot-instructions.md |
| 設定形式 | Markdown | YAML | Markdown |
| 詳細度 | 中 | 高 | 中〜高 |
| 対話性 | メンションで再レビュー | コメントで追加質問可能 | インライン会話可能 |
| 学習機能 | プロジェクト固有ルール | 過去のレビューから学習 | リポジトリ全体を学習 |
| 言語サポート | 多言語(設定で指定) | 多言語(YAML で指定) | 英語中心 |
| 料金 | Google Cloud 従量課金 | 月額課金 | GitHub Pro/Enterprise |
推奨される使い分け
1. Gemini Code Assist
- 適用場面: Google Cloud を既に利用しているプロジェクト
- 強み: Google の AI モデルを活用、シンプルな設定
- 注意点: 再レビューには必ずメンション必要
2. CodeRabbit
- 適用場面: 詳細なカスタマイズが必要なプロジェクト
- 強み: YAML で細かく制御可能、学習機能が強力
- 注意点: 設定ファイルが複雑になりがち
3. GitHub Copilot
- 適用場面: GitHub をメインで使用しているプロジェクト
- 強み: GitHub エコシステムとの統合が強力
- 注意点: GitHub Pro/Enterprise が必要
複数ツールの併用戦略
パターン1: 役割分担
- Gemini Code Assist: 基本的なコードレビュー
- CodeRabbit: セキュリティ・パフォーマンス重点チェック
- GitHub Copilot: PR 説明文生成とインライン質問対応
パターン2: 段階的適用
1. GitHub Copilot: PR 作成時の初期レビュー
2. CodeRabbit: 詳細な自動レビュー
3. Gemini Code Assist: 最終確認レビュー
パターン3: ツール特化
- Frontend コード: GitHub Copilot(TypeScript サポート強力)
- Backend コード: CodeRabbit(セキュリティチェック強力)
- Infrastructure: Gemini Code Assist(GCP 連携強力)
共通のベストプラクティス
1. 設定ファイルのバージョン管理
すべての設定ファイルを Git で管理し、変更履歴を追跡します。
2. チーム合意
設定変更は必ずチーム全体でレビューし、合意を取ります。
3. 定期的な見直し
プロジェクトの成長に合わせて、3ヶ月に1回は設定を見直します。
4. フィードバックループ
AI レビューの精度を向上させるため、誤検知や見落としを記録します。
5. 人間レビューとの併用
AI レビューは補助ツールとして活用し、最終的には人間がレビューします。
6. メンション文化の定着
すべての AI レビューツールに共通: フィードバック対応後は必ずレビューアをメンションします。
@gemini-code-assist
@coderabbit
@github-copilot
## Review Feedback Addressed ✅
All feedback points have been addressed.
### Changes Made
| Feedback | Resolution |
|----------|------------|
| [Issue 1] | [Fix description] |
| [Issue 2] | [Fix description] |
### Commits
- `abc1234` - Fix issue 1
- `def5678` - Fix issue 2
Please re-review when you have a chance.
設定例:AI Feel Chatbot プロジェクト
Gemini Code Assist 設定
# .github/gemini_code_assist.md
## Project Context
Commercial RAG chatbot service with FastAPI and Vue.js
## Mandatory Checks
1. DRY Principle: No duplicate code or magic numbers
2. Type Safety: All functions must have type annotations
3. Security: OWASP Top 10 vulnerabilities
4. Styling: TailwindCSS + PrimeVue CSS variables only
## Framework Rules
### Vue.js
- `<script setup>` syntax required
- PrimeVue components preferred
- Tailwind for layout, PrimeVue variables for colors
### FastAPI
- async/await for database operations
- Proper error handling
- RESTful naming conventions
## Review Priorities
- Critical: Security, type errors
- Important: Error handling, imports
- Quality: Magic numbers, naming
CodeRabbit 設定
# .coderabbit.yaml
language: "ja"
reviews:
level: "detailed"
auto_review: true
tone: "professional"
focus_areas:
- security
- performance
- best_practices
- error_handling
custom_rules:
- name: "No magic numbers"
severity: "error"
- name: "DRY principle"
severity: "warning"
- name: "Type annotations"
severity: "error"
file_patterns:
- pattern: "**/*.vue"
rules:
- "Use <script setup> syntax"
- "PrimeVue components preferred"
- pattern: "**/*.py"
rules:
- "async/await for I/O"
- "Type hints required"
exclude:
- "dist/**"
- "node_modules/**"
- "**/migrations/**"
security:
enabled: true
checks:
- "sql_injection"
- "xss"
- "hardcoded_secrets"
testing:
require_tests: true
min_coverage: 80
GitHub Copilot 設定
# .github/copilot-instructions.md
## Project Context
Commercial RAG chatbot service built with FastAPI and Vue.js
## Code Review Guidelines
### General Rules
- DRY principle strictly enforced
- No magic numbers
- Type annotations required
- Comprehensive error handling
### Framework-Specific Rules
#### Vue.js / TypeScript
- `<script setup>` syntax
- PrimeVue components preferred
- Tailwind + PrimeVue CSS variables
- No hardcoded colors
#### FastAPI / Python
- async/await for I/O
- Type hints required
- Proper exception handling
### Review Priorities
1. Critical: Security, type errors
2. Important: Error handling, performance
3. Quality: Magic numbers, naming
### Exclusions
- `dist/`, `node_modules/`
- Auto-generated files
- Migration files
まとめ
AI コードレビューツールのカスタマイズは、プロジェクトの品質向上とレビュー効率化の鍵となります。各ツールの特性を理解し、プロジェクトのニーズに合わせて適切に設定することで、一貫性のあるコードベースを維持できます。
重要なポイント
- 設定ファイルの管理: すべての設定をバージョン管理
- チーム合意: 設定変更は必ずチームで合意
- 定期的な見直し: 3ヶ月に1回は設定を見直し
- メンション文化: フィードバック対応後は必ずメンション
- 人間レビューとの併用: AI は補助ツール、最終判断は人間
これにより、チーム全体の生産性が向上し、高品質なコードを継続的に提供できます。