Testing: Issue Number Extraction
Complete testing guide for issue number extraction patterns used in workflows.
Test Script: test-issue-extraction.sh
Quick Start
./.github/workflows/test-issue-extraction.shTests 20+ branch naming and PR description patterns to ensure issue numbers are correctly extracted.
What Gets Tested
The test script validates extraction patterns for:
✅ Branch Names
issue-123→ #123issue/123→ #123fix-456→ #456fix/456→ #456feature-789→ #789feature/789→ #789123-description→ #123#999→ #999
✅ PR Descriptions
Fixes #123→ #123 (case-insensitive)Closes #456→ #456Resolves #789→ #789Fix #111→ #111Close #222→ #222Resolve #333→ #333This PR fixes #444→ #444Feature: #555 description→ #555#666→ #666
✅ Edge Cases
- Case-insensitive matching
- Multiple spaces handling
- No false positives for non-matching patterns
Expected Output
Testing Issue Number Extraction Patterns
========================================
Branch Pattern Tests:
---------------------
✅ PASS: 'issue-123' → #123
✅ PASS: 'issue/123' → #123
✅ PASS: 'fix-456' → #456
✅ PASS: 'fix/456' → #456
✅ PASS: 'feature-789' → #789
✅ PASS: 'feature/789' → #789
✅ PASS: '123-description' → #123
✅ PASS: '#999' → #999
✅ PASS: 'feature/new-ui' → (no match) ✓
✅ PASS: 'main' → (no match) ✓
PR Pattern Tests:
-----------------
✅ PASS: 'Fixes #123' → #123
✅ PASS: 'Closes #456' → #456
✅ PASS: 'Resolves #789' → #789
✅ PASS: 'Fix #111' → #111
✅ PASS: 'Close #222' → #222
✅ PASS: 'Resolve #333' → #333
✅ PASS: 'This PR fixes #444' → #444
✅ PASS: 'Feature: #555 description' → #555
✅ PASS: '#666' → #666
✅ PASS: 'No issue reference' → (no match) ✓
All tests passed! ✅How Issue Extraction Works
Branch Pattern Matching
The workflow extracts issue numbers from branch names using these patterns:
# Pattern 1: issue-123 or issue/123
if [[ "$branch" =~ issue[-/]([0-9]+) ]]
# Pattern 2: fix-456 or fix/456
if [[ "$branch" =~ fix[-/]([0-9]+) ]]
# Pattern 3: feature-789 or feature/789
if [[ "$branch" =~ feature[-/]([0-9]+) ]]
# Pattern 4: 123-description (issue number first)
if [[ "$branch" =~ ^([0-9]+)- ]]
# Pattern 5: #999 (direct hash reference)
if [[ "$branch" =~ \#([0-9]+) ]]Matched groups are extracted: #123, #456, etc.
PR Description Pattern Matching
The workflow extracts issue numbers from PR titles/bodies:
# Case-insensitive patterns
# Matches: Fixes #123, Closes #456, Resolves #789, etc.
if [[ "$text_lower" =~ (fixes|closes|resolves|fix|close|resolve)[[:space:]]*\#([0-9]+) ]]
# Fallback: direct hash reference
if [[ "$text" =~ \#([0-9]+) ]]Use Cases
Automatic Issue Linking
When you create a PR:
# Create branch with issue number
git checkout -b fix-123-ui-bug
# Workflow automatically extracts: #123
# Workflow links PR to issue #123Auto-Add to Projects
When you open a PR:
PR Title: "Fix navigation crash"
PR Body: "Fixes #456"
Workflow:
1. Extracts issue #456
2. Adds to GitHub Projects V2
3. Sets Status to "In progress"
4. Sets Start date to todayTest Coverage
20+ test cases covering:
- Both
/and-separators - Case variations (fixes, Fixes, FIXES)
- Multiple spaces
- Different prefix types (issue, fix, feature)
- Direct hash references
- Fallback matching
- False negative prevention (non-matching patterns)
Troubleshooting
"Tests failed"
Check if branch naming convention changed:
# Review current branch names
git branch -a
# Check if they match expected patterns
git branch | grep -E '^[[:space:]]*(issue|fix|feature)[-/][0-9]+'Adding New Extraction Patterns
To add a new branch naming pattern:
File: .github/workflows/test-issue-extraction.sh
- Add test case:
test_branch_pattern "your-pattern-123" "123"- Update extraction logic in workflow: File:
.github/workflows/issue-automation.yml
Add pattern to extraction section:
if [[ "$branch" =~ your-pattern[-/]([0-9]+) ]]; then
ISSUE_NUMBER="${BASH_REMATCH[1]}"
fi- Add test to ensure it works:
./.github/workflows/test-issue-extraction.shBest Practices
Branch Naming
✅ DO:
- Use
issue-123orissue/123for issues - Use
fix-456for bug fixes - Use
feature-789for features - Use
123-descriptionfor issue numbers first - Keep it clear and consistent
❌ DON'T:
- Use vague names like
fix-ui - Mix separators randomly
- Create branches without issue numbers
- Use non-numeric characters in issue numbers
PR Descriptions
✅ DO:
- Use "Fixes #123" in PR body
- Use "Closes #456" for completing issues
- Be explicit: "Resolves #789 by adding validation"
❌ DON'T:
- Use "Refs #123" (won't auto-link)
- Hide issue numbers in middle of sentences
- Create PRs without issue references
Related Patterns
These patterns feed into other workflows:
| Workflow | Uses | Purpose |
|---|---|---|
issue-automation.yml | Branch + PR patterns | Link issues to projects |
apply-triage.yml | Issue extraction | Apply auto-triage labels |
discord-notify.yml | Issue extraction | Discord notifications |
Examples
Example 1: Perfect Workflow
# 1. Create issue in GitHub
# Issue #123: "Fix login button"
# 2. Create branch following pattern
git checkout -b fix-123-login-button
# 3. Make changes and push
git push origin fix-123-login-button
# 4. Create PR with description
# Title: "Fix login button styling"
# Body: "Fixes #123"
# Workflow automatically:
# ✅ Extracts #123 from branch
# ✅ Extracts #123 from PR description
# ✅ Links PR to issue
# ✅ Adds to Projects
# ✅ Sets status and dateExample 2: Feature Development
# Branch: feature-456-dark-mode
# PR Body: "Closes #456 - Implements dark mode with toggle"
# Workflow extracts #456 and:
# ✅ Links PR to issue
# ✅ Auto-closes issue on merge (because of "Closes")See Also
- Workflows Overview - All workflows
- GitHub Actions Patterns
- Bash Pattern Matching