diff --git a/files/webhook b/files/webhook index 6e090764..da4abea0 100755 --- a/files/webhook +++ b/files/webhook @@ -8,7 +8,6 @@ # Jeff Malnick require 'rubygems' - require 'sinatra/base' require 'webrick' require 'webrick/https' @@ -17,6 +16,7 @@ require 'mcollective' require 'resolv' require 'json' require 'yaml' +require 'cgi' include MCollective::RPC @@ -60,15 +60,26 @@ class Server < Sinatra::Base # Simulate a github post: # curl -d '{ "ref": "refs/heads/production" }' -H "Accept: application/json" 'https://puppet:puppet@localhost:8088/payload' -k -q # - # Somulate a stash post: + # Simulate a stash post: # curl -d '{ "refChanges":[ { "refId":"refs/heads/production" } ] }' -H "Accept: application/json" 'https://puppet:puppet@localhost:8088/payload' -k -q # + # Simulate a Gitorious post: + # curl -X POST -d '%7b%22ref%22%3a%22master%22%7d' 'http://puppet:puppet@localhost:8088/payload' -q + # Yes, Gitorious does not support https... post '/payload' do protected! if $config['protected'] $logger.info("authenticated: #{$config['user']}") request.body.rewind # in case someone already read it - data = JSON.parse(request.body.read, :quirks_mode => true) + + # Check if content type is x-www-form-urlencoded + if request.content_type.to_s.downcase.eql?('application/x-www-form-urlencoded') + decoded = CGI::unescape(request.body.read).gsub(/^payload\=/,'') + else + decoded = request.body.read + end + data = JSON.parse(decoded, :quirks_mode => true) + # github sends a 'ref', stash sends an array in 'refChanges' branch = ( data['ref'] || data['refChanges'][0]['refId'] ).split("/").last