Fix: PR number extraction regex to handle format variations

Resolved 💬 4 comments Opened Nov 5, 2025 by sl-factory[bot] Closed Jan 9, 2026

Summary

Fix PR number extraction from ticket comments to handle variations in formatting (colons, spaces, etc.).

Problem (Bug #5 from #167)

Ticket #2 execution showed:

✓ Pull Request: #18 - Ready for review
✗ Error executing #2: Developer failed to create PR

PR #18 was created successfully, but CLI marked ticket as failed because it couldn't extract the PR number.

Impact:

  • False failures block workflow
  • Successful tickets marked as failed
  • Sprint execution stops prematurely

Root Cause

Developer commented: **Pull Request:** #18 - Ready for review

CLI regex: r"(?:Pull request|PR)\s+#(\d+)"

  • Requires space(s) between "PR" and "#"
  • Actual comment has colon: "Pull Request: #18"
  • Colon breaks the match → extraction fails → ticket marked as failed

Solution

Make regex more flexible to handle common variations:

Location: src/factory/cli.py:1800

# OLD:
pr_match = re.search(r"(?:Pull request|PR)\s+#(\d+)", comment.body, re.IGNORECASE)

# NEW:
pr_match = re.search(
    r"(?:Pull request|PR)[:\s]+#(\d+)",  # Allow colon or spaces
    comment.body,
    re.IGNORECASE
)

This allows:

  • Pull request #18
  • PR #18
  • Pull Request: #18
  • PR: #18
  • Pull request: #18 (multiple spaces)

Test Plan

  1. Unit tests for PR extraction:
test_cases = [
    "Pull request #18",
    "PR #18",
    "Pull Request: #18",
    "PR: #18",
    "**Pull Request:** #123 - Ready",
    "Created pull request #456",
]
for comment in test_cases:
    assert extract_pr_number(comment) is not None
  1. E2E test:
  • Mock Developer agent to post comment with colon format
  • Verify CLI successfully extracts PR number
  • Verify ticket not marked as failed

Acceptance Criteria

  • [ ] Regex updated to r"(?:Pull request|PR)[:\s]+#(\d+)"
  • [ ] Unit tests for all format variations
  • [ ] All existing tests still pass
  • [ ] E2E test with colon format
  • [ ] Documentation: Comment format examples

Related Issues

  • Fixes Bug #5 in #167
  • One-line regex fix

Priority

High - Causes false failures in Stage 2 execution.

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗