Summary
Add a PR Review auto-fix workflow to cgate. When a user comments /claude fix-review on a PR, cgate reads all pending review comments, launches Claude Code to judge which ones need fixing, applies fixes, and pushes additional commits to the same branch.
Requirements
1. Trigger Chain
New GitHub Actions Workflow pr-review-webhook.yml for target repos:
- Listen on
issue_comment events (PR comments are issue_comment type)
- Filter conditions:
- PR is open (
github.event.issue.pull_request exists)
- Comment body starts with
/claude fix-review
- Comment author has write access (owner / collaborator / member)
- Forward to cgate
POST /webhook/github endpoint
- Payload must include:
trigger_type: "pr_review", pr_number, comment_id, repository, etc.
- Provide a sample workflow file under
workflows/ or runner-image/ for reference
Webhook Payload Extension:
Add fields to WebhookPayload in domain/task.go:
Action string `json:"action"` // "opened" (issue) / "created" (comment)
TriggerType string `json:"trigger_type"` // "issue" / "pr_review"
PRNumber int `json:"pr_number"` // PR number (set for PR Review tasks)
CommentID int64 `json:"comment_id"` // Triggering comment ID
2. Server-Side Processing (Go)
Task Type Extension:
Add TaskType to domain/task.go:
type TaskType string
const (
TaskTypeIssue TaskType = "issue"
TaskTypePRReview TaskType = "pr_review"
)
Add fields to Task entity:
TaskType TaskType `json:"task_type"`
PRNumber int `json:"pr_number,omitempty"`
CommentID int64 `json:"comment_id,omitempty"`
Webhook Controller (api/controller/webhook_controller.go):
- Route based on payload
trigger_type
issue: existing Issue flow (unchanged)
pr_review: create a TaskTypePRReview task and enqueue it
HandleWebhook (usecase) (usecase/task_usecase.go):
- Extend to support
pr_review type
- Validate PR is still open
- Create Task with
TaskType: TaskTypePRReview, PRNumber, and CommentID
- Reuse existing
scheduleLoop and watchContainer — no changes to scheduling logic
Docker Runner (internal/docker/runner.go):
- Pass different env vars based on Task
TaskType
- PR Review type passes extra env:
TASK_TYPE=pr_review, PR_NUMBER=<number>
- Reuse existing container create/start/log stream/cleanup logic
Duplicate Prevention:
- Reject new
pr_review task creation if the same PR already has a running pr_review task
- Reuse existing
hasActiveTask check logic, add task_type filtering
3. Container-Side Processing (runner-image/entrypoint.sh)
When TASK_TYPE=pr_review, execute new branch logic:
gh pr view $PR_NUMBER --json headRefName to get PR branch name
git fetch origin <branch> && git checkout <branch> to switch to PR branch
gh api repos/{owner}/{repo}/pulls/{PR_NUMBER}/reviews to get all reviews
gh api repos/{owner}/{repo}/pulls/{PR_NUMBER}/comments to get all inline review comments
- Assemble review content (author, state, body, file path, line number) into
/workspace/reviews.json
- Generate prompt using
runner-image/prompt-template-pr-review.txt template
- Run
claude -p "<prompt>" to let Claude Code judge and fix
- After fixes:
git push to same branch (append commits, no force push)
Review Filtering:
- Only process
CHANGES_REQUESTED and COMMENT type reviews
- Ignore
PENDING and APPROVED reviews
- Only process unresolved review comments
4. Prompt Template
Create runner-image/prompt-template-pr-review.txt with core instructions:
- Read review comments from
/workspace/reviews.json
- Must follow all coding standards and workflow protocols in the project root
CLAUDE.md
- For each comment: judge whether it is a valid code issue (ignore pure style preferences, subjective opinions)
- Only fix comments that genuinely need changes
- Each fix gets an independent commit, message format:
fix(review): address review comment on <file>
- Do not modify code unrelated to reviews
- After fixing, run pipeline gates (
go vet, go build, go test, golangci-lint run)
- If a gate fails, follow the Debug Protocol to fix
5. Database Migration
Add task_type, pr_number, comment_id columns to SQLite tasks table. Existing records default to task_type = 'issue'.
6. API Changes
- Task list/detail API responses include new fields:
task_type, pr_number
- No new endpoints needed
Technical Constraints
- Go 1.24+, stdlib only (except existing dependencies)
- No new third-party dependencies
- Follow project Clean Architecture: domain -> usecase -> repository/runner
- Follow all coding standards in CLAUDE.md
- All pipeline gates must pass:
go vet -> go build -> go test -> golangci-lint run
Acceptance Criteria
- Commenting
/claude fix-review on a PR triggers cgate to create a pr_review type Task
- Container correctly clones the PR branch and fetches review comments
- Claude Code reads reviews and intelligently judges which need fixing
- Fixes are pushed as additional commits to the PR branch
- Duplicate
running tasks are prevented for the same PR
- All existing tests pass; new functionality has corresponding tests
- A sample
pr-review-webhook.yml workflow file is provided
Summary
Add a PR Review auto-fix workflow to cgate. When a user comments
/claude fix-reviewon a PR, cgate reads all pending review comments, launches Claude Code to judge which ones need fixing, applies fixes, and pushes additional commits to the same branch.Requirements
1. Trigger Chain
New GitHub Actions Workflow
pr-review-webhook.ymlfor target repos:issue_commentevents (PR comments areissue_commenttype)github.event.issue.pull_requestexists)/claude fix-reviewPOST /webhook/githubendpointtrigger_type: "pr_review",pr_number,comment_id,repository, etc.workflows/orrunner-image/for referenceWebhook Payload Extension:
Add fields to
WebhookPayloadindomain/task.go:2. Server-Side Processing (Go)
Task Type Extension:
Add
TaskTypetodomain/task.go:Add fields to Task entity:
Webhook Controller (
api/controller/webhook_controller.go):trigger_typeissue: existing Issue flow (unchanged)pr_review: create aTaskTypePRReviewtask and enqueue itHandleWebhook (usecase) (
usecase/task_usecase.go):pr_reviewtypeTaskType: TaskTypePRReview,PRNumber, andCommentIDscheduleLoopandwatchContainer— no changes to scheduling logicDocker Runner (
internal/docker/runner.go):TaskTypeTASK_TYPE=pr_review,PR_NUMBER=<number>Duplicate Prevention:
pr_reviewtask creation if the same PR already has arunningpr_reviewtaskhasActiveTaskcheck logic, addtask_typefiltering3. Container-Side Processing (runner-image/entrypoint.sh)
When
TASK_TYPE=pr_review, execute new branch logic:gh pr view $PR_NUMBER --json headRefNameto get PR branch namegit fetch origin <branch> && git checkout <branch>to switch to PR branchgh api repos/{owner}/{repo}/pulls/{PR_NUMBER}/reviewsto get all reviewsgh api repos/{owner}/{repo}/pulls/{PR_NUMBER}/commentsto get all inline review comments/workspace/reviews.jsonrunner-image/prompt-template-pr-review.txttemplateclaude -p "<prompt>"to let Claude Code judge and fixgit pushto same branch (append commits, no force push)Review Filtering:
CHANGES_REQUESTEDandCOMMENTtype reviewsPENDINGandAPPROVEDreviews4. Prompt Template
Create
runner-image/prompt-template-pr-review.txtwith core instructions:/workspace/reviews.jsonCLAUDE.mdfix(review): address review comment on <file>go vet,go build,go test,golangci-lint run)5. Database Migration
Add
task_type,pr_number,comment_idcolumns to SQLite tasks table. Existing records default totask_type = 'issue'.6. API Changes
task_type,pr_numberTechnical Constraints
go vet->go build->go test->golangci-lint runAcceptance Criteria
/claude fix-reviewon a PR triggers cgate to create apr_reviewtype Taskrunningtasks are prevented for the same PRpr-review-webhook.ymlworkflow file is provided