This repository was archived by the owner on Sep 12, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +57
-0
lines changed Expand file tree Collapse file tree 3 files changed +57
-0
lines changed Original file line number Diff line number Diff line change
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'sinatra'
4
+ gem 'json'
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments