#!/usr/bin/ruby
#--
#-------------------------------------------------------------------------------
#++
#
#= Introduction
#
#== Name: check_format_bug_branch.rb
#
#== Author: Robert Cowham <robert@vaccaperna.co.uk>
#
#== Description
#
# Example trigger to enforce bugzilla branch naming convention
# e.g. //software/development/bgz000xxx/bgz000297.br/...
# to avoid no-leading zeroes etc.
#
#== Requires
# Ruby
# P4Ruby
# P4Triggers module
#
#== Example 'triggers' section:
#
# Restrict to only releases area of the repository
#
# Triggers:
# release_check change-submit //software/development/... "ruby whatever/check_format_bug_branch.rb -p %port% -u %user% %changelist%"
# release_check change-submit //software/development/... "ruby c:/work/icera/robert-triggers/check_format_bug_branch.rb -p %serverport% -u robert %changelist% -d"
#
#
#--
#-------------------------------------------------------------------------------
#++
$:.unshift(File.dirname(__FILE__))
require "P4"
require "P4Triggers"
#
# The trigger class itself. The main method in here is validate() which
# is invoked from the super-class' parse_change() method.
#
class NameTrigger < P4Trigger
@@EXCEPTIONS = %w{
//software/development/bug0000xx/bgz000093.br
//software/development/bug0000xx/bgz000254.br
//software/development/bug0000xx/bug000013.br
//software/development/bug0001xx/bug000192.br
//software/development/bug0002xx/bgz000297.br
}
def initialize(options)
@exceptions = @@EXCEPTIONS.collect{|e| Regexp.new(e)}
super(options)
end
#
# The error message we give to the user
#
@@USER_MESSAGE =
"\n\n" +
"Your submission has been rejected because the bugzilla branch name was of the\n" +
"wrong format: //software/development/bgzNNNxxx/bgzNNNNNN.br\n\n"
# Enforce name checking.
def validate()
re_valid_file = Regexp.new('//software/development/bgz(\d\d\d)xxx/bgz(\d\d\d)\d\d\d.br/')
change.each_file do
|file|
# Ignore files not open for add
next unless (file.revisions[ 0 ].action == "add" ||
file.revisions[ 0 ].action == "branch")
if (file.depot_file !~ re_valid_file) ||
($1 != $2)
if @exceptions.select{|re| re.match(file.depot_file)}.size == 0
message(@@USER_MESSAGE)
return false
end
end
end
return true
end
end
#--
#-------------------------------------------------------------------------------
# Start of main script execution
#-------------------------------------------------------------------------------
#++
# By this stage it's pretty simple. Even argument validation is handled by
# the p4Trigger class so we don't even need to check that we were passed
# a changelist number.
trig = NameTrigger.new(P4TriggerOptions.new(ARGV))
result = trig.parse_change(ARGV.shift)
exit(result)