diff --git a/lib/txgh/handlers/github.rb b/lib/txgh/handlers/github.rb index 701c5440..5a8903fb 100644 --- a/lib/txgh/handlers/github.rb +++ b/lib/txgh/handlers/github.rb @@ -3,6 +3,7 @@ module Handlers module Github autoload :DeleteHandler, 'txgh/handlers/github/delete_handler' autoload :Handler, 'txgh/handlers/github/handler' + autoload :PingHandler, 'txgh/handlers/github/ping_handler' autoload :PushHandler, 'txgh/handlers/github/push_handler' autoload :RequestHandler, 'txgh/handlers/github/request_handler' end diff --git a/lib/txgh/handlers/github/ping_handler.rb b/lib/txgh/handlers/github/ping_handler.rb new file mode 100644 index 00000000..79ec707e --- /dev/null +++ b/lib/txgh/handlers/github/ping_handler.rb @@ -0,0 +1,18 @@ +module Txgh + module Handlers + module Github + # Handles github's ping event, which is a test event fired whenever a new + # webhook is set up. + class PingHandler + include ResponseHelpers + + def initialize(options = {}) + end + + def execute + respond_with(200, {}) + end + end + end + end +end diff --git a/lib/txgh/handlers/github/request_handler.rb b/lib/txgh/handlers/github/request_handler.rb index 9e1e7247..61af9799 100644 --- a/lib/txgh/handlers/github/request_handler.rb +++ b/lib/txgh/handlers/github/request_handler.rb @@ -14,6 +14,8 @@ def handle_request(request, logger) handle_push(request, logger) when 'delete' handle_delete(request, logger) + when 'ping' + handle_ping(request, logger) else handle_unexpected end @@ -31,6 +33,11 @@ def handle_delete(request, logger) new(request, logger).handle(klass) end + def handle_ping(request, logger) + klass = Txgh::Handlers::Github::PingHandler + new(request, logger).handle(klass) + end + def handle_unexpected respond_with_error(400, 'Unexpected event type') end diff --git a/lib/txgh/response_helpers.rb b/lib/txgh/response_helpers.rb index 96146352..8f56dadb 100644 --- a/lib/txgh/response_helpers.rb +++ b/lib/txgh/response_helpers.rb @@ -6,10 +6,6 @@ def respond_with(status, body, e = nil) Txgh::Handlers::Response.new(status, body, e) end - def respond_with_success(status, body) - respond_with(status, data(body)) - end - def respond_with_error(status, message, e = nil) respond_with(status, error(message), e) end diff --git a/spec/handlers/github/ping_handler_spec.rb b/spec/handlers/github/ping_handler_spec.rb new file mode 100644 index 00000000..4692a7d5 --- /dev/null +++ b/spec/handlers/github/ping_handler_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper' + +include Txgh +include Txgh::Handlers::Github + +describe PingHandler do + let(:handler) do + PingHandler.new + end + + it 'responds with a 200 success' do + response = handler.execute + expect(response.status).to eq(200) + expect(response.body).to eq({}) + end +end