Fix PR Review Issues
Address feedback from PR review comments, make necessary code changes, and update the pull request.
Repository Configuration
- Project: Program Unify
- Repository ID: d3fa6f02-bfdf-428d-825c-7e7bd4e7f338
- Repository Name: unify_2_1_dm_synapse_env_d10
What This Does
- Retrieves PR details and all active review comments
- Analyzes review feedback and identifies required changes
- Makes code changes to address each review comment
- Commits changes with descriptive message
- Pushes to feature branch (automatically updates PR)
- Replies to review threads confirming fixes
- Resolves review threads when appropriate
Implementation Logic
1. Get PR Information
- Use `mcp__ado__repo_get_pull_request_by_id` with PR_ID from `$ARGUMENTS`
- Extract source branch, target branch, and PR title
- Validate PR is still active
2. Retrieve Review Comments
- Use `mcp__ado__repo_list_pull_request_threads` to get all threads
- Filter for active threads (status = "Active")
- For each thread, use `mcp__ado__repo_list_pull_request_thread_comments` to get details
- Display all review comments with:
- File path and line number
- Reviewer name
- Comment content
- Thread ID (for later replies)
3. Checkout Feature Branch
```bash
git fetch origin
git checkout <source-branch-name>
git pull origin <source-branch-name>
```
4. Address Each Review Comment
Categorise review comments first:
Standard Code Quality Issues
Handle directly with Edit tool for:
- Type hints
- Line length violations
- Formatting issues
- Missing decorators
- Import organization
- Variable naming
Implementation:
- Read affected file using Read tool
- Analyze the feedback and determine required changes
- Make code changes using Edit tool
- Validate changes meet project standards
Complex PySpark Issues
Use pyspark-engineer agent for:
- Performance optimisation requests
- Partitioning strategy changes
- Shuffle optimisation
- Broadcast join refactoring
- Memory management improvements
- Medallion architecture violations
- Complex transformation logic
Trigger criteria:
- Review comment mentions: "performance", "optimisation", "partitioning", "shuffle", "memory", "medallion", "bronze/silver/gold layer"
- Files affected in: `python_files/pipeline_operations/`, `python_files/silver/`, `python_files/gold/`, `python_files/utilities/session_optimiser.py`
Use Task tool to launch pyspark-engineer agent:
```
Task tool parameters:
-
subagent_type: "pyspark-engineer"
-
description: "Implement PySpark fixes for PR #[PR_ID]"
-
prompt: "
Address PySpark review feedback for PR #[PR_ID]:
Review Comment Details:
[For each PySpark-related comment, include:]
- File: [FILE_PATH]
- Line: [LINE_NUMBER]
- Reviewer Feedback: [COMMENT_TEXT]
- Thread ID: [THREAD_ID]
Implementation Requirements:
- Read all affected files
- Implement fixes following these standards:
- Maximum line length: 240 characters
- No blank lines inside functions
- Proper type hints for all functions
- Use @synapse_error_print_handler decorator
- PySpark DataFrame operations (not SQL)
- Suffix _sdf for all DataFrames
- Follow medallion architecture patterns
- Optimize for:
- Performance and cost-efficiency
- Data skew handling
- Memory management
- Proper partitioning strategies
- Ensure production readiness:
- Error handling
- Logging with NotebookLogger
- Idempotent operations
- Run quality gates:
- Syntax validation: python3 -m py_compile
- Linting: ruff check python_files/
- Formatting: ruff format python_files/
Return:
- List of files modified
- Summary of changes made
- Explanation of how each review comment was addressed
- Any additional optimisations implemented
"
```
Integration:
- pyspark-engineer will read, modify, and validate files
- Agent will run quality gates automatically
- You will receive summary of changes
- Use summary for commit message and review replies
Validation for All Changes
Regardless of method (direct Edit or pyspark-engineer agent):
- Maximum line length: 240 characters
- No blank lines inside functions
- Proper type hints
- Use of `@synapse_error_print_handler` decorator
- PySpark best practices from `.claude/rules/python_rules.md`
- Document all fixes for commit message
5. Validate Changes
Run quality gates:
```bash
Syntax check
python3 -m py_compile <changed-file>
Linting
ruff check python_files/
Format
ruff format python_files/
```
6. Commit and Push
```bash
git add .
git commit -m "♻️ refactor: address PR review feedback - <brief-summary>"
git push origin <source-branch>
```
Commit Message Format:
```
♻️ refactor: address PR review feedback
Fixes applied:
- <file1>: <description of fix>
- <file2>: <description of fix>
- ...
Review comments addressed in PR #<PR_ID>
```
7. Reply to Review Threads
For each addressed comment:
8. Report Results
Provide summary:
```
PR Review Fixes Completed
PR: #<PR_ID> - <PR_Title>
Branch: <source-branch> → <target-branch>
Review Comments Addressed: <count>
Files Modified: <file-list>
Commit SHA: <sha>
Quality Gates:
✓ Syntax validation passed
✓ Linting passed
✓ Code formatting applied
The PR has been updated and is ready for re-review.
```
Error Handling
No PR ID Provided
If `$ARGUMENTS` is empty:
- Use `mcp__ado__repo_list_pull_requests_by_repo_or_project` to list open PRs
- Display all PRs created by current user
- Prompt user to specify PR ID
No Active Review Comments
If no active review threads found:
```
No active review comments found for PR #<PR_ID>.
The PR may already be approved or have no feedback requiring changes.
Would you like me to re-run /pr-review to check current status?
```
Merge Conflicts
If `git pull` results in merge conflicts:
- Display conflict files
- Guide user through resolution:
- Show conflicting sections
- Suggest resolution based on context
- Use Edit tool to resolve
- Complete merge commit
- Continue with review fixes
Quality Gate Failures
If syntax check or linting fails:
- Display specific errors
- Fix automatically if possible
- Re-run quality gates
- Only proceed to commit when all gates pass
Example Usage
Fix Review for Specific PR
```bash
/pr-fix-pr-review 5642
```
Fix Review for Latest PR
```bash
/pr-fix-pr-review
```
(Will list your open PRs if ID not provided)
Best Practices
- Read all comments first - Understand full scope before making changes
- Make targeted fixes - Address each comment specifically
- Run quality gates - Ensure changes meet project standards
- Descriptive replies - Explain what was changed and why
- Resolve appropriately - Only resolve threads when fix is complete
- Test locally - Consider running relevant tests if available
Integration with /deploy-workflow
This command is automatically called by `/deploy-workflow` when:
- `/pr-review` identifies issues requiring changes
- The workflow needs to iterate on PR quality before merging
The workflow will loop:
- `/pr-review` → identifies issues (may include pyspark-engineer deep analysis)
- `/pr-fix-pr-review` → addresses issues
- Standard fixes: Direct Edit tool usage
- Complex PySpark fixes: pyspark-engineer agent handles implementation
- `/pr-review` → re-validates
- Repeat until PR is approved
PySpark-Engineer Integration:
- Automatically triggered for performance and architecture issues
- Ensures optimised, production-ready PySpark code
- Maintains consistency with medallion architecture patterns
- Validates test coverage and quality gates
Notes
- Automatic PR Update: Pushing to source branch automatically updates the PR
- No New PR Created: This updates the existing PR, doesn't create a new one
- Preserves History: All review iterations are preserved in commit history
- Thread Management: Replies and resolutions are tracked in Azure DevOps
- Quality First: Will not commit changes that fail quality gates
- Intelligent Delegation: Routes simple fixes to Edit tool, complex PySpark issues to specialist agent
- Expert Optimisation: pyspark-engineer ensures performance and architecture best practices