Make handler field support only snake_case in configuration#54
Merged
Conversation
Co-authored-by: GrantBirki <23362539+GrantBirki@users.noreply.github.com>
Co-authored-by: GrantBirki <23362539+GrantBirki@users.noreply.github.com>
Co-authored-by: GrantBirki <23362539+GrantBirki@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] task: make the handler field support only snake_case
Make handler field support only snake_case in configuration
Jun 17, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR enforces snake_case naming for the handler field in endpoint configurations, updating validation, loading, and tests to match the new convention.
- Updated
ConfigValidatorto only accept snake_case handler names and convert them to PascalCase for security checks - Modified
PluginLoaderto transform snake_case config values into PascalCase for internal class lookup - Revised tests and helper methods to use snake_case everywhere and maintain 100% coverage
Reviewed Changes
Copilot reviewed 48 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/hooks/core/config_validator.rb | Changed handler-name regex to snake_case and adjusted dangerous-class check |
| lib/hooks/core/plugin_loader.rb | Added snake_case → PascalCase conversion for lookup |
| lib/hooks/app/helpers.rb | Updated docstring to reflect snake_case parameter |
| spec/unit/lib/hooks/handlers/base_spec.rb | Updated test expectations from PascalCase to snake_case |
| spec/unit/lib/hooks/core/config_validator_spec.rb | Switched handler fixtures to snake_case |
| spec/unit/lib/hooks/core/config_validator_security_spec.rb | Updated security tests for snake_case and PascalCase failures |
| spec/unit/lib/hooks/core/plugin_loader_spec.rb | Adjusted plugin lookup tests to use snake_case |
| spec/unit/lib/hooks/app/helpers_spec.rb | Updated helper load expectations |
| spec/unit/lib/hooks/app/helpers_security_spec.rb | Updated helper security tests to snake_case |
| spec/unit/app/rack_env_builder_spec.rb | Switched handler in rack env to snake_case |
| spec/integration/hooks_integration_spec.rb | Updated integration YAML fixture to snake_case |
| spec/integration/global_lifecycle_hooks_spec.rb | Updated global-lifecycle YAML fixture to snake_case |
| .bundle/config | Bundler path updates (unrelated to handler change) |
Comments suppressed due to low confidence (2)
spec/unit/lib/hooks/core/plugin_loader_spec.rb:166
- We only test default_handler → DefaultHandler; consider adding a test case for a handler name containing a number (e.g.
team_1_handler) to verify the snake_case→PascalCase conversion handles digits correctly.
expect(described_class.get_handler_plugin("default_handler")).to eq(DefaultHandler)
.bundle/config:3
- [nitpick] This CI/deployment configuration change is unrelated to the handler naming change and pollutes the PR; consider removing or splitting it into its own commit.
BUNDLE_PATH: "/home/runner/work/hooks/hooks/vendor/bundle"
…ions; add Team1Handler example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements a breaking change to make the
handlerfield in endpoint configuration files support only snake_case naming, matching the same enforcements of theauth.typefield.Changes Made
Before this change:
After this change:
Implementation Details
/\A[A-Z][a-zA-Z0-9_]*\z/to/\A[a-z][a-z0-9_]*\z/to only accept snake_case handler namesget_handler_pluginmethod to convert snake_case configuration values to PascalCase for internal class lookupgithub_handler.rb) and class names (GithubHandler) remain unchanged - only configuration references use snake_caseExample Usage
If you have a handler file
handlers/github_handler.rbwith contents:It should now be referenced as
handler: github_handlerin endpoint configurations (previouslyhandler: GithubHandler).Breaking Change Notice
This is an intentional breaking change with no backwards compatibility. All existing endpoint configurations using PascalCase handler names must be updated to use snake_case.
Testing
Fixes #53.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.