#!/usr/bin/env ruby # # Triggers: # sendrequest change-commit ... "/path/to/file/sendrequest.rb # %serverport% %change%" # # Description: # Sends a POST to the URLs specified in the 'urls' array. Sends info about the # specified changelist as JSON. The information sent is the user who # submitted the change, the change description, and the list of files changed. # SET THESE OR TRIGGER WILL NOT WORK p4bin = '/usr/local/bin/p4' user = 'jbrower' passwd = 'j1ml1nk1' client = 'jbrower_primary' # Array of URLs to POST to (Add more if you want) urls = [] urls << 'http://localhost:3000/outside_requests' # ALL SET require 'net/http' require 'json' begin if ARGV.length != 2 puts 'Usage: CreateThumbnails.rb serverport change' exit 1 end serverport = ARGV[0] change = ARGV[1] p4 = "#{p4bin} -p #{serverport} -u #{user} -c #{client} -P #{passwd}" describe_output = `#{p4} -R describe -s #{change}` formatted = Marshal.load(describe_output) change_user = formatted['user'] change_desc = formatted['desc'] files = [] i = 0 loop do filename = formatted["depotFile#{i}"] break if (nil == filename) files << filename i += 1 end payload = {'user' => change_user, 'description' => change_desc, 'files' => "#{files}"} #puts payload #params = {} #params['content'] = "#{payload}" #params['content'] = payload #puts payload params = payload json_headers = {"Content-Type" => "application/json", "Accept" => "application/json"} urls.each do |url| uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) response = http.post(uri.path, params.to_json, json_headers) #puts response end end exit 0