Skip to content

Testing: Issue Number Extraction

Complete testing guide for issue number extraction patterns used in workflows.

Test Script: test-issue-extraction.sh

Quick Start

bash
./.github/workflows/test-issue-extraction.sh

Tests 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 → #123
  • issue/123 → #123
  • fix-456 → #456
  • fix/456 → #456
  • feature-789 → #789
  • feature/789 → #789
  • 123-description → #123
  • #999 → #999

PR Descriptions

  • Fixes #123 → #123 (case-insensitive)
  • Closes #456 → #456
  • Resolves #789 → #789
  • Fix #111 → #111
  • Close #222 → #222
  • Resolve #333 → #333
  • This PR fixes #444 → #444
  • Feature: #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:

bash
# 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:

bash
# 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:

bash
# Create branch with issue number
git checkout -b fix-123-ui-bug

# Workflow automatically extracts: #123
# Workflow links PR to issue #123

Auto-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 today

Test 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:

bash
# 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

  1. Add test case:
bash
test_branch_pattern "your-pattern-123" "123"
  1. Update extraction logic in workflow: File: .github/workflows/issue-automation.yml

Add pattern to extraction section:

bash
if [[ "$branch" =~ your-pattern[-/]([0-9]+) ]]; then
  ISSUE_NUMBER="${BASH_REMATCH[1]}"
fi
  1. Add test to ensure it works:
bash
./.github/workflows/test-issue-extraction.sh

Best Practices

Branch Naming

DO:

  • Use issue-123 or issue/123 for issues
  • Use fix-456 for bug fixes
  • Use feature-789 for features
  • Use 123-description for 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

These patterns feed into other workflows:

WorkflowUsesPurpose
issue-automation.ymlBranch + PR patternsLink issues to projects
apply-triage.ymlIssue extractionApply auto-triage labels
discord-notify.ymlIssue extractionDiscord notifications

Examples

Example 1: Perfect Workflow

bash
# 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 date

Example 2: Feature Development

bash
# 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

Built with VitePress