Skip to content
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

Adding custom github webhook getting "NameError: uninitialized constant Handlers" #1084

Open
stairsj opened this issue Jun 15, 2020 · 1 comment

Comments

@stairsj
Copy link

stairsj commented Jun 15, 2020

Hello,

Newbie Ruby developer, I am trying to add a custom github webhook listener to shipit. I have modified by environments/development.rb and added the following lines

Shipit::Webhooks.register_handler('issue_comment') do |params| puts "Webhook Calling issue_comment" end

I end up with the following error message on start

rake aborted! NameError: uninitialized constant Handlers /usr/local/bundle/gems/shipit-engine-0.31.0/app/models/shipit/webhooks.rb:6:indefault_handlers'
/usr/local/bundle/gems/shipit-engine-0.31.0/app/models/shipit/webhooks.rb:18:in reset_handlers!' /usr/local/bundle/gems/shipit-engine-0.31.0/app/models/shipit/webhooks.rb:14:in handlers'
/usr/local/bundle/gems/shipit-engine-0.31.0/app/models/shipit/webhooks.rb:22:in register_handler' /var/shipit/config/environments/development.rb:65:in block in <top (required)>'
/usr/local/bundle/gems/railties-6.0.2.1/lib/rails/railtie.rb:216:in instance_eval' /usr/local/bundle/gems/railties-6.0.2.1/lib/rails/railtie.rb:216:in configure'
/var/shipit/config/environments/development.rb:1:in <top (required)>' /usr/local/bundle/gems/railties-6.0.2.1/lib/rails/engine.rb:612:in block (2 levels) in class:Engine'
/usr/local/bundle/gems/railties-6.0.2.1/lib/rails/engine.rb:611:in each' /usr/local/bundle/gems/railties-6.0.2.1/lib/rails/engine.rb:611:in block in class:Engine'
/usr/local/bundle/gems/railties-6.0.2.1/lib/rails/initializable.rb:32:in instance_exec' /usr/local/bundle/gems/railties-6.0.2.1/lib/rails/initializable.rb:32:in run'
/usr/local/bundle/gems/railties-6.0.2.1/lib/rails/initializable.rb:61:in block in run_initializers' /usr/local/bundle/gems/railties-6.0.2.1/lib/rails/initializable.rb:50:in each'
/usr/local/bundle/gems/railties-6.0.2.1/lib/rails/initializable.rb:50:in tsort_each_child' /usr/local/bundle/gems/railties-6.0.2.1/lib/rails/initializable.rb:60:in run_initializers'
/usr/local/bundle/gems/railties-6.0.2.1/lib/rails/application.rb:363:in initialize!' /var/shipit/config/environment.rb:5:in <top (required)>'
/usr/local/bundle/gems/railties-6.0.2.1/lib/rails/application.rb:339:in require_environment!' /usr/local/bundle/gems/railties-6.0.2.1/lib/rails/application.rb:515:in block in run_tasks_blocks'
Tasks: TOP => railties:install:migrations => db:load_config => environment
(See full trace by running task with --trace)
`
Any assistance would be greatly appreciated.

@casperisfine
Copy link
Contributor

Hi, this happens because the register happens too early in the application initialization cycle. To fix this the register_handler should be in a to_prepare callback:

https://guides.rubyonrails.org/configuring.html#initialization-events

The README.md isn't clear enough on this though, it should be improved.

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

No branches or pull requests

2 participants