Skip to content

Instantly share code, notes, and snippets.

@feelobot
Created May 29, 2014 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save feelobot/32edcda4706c06267fa5 to your computer and use it in GitHub Desktop.
Save feelobot/32edcda4706c06267fa5 to your computer and use it in GitHub Desktop.
require 'sinatra'
require 'json'
require 'digest/sha2'
class TravisWebhook < Sinatra::Base
set :token, ENV['TRAVIS_USER_TOKEN']
post '/' do
if not valid_request?
puts "Invalid payload request for repository #{repo_slug}"
else
payload = JSON.parse(params[:payload])
puts "Received valid payload for repository #{repo_slug}"
end
end
def valid_request?
digest = Digest::SHA2.new.update("#{repo_slug}#{settings.token}")
digest.to_s == authorization
end
def authorization
env['HTTP_AUTHORIZATION']
end
def repo_slug
env['HTTP_TRAVIS_REPO_SLUG']
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment