#!/usr/bin/perl
#
# dtg_trigger.pl
#
# Copyright (c) 2009, Perforce Software, Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. 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.
#
# Trigger script to insert a 'DTG_URL:' field into a Perforce job
# created when P4DTG replicates a Bugzilla bug to Perforce.
# The field will contain the URL for the Bugzilla bug id.
#
# Modify the variable $bugzilla_url_stem to match the stem of the Bugzilla URL
# on your site.
#
# Add a trigger specification similar to this, replacing the path as
# appropriate:
#
# jobId form-in job "/path-to-your-triggers/dtg_trigger.pl %formfile%"
#
#
$formfile = $ARGV[0]; # from %formfile% in trigger table
$modifiedform = "";
$found_dtg_url = 0;
$bugzilla_url_stem = "http://your_host/cgi-bin/bugzilla3/show_bug.cgi?id=";
open FORM, $formfile or die "Trigger couldn't read form tempfile";
while ( <FORM> )
{
###### Check in here for the DTG_DTISSUE fields ######
if ( /^DTG_DTISSUE:\s*(\d+)/ ) {
$lastfield .= "\n\nDTG_URL:\t$bugzilla_url_stem$1\n\n";
}
if ( /^DTG_URL:/ ) {
$found_dtg_url = 1;
}
$modifiedform .= $_;
}
if ( $found_dtg_url == 0 ) {
$modifiedform .= $lastfield;
}
# Write the modified spec back to the %formfile%,
open MODFORM, ">$formfile" or die "Couldn't write form tempfile";
print MODFORM $modifiedform;
exit 0;