Skip to content

feat: add support for regex patterns in scopes - #982

Open
yarinvak wants to merge 1 commit into
Ezard:masterfrom
yarinvak:master
Open

feat: add support for regex patterns in scopes#982
yarinvak wants to merge 1 commit into
Ezard:masterfrom
yarinvak:master

Conversation

@yarinvak

Copy link
Copy Markdown

This PR enhances the scope validation in semantic-prs to support regex patterns in addition to exact string matches. This allows for more flexible scope configurations, particularly useful for ticket-based workflows.

Motivation

Previously, scopes could only be validated against exact string matches. This meant that for ticket-based workflows (e.g., JIRA tickets, GitHub issues), every possible ticket ID would need to be listed in the configuration, which is impractical. With regex support, you can now define patterns like COR- to match any ticket starting with that prefix.

Changes

✨ Enhanced scope validation logic in is-message-semantic.ts to support regex patterns
🧪 Added comprehensive test coverage for regex scope matching (8 new test cases)
📝 Updated README documentation to explain the new regex functionality
🛡️ Added graceful error handling for invalid regex patterns

How It Works

The validation logic now follows this approach:
First attempts an exact string match
If no exact match is found, treats the scope as a regex pattern
Invalid regex patterns are handled gracefully and fall back to exact match only

Configuration Example

scopes:
  - auth          # Exact match
  - frontend      # Exact match  
  - COR-          # Matches COR-1234, COR-5678, etc.
  - JIRA-         # Matches JIRA-123, JIRA-456, etc.

Testing

All existing tests continue to pass

Added 8 new test cases covering:

  • Basic regex pattern matching
  • Multiple regex patterns
  • Mix of exact and regex patterns
  • Invalid regex handling
  • Multi-scope commits with patterns

Breaking Changes

None. This change is fully backward compatible - existing configurations will continue to work exactly as before.
Examples

Valid commit messages with regex scopes:

  • feat(COR-1234): implement new feature
  • fix(JIRA-5678): resolve bug in authentication
  • docs(COR-999,auth): update API documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant