Skip to content

Commit

Permalink
implement travis event handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Oct 7, 2019
1 parent 91c43c4 commit fe92a18
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/controllers/incoming_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class IncomingController < ApplicationController
##
# Parse the whole payload from Github and hand it over to the GithubEvent handler
def github
# ToDo: verify the payload
payload = request.body.read
useable_body = JSON.parse(payload).to_h

Expand All @@ -15,6 +16,17 @@ def github
GithubEvent.new(useable_body, request.headers['X-GitHub-Event'])
end

##
# Parse the whole payload from travis and hand it over to the TravisEvent handler
def travis
# ToDo: verify the payload
# https://github.com/travis-ci/webhook-signature-verifier/blob/master/lib/webhook-signature-verifier.rb#L40
# https://docs.travis-ci.com/user/notifications/#verifying-webhook-requests
payload = request.body.read
useable_body = JSON.parse(payload).to_h
TravisEvent.new(useable_body)
end

private

def verify_signature(payload)
Expand Down
30 changes: 30 additions & 0 deletions app/lib/travis_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

class TravisEvent
attr_reader :processor
delegate :process, to: :processor

##
# The TravisEvent handler checks which type of event we are dealing with.
#
# If it is a known event, create a specific handler and let it take care of
# the next steps. If not kick off a Sentry error.

def initialize(payload, type)
known_but_ignoreable_events = %w[
installation
issues
pull_request_review
issue_comment
label
pull_request_review_comment
installation_repositories
integration_installation_repositories
repository
integration_installation
ping
pull_request_review
]

end
end
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

post 'incoming/github', to: 'incoming#github'

post 'incoming/travis', to: 'incoming#travis'

constraints ->(req) { req.session['user_id'] } do
mount Sidekiq::Web => '/sidekiq'
end
Expand Down

0 comments on commit fe92a18

Please sign in to comment.