Skip to content

feat: add PR review fix workflow triggered by slash command - #14

Merged
Lin-Jiong-HDU merged 2 commits into
mainfrom
feat/issue-13-feat-add-review-fix-workflow-triggered-b
May 5, 2026
Merged

feat: add PR review fix workflow triggered by slash command#14
Lin-Jiong-HDU merged 2 commits into
mainfrom
feat/issue-13-feat-add-review-fix-workflow-triggered-b

Conversation

@Lin-Jiong-HDU

@Lin-Jiong-HDU Lin-Jiong-HDU commented May 4, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add PR Review auto-fix workflow to cgate: when a user comments /claude fix-review on a PR, cgate reads pending review comments, launches Claude Code to judge which ones need fixing, applies fixes, and pushes additional commits to the PR branch
  • Extend domain types with TaskType (issue/pr_review), PRNumber, CommentID for routing and duplicate prevention
  • Add idempotent SQLite migration for new columns, PR review entrypoint flow, prompt template, and sample GitHub Actions workflow

Closes #13

Changes

Domain Layer

  • domain/task.go: Add TaskType type with constants (TaskTypeIssue, TaskTypePRReview), add TaskType, PRNumber, CommentID fields to Task and WebhookPayload, update NewTask to route by TriggerType
  • domain/repository.go: Add FindActiveByPR method for duplicate prevention

Data Layer

  • repository/sqlite.go: Add idempotent migration (v2) for task_type, pr_number, comment_id columns with columnExists helper
  • repository/task_repository.go: Update all SQL queries for new columns, implement FindActiveByPR

Business Logic

  • usecase/task_usecase.go: Route HandleWebhook by trigger_type — issue flow uses FindActiveByIssue, PR review flow uses FindActiveByPR

Infrastructure

  • internal/docker/runner.go: Pass TASK_TYPE and PR_NUMBER env vars to container
  • runner-image/entrypoint.sh: Add run_pr_review function — checkout PR branch, fetch reviews/comments via gh api, assemble reviews.json, run Claude with PR review prompt, push fixes
  • runner-image/prompt-template-pr-review.txt: New prompt template for review fix instructions
  • runner-image/Dockerfile: Copy new prompt template

Workflow

  • .github/workflows/pr-review-webhook.yml: Sample workflow for issue_comment events on PRs with /claude fix-review command

Test plan

  • All existing tests pass (go vet, go build, go test ./...)
  • New domain tests: TestNewTask_PRReviewPayload verifies TaskType, PRNumber, CommentID
  • New repository tests: FindActiveByPR, FindActiveByPR_DoesNotReturnIssueTasks, PRReviewTask_RoundTrip
  • New usecase tests: PRReview_CreatesAndEnqueues, PRReview_RejectsDuplicateActive, PRReview_UnauthorizedAuthor, PRReview_IssueAndPRCanCoexist
  • Idempotent migration tested via TestInitDB_Idempotent
  • Note: golangci-lint has pre-existing version mismatch (built with Go 1.24, project targets Go 1.25)

🤖 Generated with Claude Code

…ix-review

Add support for a new task type (pr_review) that enables automated PR
review fixes. When a user comments /claude fix-review on a PR, cgate
fetches review comments, launches Claude Code to judge and fix valid
issues, then pushes commits to the PR branch.

Changes:
- Add TaskType (issue/pr_review), PRNumber, CommentID to domain types
- Extend WebhookPayload with trigger_type for routing
- Add FindActiveByPR to repository for duplicate prevention
- Add idempotent SQLite migration for new columns (task_type, pr_number, comment_id)
- Route HandleWebhook based on trigger_type (issue vs pr_review)
- Pass TASK_TYPE and PR_NUMBER env vars to container for PR review tasks
- Add PR review flow to entrypoint.sh (checkout PR branch, fetch reviews, push fixes)
- Add prompt-template-pr-review.txt for review fix instructions
- Add pr-review-webhook.yml sample workflow for target repos

Note: golangci-lint gate has pre-existing version mismatch (binary built
with Go 1.24, project targets Go 1.25). Gates 1-3 (vet, build, test) pass.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new “PR review auto-fix” task type and end-to-end workflow so cgate can be triggered by a /claude fix-review PR comment, then fetch review feedback, run Claude Code to apply fixes, and push commits back to the PR branch.

Changes:

  • Extend domain/task + repository interfaces to support TaskType (issue/pr_review) and PR-review-specific identifiers (PRNumber, CommentID) with duplicate prevention via FindActiveByPR.
  • Update SQLite schema/migration + repository SQL to persist/query new task fields and support PR-review active-task detection.
  • Add runner/container-side PR review flow (entrypoint + prompt template) and a sample GitHub Actions workflow to forward /claude fix-review comments to cgate.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
domain/task.go Adds TaskType + PR review fields and sets task type based on payload trigger_type.
domain/task_test.go Adds coverage for PR review payload → task construction and default issue task fields.
domain/repository.go Extends TaskRepository with FindActiveByPR.
usecase/task_usecase.go Routes duplicate-prevention check based on trigger_type and logs task type/PR.
usecase/task_usecase_test.go Adds usecase tests for PR review creation, duplicate rejection, and authorization.
repository/sqlite.go Adds new columns/indexes and an idempotent migration helper.
repository/task_repository.go Persists/loads new columns and implements FindActiveByPR.
repository/task_repository_test.go Adds PR-review roundtrip + active-task query tests.
internal/docker/runner.go Passes TASK_TYPE and PR_NUMBER env vars into runner containers.
runner-image/entrypoint.sh Adds PR review execution path: checkout PR branch, fetch review data, run Claude, push commits.
runner-image/prompt-template-pr-review.txt New prompt template instructing Claude on PR review auto-fix behavior and gates.
runner-image/Dockerfile Copies the new PR review prompt template into the image.
.github/workflows/pr-review-webhook.yml Sample workflow to POST webhook payload on /claude fix-review PR comments.

Comment thread runner-image/entrypoint.sh Outdated
Comment on lines +128 to +136
# Fetch all reviews
reviews_json=$(gh api "repos/${REPOSITORY}/pulls/${PR_NUMBER}/reviews" 2>/dev/null || echo '[]')

# Fetch all inline review comments
comments_json=$(gh api "repos/${REPOSITORY}/pulls/${PR_NUMBER}/comments" 2>/dev/null || echo '[]')

# Filter reviews: only CHANGES_REQUESTED and COMMENT types, ignore PENDING and APPROVED
# Filter comments: only unresolved ones
# Build combined review data
Comment thread domain/task.go
Comment on lines +66 to +69
taskType := TaskTypeIssue
if payload.TriggerType == "pr_review" {
taskType = TaskTypePRReview
}
Comment thread usecase/task_usecase.go
Comment on lines +50 to +52
if payload.TriggerType == "pr_review" {
active, err := u.repo.FindActiveByPR(ctx, payload.Repository, payload.PRNumber)
if err != nil {
Comment thread repository/sqlite.go Outdated
Comment on lines +58 to +76
exists, err := columnExists(db, "tasks", "task_type")
if err != nil {
return err
}
if exists {
return nil
}

alters := []string{
"ALTER TABLE tasks ADD COLUMN task_type TEXT NOT NULL DEFAULT 'issue'",
"ALTER TABLE tasks ADD COLUMN pr_number INTEGER DEFAULT 0",
"ALTER TABLE tasks ADD COLUMN comment_id INTEGER DEFAULT 0",
}
for _, stmt := range alters {
if _, err := db.Exec(stmt); err != nil {
return err
}
}
_, err = db.Exec("CREATE INDEX IF NOT EXISTS idx_tasks_repo_pr_type ON tasks(repository, pr_number, task_type)")
Comment thread runner-image/entrypoint.sh Outdated
Comment on lines 28 to 33
if [ "$TASK_TYPE" = "pr_review" ]; then
run_pr_review
else
run_issue
fi

- Move dispatch block after function definitions in entrypoint.sh
  (bash requires functions defined before invocation)
- Filter reviews by state (CHANGES_REQUESTED/COMMENTED) at fetch time
  using gh api --jq per issue #13 spec
- Make migrateV2 check each column independently to handle partial
  migration scenarios

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@Lin-Jiong-HDU
Lin-Jiong-HDU merged commit 8020e1c into main May 5, 2026
1 check passed
@Lin-Jiong-HDU
Lin-Jiong-HDU deleted the feat/issue-13-feat-add-review-fix-workflow-triggered-b branch May 5, 2026 07:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants