Skip to content

feat: add PR review fix workflow triggered by slash command [claude bot] #12

Description

@Lin-Jiong-HDU

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:

  1. gh pr view $PR_NUMBER --json headRefName to get PR branch name
  2. git fetch origin <branch> && git checkout <branch> to switch to PR branch
  3. gh api repos/{owner}/{repo}/pulls/{PR_NUMBER}/reviews to get all reviews
  4. gh api repos/{owner}/{repo}/pulls/{PR_NUMBER}/comments to get all inline review comments
  5. Assemble review content (author, state, body, file path, line number) into /workspace/reviews.json
  6. Generate prompt using runner-image/prompt-template-pr-review.txt template
  7. Run claude -p "<prompt>" to let Claude Code judge and fix
  8. 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

  1. Commenting /claude fix-review on a PR triggers cgate to create a pr_review type Task
  2. Container correctly clones the PR branch and fetches review comments
  3. Claude Code reads reviews and intelligently judges which need fixing
  4. Fixes are pushed as additional commits to the PR branch
  5. Duplicate running tasks are prevented for the same PR
  6. All existing tests pass; new functionality has corresponding tests
  7. A sample pr-review-webhook.yml workflow file is provided

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions