Conversation
feat: make PR Sync autofill before synchronization
📝 WalkthroughWalkthroughThe PR adds a reusable autofill CLI that resolves pull request issues and milestones, rewrites selected body sections, updates GitHub and event data, and runs before PR synchronization. Tests cover resolution, exclusions, persistence, and workflow ordering. ChangesPull request autofill
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@project_setup/pr_autofill.py`:
- Around line 39-50: Update the section-parsing loop in rewrite_pr_body to track
whether each line is inside a fenced Markdown code block and skip
SECTION_HEADING_PATTERN matching while fenced. Toggle the fence state on
Markdown fence delimiters, preserve existing preamble and section handling
outside fences, and add a regression test covering a fenced block containing a
target heading that must remain unchanged.
- Around line 146-153: Update resolve_from_branch’s explicit branch-token path
to catch GitHubRequestError from client.get_issue when the referenced issue is
unresolved. Return no issue and no milestone with the existing explanatory
message, allowing PR sync to continue without issuing a PATCH.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 4ec83ca8-4f3b-409d-b756-3484f6924d9a
📒 Files selected for processing (3)
.github/workflows/pr-sync.ymlproject_setup/pr_autofill.pytests/test_pr_sync_autofill.py
| for line in (body or "").splitlines(): | ||
| heading = SECTION_HEADING_PATTERN.match(line) | ||
| if heading: | ||
| if current_name is not None: | ||
| sections.append((current_name, current_lines)) | ||
| current_name = heading.group(1) | ||
| current_lines = [] | ||
| continue | ||
| if current_name is None: | ||
| preamble.append(line) | ||
| else: | ||
| current_lines.append(line) |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Do not parse headings inside fenced Markdown blocks.
A fenced code example can contain ## Linked Issue or ## Milestone. This parser treats that content as a mutable section. rewrite_pr_body can then modify code that the PR author did not intend to change.
Track fenced code blocks before matching section headings. Add a regression test with a fenced block that contains a target heading.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@project_setup/pr_autofill.py` around lines 39 - 50, Update the
section-parsing loop in rewrite_pr_body to track whether each line is inside a
fenced Markdown code block and skip SECTION_HEADING_PATTERN matching while
fenced. Toggle the fence state on Markdown fence delimiters, preserve existing
preamble and section handling outside fences, and add a regression test covering
a fenced block containing a target heading that must remain unchanged.
| explicit = BRANCH_ISSUE_PATTERN.search(branch or "") | ||
| if explicit: | ||
| number = int(explicit.group(1)) | ||
| issue = client.get_issue(repo, number) | ||
| if "pull_request" in issue: | ||
| return None, None, f"branch references #{number}, but that item is a pull request" | ||
| milestone = (issue.get("milestone") or {}).get("title") | ||
| return issue, str(milestone) if milestone else None, f"resolved issue #{number} from branch token" |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the GitHub client's non-success response behavior.
ast-grep outline project_setup/github.py --items all
rg -n -C 8 'def request_json\(|def get_issue\(|raise |HTTP|status' project_setup/github.py
# Locate existing tests for failed issue resolution.
rg -n -C 5 'get_issue\(|resolve_from_branch|issue-[0-9]+' tests project_setupRepository: v-Kaefer/Github-Project-Automation
Length of output: 17428
Handle unresolved explicit issue tokens without stopping PR Sync.
get_issue() raises GitHubRequestError for a 404, and resolve_from_branch() does not catch it. Catch this error for the explicit branch issue, return no metadata, and let the existing message print without issuing a PATCH.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@project_setup/pr_autofill.py` around lines 146 - 153, Update
resolve_from_branch’s explicit branch-token path to catch GitHubRequestError
from client.get_issue when the referenced issue is unresolved. Return no issue
and no milestone with the existing explanatory message, allowing PR sync to
continue without issuing a PATCH.
Linked Issue
Milestone
Summary
How to test
Evidence
Known risks
DoD checklist
Summary by CodeRabbit