gemini-review について
Google Gemini CLI でコードレビューを行うスキルで、対話型、ヘッドレス、リポジトリ連携の各ワークフローを扱います。ブランチの変更確認や、CI・プルリクエストでのレビュー自動化に対応します。
主な機能
- 01code-review 拡張による対話型レビュー
- 02JSON 出力対応のヘッドレス CLI レビュー
- 03GitHub アプリと Action のワークフロー
- 04GitLab CI のレビュー設定
- 05GEMINI.md によるプロジェクトコンテキスト
活用シーン
- 01ブランチ変更のバグやセキュリティ問題の確認
- 02プルリクエストレビューの自動化
- 03CI パイプラインでのコードレビュー実行
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ alinaqi/ maggy --skill gemini-reviewインストール後、Claude Code で/gemini-reviewを入力して読み込まれたか確認します。
詳細
Google Gemini コードレビュースキル
Google の Gemini CLI と Gemini 2.5 Pro を使ってコードをレビューします。Gemini 2.5 Pro は、リポジトリ全体を一度に分析できる、圧倒的な 100 万トークンのコンテキストウィンドウを備えています。
ソース: Gemini CLI | コードレビュー拡張機能 | Gemini Code Assist | GitHub Action
コードレビューに Gemini を使う理由
| 機能 | メリット |
|---|---|
| Gemini 2.5 Pro | コードに対する最先端の推論能力 |
| 100 万トークンのコンテキスト | リポジトリ全体を扱えるため、分割は不要 |
| 無料枠 | Google アカウントで 1 日 1,000 件のリクエスト |
| 一貫した出力 | すっきりとした書式で、予測可能な構成 |
| GitHub とのネイティブ連携 | PR を自動レビューする Gemini Code Assist アプリ |
ベンチマーク性能
| ベンチマーク | スコア | 備考 |
|---|---|---|
| SWE-Bench Verified | 63.8% | エージェント型コーディングのベンチマーク |
| Qodo PR Benchmark | 56.3% | PR レビューの品質 |
| LiveCodeBench v5 | 70.4% | コード生成 |
| WebDev Arena | #1 | ウェブ開発 |
インストール
前提条件
# Check Node.js version (requires 20+)
node --version
# Install Node.js 20 if needed
# macOS
brew install node@20
# Or via nvm
nvm install 20
nvm use 20
Gemini CLI をインストールする
# Via npm (recommended)
npm install -g @google/gemini-cli
# Via Homebrew (macOS)
brew install gemini-cli
# Or run without installing
npx @google/gemini-cli
# Verify installation
gemini --version
コードレビュー拡張機能をインストールする
# Requires Gemini CLI v0.4.0+
gemini extensions install https://github.com/gemini-cli-extensions/code-review
# Verify extension
gemini extensions list
認証
オプション 1:Google アカウント(推奨)
無料枠:1 日あたり 1,000 件、1 分あたり 60 件のリクエスト
# Run gemini and follow browser login
gemini
# Select: "Login with Google Account"
# Opens browser for OAuth
これにより、100 万トークンのコンテキストウィンドウを最大限に活用して Gemini 2.5 Pro にアクセスできます。
オプション 2:Gemini API キー
無料枠:1 日あたり 100 件のリクエスト
# Get API key from https://aistudio.google.com/apikey
# Set environment variable
export GEMINI_API_KEY="your-api-key"
# Or add to shell profile
echo 'export GEMINI_API_KEY="your-api-key"' >> ~/.zshrc
# Run Gemini
gemini
オプション 3:Vertex AI(エンタープライズ)
# For Google Cloud projects
export GOOGLE_API_KEY="your-api-key"
export GOOGLE_GENAI_USE_VERTEXAI=true
export GOOGLE_CLOUD_PROJECT="your-project-id"
gemini
インタラクティブなコードレビュー
コードレビュー拡張機能を使う
# Start Gemini CLI
gemini
# Run code review on current branch
/code-review
拡張機能は次の内容を分析します:
- 現在のブランチのコード変更
- 品質上の問題の特定
- 修正案の提案
手動レビュー用プロンプト
# In interactive mode
gemini
# Then ask:
> Review the changes in this branch for bugs and security issues
> Analyze src/api/users.ts for potential vulnerabilities
> What are the code quality issues in the last 3 commits?
ヘッドレスモード(自動化)
基本的な使い方
# Simple prompt execution
gemini -p "Review the code changes for bugs and security issues"
# With JSON output (for parsing)
gemini -p "Review the changes" --output-format json
# Stream JSON events (real-time)
gemini -p "Review and fix issues" --output-format stream-json
# Specify model
gemini -m gemini-2.5-pro -p "Deep code review of this PR"
CI/CD の完全な例
# Get diff and review
git diff origin/main...HEAD > diff.txt
gemini -p "Review this code diff for:
1. Security vulnerabilities
2. Performance issues
3. Code quality problems
4. Missing error handling
Diff:
$(cat diff.txt)
" --output-format json > review.json
セッション追跡
# Track token usage and costs
gemini -p "Review changes" --session-summary metrics.json
# View metrics
cat metrics.json
GitHub 連携
オプション 1:Gemini Code Assist アプリ(最も簡単)
GitHub Marketplace からインストールします:
- GitHub Marketplace → Gemini Code Assist に移動します
- 「Install」をクリックし、リポジトリを選択します
- PR を開くと、自動的にレビューされます
PR コメントで使えるコマンド:
/gemini review # Request code review
/gemini summary # Get PR summary
/gemini help # Show available commands
利用上限:
- 無料:1 日あたり 33 件の PR
- エンタープライズ:1 日あたり 100 件以上の PR
オプション 2:GitHub Action
# .github/workflows/gemini-review.yml
name: Gemini Code Review
on:
pull_request:
types: [opened, synchronize]
jobs:
review:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Gemini CLI
run: npm install -g @google/gemini-cli
- name: Run Review
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
run: |
# Get diff
git diff origin/${{ github.base_ref }}...HEAD > diff.txt
# Run Gemini review
gemini -p "Review this pull request diff for bugs, security issues, and code quality problems. Be specific about file names and line numbers.
$(cat diff.txt)" > review.md
- name: Post Review Comment
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const review = fs.readFileSync('review.md', 'utf8');
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `## 🤖 Gemini Code Review\n\n${review}`
});
オプション 3:公式 GitHub Action
# .github/workflows/gemini-review.yml
name: Gemini Code Review
on:
pull_request:
types: [opened, synchronize]
issue_comment:
types: [created]
jobs:
review:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
issues: write
steps:
- uses: actions/checkout@v4
- name: Run Gemini CLI
uses: google-github-actions/run-gemini-cli@v1
with:
gemini_api_key: ${{ secrets.GEMINI_API_KEY }}
prompt: "Review this pull request for code quality, security issues, and potential bugs."
コメントで使えるオンデマンドコマンド:
@gemini-cli /review
@gemini-cli explain this code change
@gemini-cli write unit tests for this component
GitLab CI/CD
# .gitlab-ci.yml
gemini-review:
image: node:20
stage: review
script:
- npm install -g @google/gemini-cli
- |
gemini -p "Review the merge request changes for bugs, security issues, and code quality" > review.md
- cat review.md
artifacts:
paths:
- review.md
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
variables:
GEMINI_API_KEY: $GEMINI_API_KEY
設定
グローバル設定
# ~/.gemini/settings.json
{
"model": "gemini-2.5-pro",
"theme": "dark",
"sandbox": true
}
プロジェクト設定(GEMINI.md)
プロジェクト固有のコンテキストを設定するには、プロジェクトのルートに GEMINI.md ファイルを作成します:
# Project Context for Gemini
## Tech Stack
- TypeScript with strict mode
- React 18 with hooks
- FastAPI backend
- PostgreSQL database
## Code Review Focus Areas
1. Type safety - ensure proper TypeScript types
2. React hooks rules - check for dependency array issues
3. SQL injection - verify parameterized queries
4. Authentication - check all endpoints have proper auth
## Conventions
- Use camelCase for variables
- Use PascalCase for components
- All API errors should use AppError class
CLI クイックリファレンス
# Interactive
gemini # Start interactive mode
/code-review # Run code review extension
# Headless
gemini -p "prompt" # Single prompt, exit
gemini -p "prompt" --output-format json # JSON output
gemini -m gemini-2.5-flash -p "prompt" # Use faster model
# Extensions
gemini extensions list # List installed
gemini extensions install URL # Install extension
gemini extensions update # Update all
# Key Flags
--output-format json # Structured output
--output-format stream-json # Real-time events
--session-summary FILE # Track metrics
-m MODEL # Select model
比較:Claude、Codex、Gemini
| 項目 | Claude | Codex CLI | Gemini CLI |
|---|---|---|---|
| セットアップ | なし(組み込み) | npm + OpenAI API | npm + Google アカウント |
| モデル | Claude | GPT-5.2-Codex | Gemini 2.5 Pro |
| コンテキスト | 会話 | レビューごとに新規 | 100 万トークン(大容量!) |
| 無料枠 | 該当なし | 制限あり | 1 日あたり 1,000 件 |
| 最適な用途 | すばやいレビュー | 高精度 | 大規模なコードベース |
| GitHub とのネイティブ連携 | なし | @codex | Gemini Code Assist |
用途に応じた選び方
| シナリオ | 推奨エンジン |
|---|---|
| ワークフロー内ですばやくレビュー | Claude |
| 重要なセキュリティレビュー | Codex(検出率 88%) |
| 大規模なコードベース(100 ファイル以上) | Gemini(100 万トークンのコンテキスト) |
| 無料の自動レビュー | Gemini |
| 複数の視点からレビュー | 3 つすべて(2 種類/3 種類のエンジン) |
トラブルシューティング
| 問題 | 解決策 |
|---|---|
gemini: command not found | npm install -g @google/gemini-cli |
Node.js version error | Node.js 20+ にアップグレードします |
Authentication failed | gemini を再実行して、もう一度ログインします |
Extension not found | gemini extensions install https://github.com/gemini-cli-extensions/code-review |
Rate limited | 待つか、Vertex AI にアップグレードします |
Hangs in CI | DEBUG 環境変数が設定されていないことを確認します |
アンチパターン
- 認証設定を省略する - CI/CD の前に必ず設定します
- ログに API キーを記録する - シークレット管理を使用します
- コンテキストの上限を無視する - 1M トークンでも、大規模なモノレポでは上限に達します
- すべてのコミットで実行する - クォータを節約するため、PR のみで使用します
- プロジェクトのコンテキストを設定しない - レビューの質を高めるため、GEMINI.md を追加します
コメント
Markdown 対応