ai-startup
CHAPTER 44 / 100
읽기 약 2분
FUNCTION
AI 코드 리뷰: GitHub PR 자동 리뷰
핵심 개념
PR webhook·diff 분석·LLM 리뷰·자동 코멘트 — 코드 품질 자동 향상.
본문
GitHub App 셋업
// 1. GitHub App 생성
// https://github.com/settings/apps/new
// Permissions: pull_requests (read+write), contents (read)
// Events: pull_request, pull_request_review
// 2. webhook URL 등록
// https://yourservice.com/webhooks/github
// 3. App 설치 (각 repo에)PR 이벤트 처리
// app/api/webhooks/github/route.ts
import { Webhooks } from '@octokit/webhooks';
const webhooks = new Webhooks({ secret: process.env.GITHUB_WEBHOOK_SECRET! });
webhooks.on('pull_request.opened', async ({ payload }) => {
await reviewPR(payload);
});
webhooks.on('pull_request.synchronize', async ({ payload }) => {
await reviewPR(payload);
});
export async function POST(req: Request) {
const body = await req.text();
const signature = req.headers.get('x-hub-signature-256')!;
await webhooks.verifyAndReceive({
id: req.headers.get('x-github-delivery')!,
name: req.headers.get('x-github-event')! as any,
payload: body,
signature,
});
return new Response('OK');
}PR diff 가져오기
import { Octokit } from '@octokit/rest';
async function reviewPR(payload: any) {
const { pull_request: pr, repository: repo, installation } = payload;
const octokit = await getInstallationOctokit(installation.id);
// diff 가져오기
const { data: diff } = await octokit.pulls.get({
owner: repo.owner.login,
repo: repo.name,
pull_number: pr.number,
mediaType: { format: 'diff' },
});
// 변경된 파일들
const { data: files } = await octokit.pulls.listFiles({
owner: repo.owner.login,
repo: repo.name,
pull_number: pr.number,
});
return analyzeAndComment(octokit, repo, pr, files, diff as unknown as string);
}LLM 코드 리뷰
async function analyzeFile(file: any, octokit: any, owner: string, repo: string, prNumber: number) {
const result = await generateObject({
model: anthropic('claude-sonnet-4-6'),
schema: z.object({
summary: z.string(),
comments: z.array(z.object({
line: z.number(),
severity: z.enum(['nit', 'suggestion', 'issue', 'critical']),
message: z.string(),
})),
overallAssessment: z.enum(['approve', 'request_changes', 'comment']),
}),
system: `You are a senior engineer doing code review.
Focus on:
- Bugs and edge cases
- Security issues
- Performance problems
- Type safety
- Error handling
- Test coverage
Don't comment on:
- Pure formatting (if linter exists)
- Personal style preferences
- Things already mentioned by other tools`,
prompt: `Review this file:
File: ${file.filename}
Language: ${file.filename.split('.').pop()}
Diff:
${file.patch}
Provide line-specific comments. Use line numbers from the new file.`,
});
// PR에 review 코멘트 작성
for (const comment of result.object.comments) {
await octokit.pulls.createReviewComment({
owner, repo, pull_number: prNumber,
body: `**${comment.severity.toUpperCase()}**: ${comment.message}`,
commit_id: pr.head.sha,
path: file.filename,
line: comment.line,
side: 'RIGHT',
});
}
return result.object;
}종합 리뷰 코멘트
async function postSummary(octokit: any, owner: string, repo: string, prNumber: number, fileReviews: any[]) {
const result = await generateText({
model: anthropic('claude-sonnet-4-6'),
prompt: `Synthesize these file reviews into a PR-level summary:
${fileReviews.map(r => `## ${r.file}\n${r.summary}`).join('\n\n')}
Provide:
1. Top 3 concerns
2. Estimated review priority (low/medium/high)
3. Test recommendations
4. Overall: approve / changes requested`,
});
await octokit.issues.createComment({
owner, repo, issue_number: prNumber,
body: `## 🤖 AI Review\n\n${result.text}`,
});
}비용 + ROI
PR당 비용:
- 평균 500 lines 변경
- ~10K input tokens + 5K output tokens
- Claude Sonnet: $0.10 per PR
비교:
- 사람 시니어 리뷰: 30분 × $100/시간 = $50
→ AI 리뷰 = 1/500 비용
→ 보조 도구 (사람 검토 전 1차)통합 — 다른 도구
[CodeRabbit] (유료 SaaS)
- 즉시 사용
- 무료 plan 있음
[Aider] (오픈소스)
- 자체 구현
- 자유도 높음
[자체 — 본 챕터 코드]
- 완전 커스텀
- 도메인 특화 룰다음 챕터
CH.45 "AI 데이터 분석".
AI 프롬프트
🤖 AI에게 잘 물어보는 법 — 모델·전략별 프롬프트
무료
월 $0 — 검증·시작 단계
AI 코드 리뷰을 무료 도구만으로 시작하는 방법을 알려줘.
소자본
월 $20~50 — MVP·초기 운영
월 $20~50 예산으로 AI 코드 리뷰을 검증·MVP 단계까지 진행하는 전략은?
프로덕션
월 $200~500 — 성장 단계
AI 코드 리뷰을 프로덕션 단계로 확장할 때 필요한 도구·운영 체계는?
스택
풀스택 — 도구 조합 분석
2026년 AI 코드 리뷰 관련 도구 5개를 조합한 추천 스택을 알려줘.
⭐ 이것만 기억하세요
AI 코드 리뷰: GitHub PR 자동 리뷰는 이 3가지만 확실히 잡으세요
1.GitHub Webhook + LLM = PR마다 자동 리뷰
2.AI 리뷰 = 1차 (보조), 사람 시니어 = 최종
3.PR당 $0.10 vs 사람 $50 = 500배 절감
공유하기
진행도 44 / 100