Sha256: 3355671e398cf3a3f0ccacde406a94ba1d468c59728953e4458a51c345cf7b29
Contents?: true
Size: 1.31 KB
Versions: 21
Compression:
Stored size: 1.31 KB
Contents
require_dependency "writefully/application_controller" module Writefully class HooksController < ApplicationController respond_to :json before_filter :check_signature HMAC_DIGEST = OpenSSL::Digest::Digest.new('sha1') class InvalidSignature < StandardError; end def create self.__send__ request.headers["X-Github-Event"].to_sym head :ok end def ping end def push Writefully.add_job :handyman, { task: :synchronize, site_slug: body.repository.name } if branch_match? end def member authorship = Authorship.find_by_uid(body.member.id) unless authorship Authorship.create_from_data(body.member) end end protected def branch_match? Site.where(slug: body.repository.name).first.branch == body.ref.split('/').last end def body @_body ||= Hashie::Mash.new(JSON.parse(request.body.read)) end def check_signature unless signature == request.headers["X-Hub-Signature"] raise InvalidSignature, "Invalid signature" end end def signature 'sha1=' + OpenSSL::HMAC.hexdigest(HMAC_DIGEST, Writefully.options[:hook_secret], request.body.read) end end end
Version data entries
21 entries across 21 versions & 1 rubygems