This repository has been archived by the owner on Mar 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
58 lines (45 loc) · 1.53 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require 'sinatra'
hipchat_api_token = ENV['HIPCHAT_TOKEN']
hipchat_room_id = ENV['HIPCHAT_ROOM_ID']
hipchat_username = ENV['HIPCHAT_USERNAME']
hipchat_client = HipChat::Client.new(hipchat_api_token)
client = Octokit::Client.new(oauth_token: ENV['GITHUB_TOKEN'])
repo_owner = ENV['GITHUB_REPO_OWNER']
repo_name = ENV['GITHUB_REPO_NAME']
repo = Octokit::Repository.new(owner: repo_owner, name: repo_name)
Redis.current = Redis.new( url: ENV['REDISCLOUD_URL'] )
get '/' do
puts "Hello World!"
end
get '/test_hipchat' do
hipchat_client[hipchat_room_id].send(hipchat_username, 'Hello!')
end
post '/build_result' do
puts params
sha = params['sha']
state = params['state']
target_url = params['target_url']
build_result = Redis::HashKey.new(sha)
build_result['state'] = state
build_result['target_url'] = target_url
client.create_status(repo, sha, state, target_url: target_url)
"POSTED BUILD RESULT #{state} #{sha} #{target_url}"
end
post '/github_callback' do
payload = JSON.parse(params[:payload])
puts "payload.keys #{payload.keys}"
pull_request = payload['pull_request']
if pull_request['state'] == 'open'
puts "pull_request.keys #{pull_request.keys}"
head = pull_request['head']
puts "head #{head}"
sha = head['sha']
build_result = Redis::HashKey.new(sha)
state = build_result['state'] || 'pending'
target_url = build_result['target_url']
client.create_status(repo, sha, state, target_url: target_url)
"PULL REQUEST OPEN EVENT #{state} #{sha} #{target_url}"
else
"IGNORED"
end
end