Skip to content

Commit

Permalink
Adding github ping handler (#25)
Browse files Browse the repository at this point in the history
* Adding github ping handler so setting up a new webhook doesn't fail right away

* Remove unused helper
  • Loading branch information
camertron committed Apr 19, 2016
1 parent 02aa560 commit 7dcd9ab
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/txgh/handlers/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions lib/txgh/handlers/github/ping_handler.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions lib/txgh/handlers/github/request_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 0 additions & 4 deletions lib/txgh/response_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions spec/handlers/github/ping_handler_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7dcd9ab

Please sign in to comment.