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