이 튜토리얼은 GitHub Actions에서 Cursor CLI로 코드 리뷰를 설정하는 방법을 보여줘. 이 워크플로는 pull request를 분석하고, 문제를 찾아내며, 댓글로 피드백을 남겨.
대부분의 사용자에겐 Bugbot을 쓰길 추천해. Bugbot은 설정 없이 관리형 자동 코드 리뷰를 제공해. 이 CLI 방식은 기능을 탐색하거나 고급 커스터마이즈에 유용해.
풀 리퀘스트에서 인라인 댓글이 달리는 자동 코드 리뷰

인증 구성

GitHub Actions에서 Cursor CLI를 인증하려면 API 키와 리포지토리 시크릿을 설정해.

에이전트 권한 설정

에이전트가 할 수 있는 작업을 제어하는 설정 파일을 만들어. 이렇게 하면 코드 푸시나 풀 리퀘스트 생성 같은 의도치 않은 작업을 막을 수 있어. 리포지토리 루트에 .cursor/cli.json을 만들어:
{
  "permissions": {
    "deny": [
      "Shell(git push)",
      "Shell(gh pr create)",
      "Write(**)"
    ]
  }
}
이 설정은 에이전트가 파일을 읽고 GitHub CLI로 댓글을 남길 순 있지만, 리포지토리에 변경을 가하는 건 막아. 더 많은 설정 옵션은 permissions reference를 확인해.

GitHub Actions 워크플로우 빌드하기

이제 워크플로우를 단계별로 만들어 보자.

워크플로우 트리거 설정

.github/workflows/cursor-code-review.yml을 만들고 pull request에서 실행되도록 설정해:
name: Cursor Code Review

on:
  pull_request:
    types: [opened, synchronize, reopened, ready_for_review]

jobs:
  code-review:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write
    
    steps:

리포지토리 체크아웃

pull request 코드를 가져오려면 체크아웃 단계를 추가해:
- name: Checkout repository
  uses: actions/checkout@v4
  with:
    fetch-depth: 0
    ref: ${{ github.event.pull_request.head.sha }}

Cursor CLI 설치

CLI 설치 단계를 추가해:
- name: Install Cursor CLI
  run: |
    curl https://cursor.com/install -fsS | bash
    echo "$HOME/.cursor/bin" >> $GITHUB_PATH

리뷰 에이전트 구성

전체 리뷰 단계를 구현하기 전에, 리뷰 프롬프트의 구성 요소를 이해하자. 이 섹션은 에이전트가 어떻게 동작하길 원하는지 설명해: Objective: 에이전트가 현재 PR diff를 검토하고 명확하고 심각도가 높은 이슈만 표시한 다음, 변경된 라인에만 매우 짧은 인라인 코멘트(1~2문장)를 남기고 마지막에 간단한 요약을 남기길 원해. 이렇게 하면 신호 대 잡음 비율을 적절히 유지할 수 있어. Format: 코멘트는 짧고 핵심만 담아야 해. 코멘트를 빠르게 스캔할 수 있도록 이모지를 사용하고, 마지막에 전체 리뷰에 대한 하이레벨 요약이 있으면 좋아. Submission: 리뷰가 끝나면, 리뷰 중 발견한 내용을 바탕으로 짧은 코멘트를 포함해 줘. 에이전트는 인라인 코멘트와 간결한 요약을 포함하는 하나의 리뷰만 제출해야 해. Edge cases: 다음 상황을 처리해야 해:
  • 기존 코멘트가 해결됨: 해결된 경우 에이전트가 완료로 표시해야 함
  • 중복 방지: 동일하거나 유사한 피드백이 같은 줄 또는 인근 줄에 이미 있으면 코멘트를 남기지 말아야 함
Final prompt: 완전한 프롬프트는 이러한 모든 동작 요구사항을 결합해 집중적이고 실행 가능한 피드백을 만들어 이제 리뷰 에이전트 단계를 구현해 보자:
- name: Perform code review
  env:
    CURSOR_API_KEY: ${{ secrets.CURSOR_API_KEY }}
    GH_TOKEN: ${{ github.token }}
  run: |
    cursor-agent --force --model "$MODEL" --output-format=text --print "You are operating in a GitHub Actions runner performing automated code review. The gh CLI is available and authenticated via GH_TOKEN. You may comment on pull requests.
    
    Context:
    - Repo: ${{ github.repository }}
    - PR Number: ${{ github.event.pull_request.number }}
    - PR Head SHA: ${{ github.event.pull_request.head.sha }}
    - PR Base SHA: ${{ github.event.pull_request.base.sha }}
    
    Objectives:
    1) Re-check existing review comments and reply resolved when addressed
    2) Review the current PR diff and flag only clear, high-severity issues
    3) Leave very short inline comments (1-2 sentences) on changed lines only and a brief summary at the end
    
    Procedure:
    - Get existing comments: gh pr view --json comments
    - Get diff: gh pr diff
    - If a previously reported issue appears fixed by nearby changes, reply: ✅ This issue appears to be resolved by the recent changes
    - Avoid duplicates: skip if similar feedback already exists on or near the same lines
    
    Commenting rules:
    - Max 10 inline comments total; prioritize the most critical issues
    - One issue per comment; place on the exact changed line
    - Natural tone, specific and actionable; do not mention automated or high-confidence
    - Use emojis: 🚨 Critical 🔒 Security ⚡ Performance ⚠️ Logic ✅ Resolved ✨ Improvement
    
    Submission:
    - Submit one review containing inline comments plus a concise summary
    - Use only: gh pr review --comment
    - Do not use: gh pr review --approve or --request-changes"
.
├── .cursor/
│   └── cli.json
├── .github/
│   └── workflows/
│       └── cursor-code-review.yml

리뷰어를 테스트해봐

워크플로가 제대로 돌아가고 에이전트가 이모지 피드백과 함께 리뷰 댓글을 남기는지 확인하려면 테스트 풀 리퀘스트를 만들어봐.
특정 줄에 대한 이모지와 인라인 피드백이 포함된 자동 리뷰 댓글을 보여주는 풀 리퀘스트

다음 단계

이제 자동화된 코드 리뷰 시스템이 잘 돌아가. 다음 개선을 고려해봐:
  • CI 실패 수정을 위한 추가 워크플로 설정
  • 브랜치별로 서로 다른 리뷰 레벨 구성
  • 팀의 기존 코드 리뷰 프로세스와 통합
  • 파일 유형이나 디렉터리별로 에이전트 동작 사용자화