Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Commit 5e147da

Browse files
committed
Initial commit.
0 parents  commit 5e147da

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'sinatra'
4+
gem 'json'

Gemfile.lock

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
json (1.8.1)
5+
rack (1.5.2)
6+
rack-protection (1.5.2)
7+
rack
8+
sinatra (1.4.4)
9+
rack (~> 1.4)
10+
rack-protection (~> 1.4)
11+
tilt (~> 1.3, >= 1.3.4)
12+
tilt (1.4.1)
13+
14+
PLATFORMS
15+
ruby
16+
17+
DEPENDENCIES
18+
json
19+
sinatra

config.ru

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require 'bundler'
2+
Bundler.setup
3+
4+
require 'sinatra'
5+
require 'json'
6+
require 'digest/sha2'
7+
8+
class TravisWebhook < Sinatra::Base
9+
set :token, ENV['TRAVIS_USER_TOKEN']
10+
11+
post '/' do
12+
if not valid_request?
13+
puts "Invalid payload request for repository #{repo_slug}"
14+
else
15+
payload = JSON.parse(params[:payload])
16+
puts "Received valid payload"
17+
end
18+
end
19+
20+
def valid_request?
21+
digest = Digest::SHA2.new.update("#{repo_slug}#{settings.token}")
22+
digest.to_s == authorization
23+
end
24+
25+
def authorization
26+
env['HTTP_AUTHORIZATION']
27+
end
28+
29+
def repo_slug
30+
env['HTTP_TRAVIS_REPO_SLUG']
31+
end
32+
end
33+
34+
run TravisWebhook

0 commit comments

Comments
 (0)