feat: add PR review fix workflow triggered by slash command - #14
Merged
Lin-Jiong-HDU merged 2 commits intoMay 5, 2026
Merged
Conversation
…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>
There was a problem hiding this comment.
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 viaFindActiveByPR. - 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-reviewcomments 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 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 on lines
+66
to
+69
| taskType := TaskTypeIssue | ||
| if payload.TriggerType == "pr_review" { | ||
| taskType = TaskTypePRReview | ||
| } |
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 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 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
deleted the
feat/issue-13-feat-add-review-fix-workflow-triggered-b
branch
May 5, 2026 07:02
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/claude fix-reviewon 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 branchTaskType(issue/pr_review),PRNumber,CommentIDfor routing and duplicate preventionCloses #13
Changes
Domain Layer
domain/task.go: AddTaskTypetype with constants (TaskTypeIssue,TaskTypePRReview), addTaskType,PRNumber,CommentIDfields toTaskandWebhookPayload, updateNewTaskto route byTriggerTypedomain/repository.go: AddFindActiveByPRmethod for duplicate preventionData Layer
repository/sqlite.go: Add idempotent migration (v2) fortask_type,pr_number,comment_idcolumns withcolumnExistshelperrepository/task_repository.go: Update all SQL queries for new columns, implementFindActiveByPRBusiness Logic
usecase/task_usecase.go: RouteHandleWebhookbytrigger_type— issue flow usesFindActiveByIssue, PR review flow usesFindActiveByPRInfrastructure
internal/docker/runner.go: PassTASK_TYPEandPR_NUMBERenv vars to containerrunner-image/entrypoint.sh: Addrun_pr_reviewfunction — checkout PR branch, fetch reviews/comments viagh api, assemblereviews.json, run Claude with PR review prompt, push fixesrunner-image/prompt-template-pr-review.txt: New prompt template for review fix instructionsrunner-image/Dockerfile: Copy new prompt templateWorkflow
.github/workflows/pr-review-webhook.yml: Sample workflow forissue_commentevents on PRs with/claude fix-reviewcommandTest plan
go vet,go build,go test ./...)TestNewTask_PRReviewPayloadverifiesTaskType,PRNumber,CommentIDFindActiveByPR,FindActiveByPR_DoesNotReturnIssueTasks,PRReviewTask_RoundTripPRReview_CreatesAndEnqueues,PRReview_RejectsDuplicateActive,PRReview_UnauthorizedAuthor,PRReview_IssueAndPRCanCoexistTestInitDB_Idempotentgolangci-linthas pre-existing version mismatch (built with Go 1.24, project targets Go 1.25)🤖 Generated with Claude Code