forked from mmasashi/ghwebhook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webhook.rb
67 lines (63 loc) · 2.87 KB
/
webhook.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
59
60
61
62
63
64
65
66
67
require 'sinatra'
require_relative './request_parser'
require_relative './slack_notifier'
SLACK_WEB_HOOK_URL=ENV['SLACK_WEB_HOOK_URL']
get '/' do
"ok"
end
post '/' do
channel = params['channel']
event = RequestParser.new(request).parse
if event
puts "Sending slack message. event:#{request.env['HTTP_X_GITHUB_EVENT']}"
SlackNotifier.new(SLACK_WEB_HOOK_URL).send_to_slack(event.build_message, channel)
else
puts "Unsupported event. event:#{request.env['HTTP_X_GITHUB_EVENT']}"
end
"ok"
end
# for debug
def dump_request_param
puts "# request.body" # request body sent by the client (see below)
puts request.body.read # request body sent by the client (see below)
puts "# request.scheme" # "http"
puts request.scheme # "http"
puts "# request.script_name" # "/example"
puts request.script_name # "/example"
puts "# request.path_info" # "/foo"
puts request.path_info # "/foo"
puts "# request.port" # 80
puts request.port # 80
puts "# request.request_method" # "GET"
puts request.request_method # "GET"
puts "# request.query_string" # ""
puts request.query_string # ""
puts "# request.content_length" # length of request.body
puts request.content_length # length of request.body
puts "# request.media_type" # media type of request.body
puts request.media_type # media type of request.body
puts "# request.host" # "example.com"
puts request.host # "example.com"
puts "# request.get?" # true (similar methods for other verbs)
puts request.get? # true (similar methods for other verbs)
puts "# request.form_data?" # false
puts request.form_data? # false
puts "# request.referer" # the referer of the client or '/'
puts request.referer # the referer of the client or '/'
puts "# request.user_agent" # user agent (used by :agent condition)
puts request.user_agent # user agent (used by :agent condition)
puts "# request.cookies" # hash of browser cookies
puts request.cookies # hash of browser cookies
puts "# request.xhr?" # is this an ajax request?
puts request.xhr? # is this an ajax request?
puts "# request.url" # "http://example.com/example/foo"
puts request.url # "http://example.com/example/foo"
puts "# request.path" # "/example/foo"
puts request.path # "/example/foo"
puts "# request.ip" # client IP address
puts request.ip # client IP address
puts "# request.secure?" # false
puts request.secure? # false
puts "# request.env" # raw env hash handed in by Rack
puts request.env # raw env hash handed in by Rack
end