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

Version Path
houston-core-0.7.0.beta3 app/controllers/hooks_controller.rb
houston-core-0.7.0.beta2 app/controllers/hooks_controller.rb
houston-core-0.7.0.beta app/controllers/hooks_controller.rb
houston-core-0.6.3 app/controllers/hooks_controller.rb
houston-core-0.6.2 app/controllers/hooks_controller.rb
houston-core-0.6.1 app/controllers/hooks_controller.rb
houston-core-0.6.0 app/controllers/hooks_controller.rb
houston-core-0.5.6 app/controllers/hooks_controller.rb
houston-core-0.5.5 app/controllers/hooks_controller.rb