Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.