Sha256: 343fb1d684483ba635957917605f11601c57c281048d0348f3910db8661827d9
Contents?: true
Size: 1.24 KB
Versions: 9
Compression:
Stored size: 1.24 KB
Contents
class HooksController < ApplicationController skip_before_filter :verify_authenticity_token # https://developer.github.com/webhooks/#events EVENT_HANDLERS = { "pull_request" => Github::PullRequestEvent, "push" => Github::PostReceiveEvent, "commit_comment" => Github::CommitCommentEvent, "issue_comment" => Github::IssueCommentEvent, "pull_request_review_comment" => Github::DiffCommentEvent }.freeze def github event = request.headers["X-GitHub-Event"] if event == "ping" Rails.logger.info "\e[32m[github] ping received\e[0m" head 200 elsif event_processor = EVENT_HANDLERS[event] payload = params.fetch "hook" event_processor.process! payload head 200 else Rails.logger.warn "\e[33m[github] Unrecognized event: #{event}\e[0m" head 404 end end def trigger event = "hooks:#{params[:hook]}" unless Houston.observer.observed?(event) render text: "A hook with the slug '#{params[:hook]}' is not defined", status: 404 return end payload = params.except(:action, :controller).merge({ sender: { ip: request.remote_ip, agent: request.user_agent } }) Houston.observer.fire event, payload head 200 end end
Version data entries
9 entries across 9 versions & 1 rubygems