Skip to content

Commit c0b7f62

Browse files
Ambient Code Botclaude
andcommitted
feat: add CodeRabbit integration for AI-powered code review
Full-stack integration following the Jira pattern and PR #1307 conventions. Implements infrastructure for ADR-0008 (automated inner-loop review). Backend (Go): - Auth handlers: connect, status, disconnect, test (K8s Secret storage) - API key validation against CodeRabbit health API with error differentiation (401/403 = invalid key, 5xx = upstream error) - Runtime credential endpoint with RBAC for session pods - Unified integrations status includes CodeRabbit - 16 Ginkgo tests Frontend (Next.js + React): - Informational-first connection card: public repos free via GitHub App, API key collapsed under "Private repository access" with billing warning - API client layer + React Query hooks with dual cache invalidation - 4 Next.js proxy routes - Wired into IntegrationsClient grid and session integrations panel Runner (Python): - fetch_coderabbit_credentials via shared _fetch_credential helper - CODERABBIT_API_KEY injected into session env via asyncio.gather - Cleared on turn completion Pre-commit hook: - Runs coderabbit review --agent on staged changes - Supports both CODERABBIT_API_KEY env and cr auth login session - CLI reads env var directly (no --api-key in process listing) - Skips gracefully when CLI/auth/changes unavailable CI + Testing: - GHA smoke test: validates config, runs live review, tests hook behavior (actions pinned to SHAs, permissions scoped) - Integration test script: 9/9 passing against dev cluster Docs: - Starlight guide: public vs private repos, local dev, session flow - ADR-0008: automated code reviews via inner-loop + Mergify - PR #1307 impact analysis Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4c8486e commit c0b7f62

File tree

27 files changed

+2151
-17
lines changed

27 files changed

+2151
-17
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
name: CodeRabbit Integration Smoke Test
2+
3+
# Validates the CodeRabbit integration works end-to-end:
4+
# - CLI installs and authenticates
5+
# - Can review files against the real CodeRabbit API
6+
# - Config file (.coderabbit.yaml) is valid
7+
8+
on:
9+
pull_request:
10+
branches: [main]
11+
paths:
12+
- '.coderabbit.yaml'
13+
- 'components/backend/handlers/coderabbit_auth.go'
14+
- 'components/backend/handlers/integration_validation.go'
15+
- 'components/frontend/src/components/coderabbit-connection-card.tsx'
16+
- 'components/runners/ambient-runner/ambient_runner/platform/auth.py'
17+
- 'scripts/pre-commit/coderabbit-review.sh'
18+
- '.github/workflows/coderabbit-smoke-test.yml'
19+
20+
workflow_dispatch:
21+
22+
schedule:
23+
- cron: '0 6 * * 1' # Weekly Monday 6am UTC
24+
25+
permissions:
26+
contents: read
27+
28+
concurrency:
29+
group: coderabbit-smoke-${{ github.event.pull_request.number || github.ref }}
30+
cancel-in-progress: true
31+
32+
jobs:
33+
smoke-test:
34+
name: CodeRabbit Smoke Test
35+
runs-on: ubuntu-latest
36+
timeout-minutes: 10
37+
38+
steps:
39+
- name: Checkout code
40+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
41+
42+
- name: Set up Node.js
43+
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
44+
with:
45+
node-version: '20'
46+
47+
- name: Install CodeRabbit CLI
48+
run: npm install -g coderabbit
49+
50+
- name: Verify CLI installed
51+
run: |
52+
coderabbit --version
53+
echo "CLI binary: $(which coderabbit)"
54+
55+
- name: Validate .coderabbit.yaml schema
56+
run: |
57+
echo "=== Validating .coderabbit.yaml ==="
58+
python3 -c "
59+
import yaml, sys
60+
with open('.coderabbit.yaml') as f:
61+
config = yaml.safe_load(f)
62+
assert 'reviews' in config, 'Missing reviews section'
63+
assert 'language' in config, 'Missing language field'
64+
print(f'Config valid: {len(config)} top-level keys')
65+
print(f'Reviews profile: {config[\"reviews\"].get(\"profile\", \"not set\")}')
66+
print(f'Auto review: {config[\"reviews\"].get(\"auto_review\", {}).get(\"enabled\", False)}')
67+
print(f'Tools configured: {len(config[\"reviews\"].get(\"tools\", {}))}')
68+
"
69+
echo "PASSED: .coderabbit.yaml is valid"
70+
71+
- name: Run CodeRabbit review on config file
72+
env:
73+
CODERABBIT_API_KEY: ${{ secrets.CODERABBIT_API_KEY }}
74+
run: |
75+
echo "=== Running CodeRabbit review against real API ==="
76+
77+
# Skip if no API key (fork PRs, missing secret)
78+
if [ -z "$CODERABBIT_API_KEY" ]; then
79+
echo "CODERABBIT_API_KEY not set - skipping live review"
80+
echo "This is expected for fork PRs or when the secret is not configured"
81+
exit 0
82+
fi
83+
84+
# Review the config file itself using agent mode for structured output
85+
EXIT_CODE=0
86+
OUTPUT=$(coderabbit review \
87+
--agent \
88+
--files .coderabbit.yaml \
89+
--api-key "$CODERABBIT_API_KEY" \
90+
2>&1) || EXIT_CODE=$?
91+
92+
echo "$OUTPUT"
93+
94+
# Auth errors are fatal
95+
if echo "$OUTPUT" | grep -qiE "unauthorized|forbidden|invalid.*key"; then
96+
echo "FAILED: CodeRabbit API key appears invalid"
97+
exit 1
98+
fi
99+
100+
# Non-zero exit from CLI is a real failure
101+
if [ "$EXIT_CODE" -ne 0 ]; then
102+
echo "FAILED: coderabbit review exited $EXIT_CODE"
103+
exit 1
104+
fi
105+
106+
echo "PASSED: CodeRabbit API responded successfully"
107+
108+
- name: Verify pre-commit hook skips gracefully
109+
run: |
110+
echo "=== Testing pre-commit hook graceful skip ==="
111+
unset CODERABBIT_API_KEY
112+
113+
chmod +x scripts/pre-commit/coderabbit-review.sh
114+
OUTPUT=$(scripts/pre-commit/coderabbit-review.sh 2>&1)
115+
EXIT_CODE=$?
116+
117+
echo "$OUTPUT"
118+
119+
if [ "$EXIT_CODE" -ne 0 ]; then
120+
echo "FAILED: Hook should exit 0 when skipping"
121+
exit 1
122+
fi
123+
124+
if ! echo "$OUTPUT" | grep -qiE "not found|not set|skipping"; then
125+
echo "FAILED: Hook should print a skip message"
126+
exit 1
127+
fi
128+
129+
echo "PASSED: Pre-commit hook skips gracefully"

.pre-commit-config.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ repos:
6363
files: ^components/frontend/.*\.(ts|tsx|js|jsx)$
6464
pass_filenames: true
6565

66+
# ── CodeRabbit review ──────────────────────────────────────────────────
67+
- repo: local
68+
hooks:
69+
- id: coderabbit-review
70+
name: coderabbit review
71+
entry: scripts/pre-commit/coderabbit-review.sh
72+
language: script
73+
always_run: true
74+
pass_filenames: false
75+
stages: [pre-commit]
76+
6677
# ── Branch protection ────────────────────────────────────────────────
6778
- repo: local
6879
hooks:

0 commit comments

Comments
 (0)