#! /bin/tcsh -x
#
# Copyright (c) 2005 Photon Research Associates. All rights reserved.
# Author: David Lee Faison
#
###############################################################################
#
# Redistribution and use in source form, with or without modification, are
# permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notices,
# this list of conditions and the following disclaimer.
#
# 2. The name of Photon Research Associates and/or the author may not be used
# to endorse or promote products derived from this software without specific
# prior written permission.
#
# This software is provided 'AS-IS' and any warranties, express or
# implied, including, but not limited to, the implied warranties of
# merchantability and fitness for a particular purpose are
# DISCLAIMED. In no event shall Photon Research Associates or the author,
# separately or in combination with one another, be liable for any
# direct, indirect, incidental, special, exemplary, or consequential
# damages (including, but not limited to, procurement of substitute goods or
# services; loss of use, data, or profits; or business interruption) however
# caused and on any theory of liability, whether in contract, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
#
#####################################################################################
#
# PURPOSE: this script, when used from within a perforce submit trigger, enforces
# the requirement that a changelist be associated with at least one open job ticket.
#
# $1 - the changelist being submitted
#
# Note: if $1 is not specified then the existence of a CHANGELIST environment
# variable is required to specify the changelist number.
#
#####################################################################################
if ($#argv == 1 ) then
set changelist=$1
else
set changelist=$CHANGELIST
endif
set jobCount=`p4 fixes -c $changelist | wc -l`
echo jobCount=$jobCount > /dev/null
@ ztagLen = 3
@ ztagFldPos = 2
@ ztagValPos = 3
@ openCount = 0 + 0
if ($jobCount > 0) then
set jobNames=`p4 -ztag fixes -c $changelist| grep '^... Job'`
@ jobIdx = 0
while ($jobIdx < $jobCount)
@ valPos = ($jobIdx * $ztagLen) + $ztagValPos
set jobName=$jobNames[$valPos]
set jobStatus=`p4 -ztag jobs -e "Job=$jobName" | grep '^... Status'`
if ($jobStatus[$ztagValPos] =~ open) then
@ openCount++
endif
@ jobIdx++
end
endif
if ( $openCount == 0 ) then
echo "Changelist #($changelist) has no open jobs associated with it." >> $ERR_MSG_FILE
echo "YoU must associate your changelist with at least one open job before submitting it." >> $ERR_MSG_FILE
else
echo "submitting changelist #$changelist against $jobCount job ticket(s) - $openCount of which is/are still open." > /dev/null
endif