Skip to content

Commit ccf83d5

Browse files
authored
Merge pull request #40 from travis-ci/joshk-json-rulez-the-world
All events from an App are json payloads
2 parents a73851a + 8592ad2 commit ccf83d5

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

lib/travis/listener/app.rb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class App < Sinatra::Base
3232
end
3333

3434
get '/' do
35-
redirect "http://about.travis-ci.org"
35+
redirect "http://travis-ci.com"
3636
end
3737

3838
# Used for new relic uptime monitoring
@@ -205,21 +205,23 @@ def push_head_commit
205205
end
206206

207207
def delivery_guid
208-
env['HTTP_X_GITHUB_GUID']
208+
env['HTTP_X_GITHUB_GUID'] || env['HTTP_X_GITHUB_DELIVERY']
209209
end
210210

211211
def payload
212-
if github_pr_event?
212+
if !params[:payload].blank?
213213
params[:payload]
214-
elsif github_apps_event?
215-
begin
216-
@_parsed_json ||= JSON.parse(request.body.read)
217-
rescue JSON::ParserError
218-
nil
219-
end
214+
elsif !request_body.blank?
215+
request_body
216+
else
217+
nil
220218
end
221219
end
222220

221+
def request_body
222+
@_request_body ||= request.body.read
223+
end
224+
223225
def slug
224226
"#{owner_login}/#{repository_name}"
225227
end

spec/travis/app_spec.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
end
1414

1515
def create(opts = {})
16-
params = { :payload => (opts[:payload] || payload) }
16+
params = {}
17+
18+
if params_payload = (opts[:payload] || payload)
19+
params[:payload] = params_payload
20+
end
21+
1722
headers = { 'HTTP_X_GITHUB_EVENT' => 'push', 'HTTP_X_GITHUB_GUID' => 'abc123' }
1823
headers.merge!(opts.delete(:headers) || {})
1924

0 commit comments

Comments
 (0)