-
Notifications
You must be signed in to change notification settings - Fork 0
Make handler field support only snake_case in configuration #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: GrantBirki <[email protected]>
Co-authored-by: GrantBirki <[email protected]>
Co-authored-by: GrantBirki <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
ConfigValidator
to only accept snake_case handler names and convert them to PascalCase for security checks - Modified
PluginLoader
to 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 PR implements a breaking change to make the
handler
field in endpoint configuration files support only snake_case naming, matching the same enforcements of theauth.type
field.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_plugin
method 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.rb
with contents:It should now be referenced as
handler: github_handler
in 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.