-
-
Save feelobot/32edcda4706c06267fa5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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