#!/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
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 10132 | jim_brower | Moved sendrequest.rb and added webhook-wrapper | ||
#2 | 10033 | jim_brower |
sendrequest.rb now supports the three requested trigger types. URLs are extracted from specific keys on the Perforce server. Currently the user must create the keys manually before using the trigger. The program will not explode if the corresponding key is empty. |
||
#1 | 10028 | jim_brower |
Added the first version of the 'webhook' trigger. Correctly POSTs to my test rails app, but the array of files is currently a string. |