#! /usr/bin/env ruby # Default path of RUBY interpreter. # # Description: # Trigger to block submission of changelists which contain any variation of # "do not submit" (case/spacing insensitive) on the first line of the changelist # description. # # Use: # "DoNotSubmit.rb -p %serverAddress% -c %changelist%" # # Trigger use: # DoNotSubmit change-submit //DepotPathForTargetFiles/... # ".../TriggerDirectory/DoNotSubmit.rb -p %masterServer% -c %changelist%" # # Author: Joe Robinson # Created: 2013/06/28 # Editor: $Author$ # Edited: $DateTime$ # File: $File$ require 'optparse' require 'Open3' # ADMIN OPTIONS: #---------- # Regular expression to examine description field against. regexString = /\A[\W_]*DO[\W_]*NOT[\W_]*SUBMIT[\W_]*/im # LOCATION of p4 binary (server-side) p4binary = "/usr/local/bin/p4" # User to run 'p4 change' command as. Example: "someServiceUser" userArg = "joe_robinson" #---------- options = {} options[:userName] = userArg OptionParser.new do |opts| opts.banner = "Usage: #{$PROGRAM_NAME} -p SERVERADDRESS -c CHANGELISTNUM" opts.on("-p", "--port SERVERADDRESS", String, "Address of server (hostname:port).") do |newServerAddress| options[:port] = newServerAddress end opts.on("-c", "--changeNum NUM", "Changelist number being submitted.") do |newChangelistNum| options[:changelistNum] = newChangelistNum end opts.on_tail("-h", "--help", "Help message") do puts opts.help exit end end.parse! # Format command into string for execution. commandString = "p4 -R -p #{options[:port]} -u #{options[:userName]} " + "change -o #{options[:changelistNum]}" # Create dictionary object (=~ Ruby Hash) dictionary = Hash.new() # Read in dictionary object (Ruby Hash) from std_out of 'p4 -R change'. Open3.popen3("%s" % commandString) { |std_in, std_out, std_err, status| dictionary = Marshal.load(std_out) } # Get string and regexp for comparison. descString = dictionary["Description"] regexp = Regexp.compile(regexString) # If string and regexp match, abort with message. if descString =~ regexp abort(" --- DoNotSubmit (rb) REJECTED changelist %s." % options[:changelistNum]) else exit(0) end