HOWTO: Send CVSTrac Ticket Updates


As regular visitors will know, I use CVSTrac to organize most of my development efforts. A customized instance was integrated into this site, another holds a Web-based to-do list for my own consumption and yet another keeps track of internal developments my previous group did for over a year now.

I've been meaning to customize ticket notifications for a while now, and today I finally got around to hacking a quick Perl script using CPAN:MIME::Lite to send a nice (but simple) HTML mail with ticket change notifications to both the ticket owner and the requestor.


You need to know your way around systems, debug Perl (to change a few things in the script according to your install) and generally know what you're doing. An HTML-tolerant mailer and reasonable eyesight will also help in actually viewing the results.

Without further ado, here's the script (which could be prettier, but I'm thinking of expanding it a bit later on - hence the reliance on Getopt and my usual Hungarian Notation variable names):

use MIME::Lite;
use POSIX;
use Getopt::Long;


if( @ARGV > 0 ) {
  GetOptions( 'a|assigned=s'    => \$gszAssignedMail,
              'n|name=s'        => \$gszAssignedName,
              'c|contact=s'     => \$gszContact,
              'd|description=s' => \$gszDescription,
              'i|ticket=s'      => \$gszTicketNumber,
              'p|project=s'     => \$gszProject,
              'r|remarks=s'     => \$gszRemarks,
              's|status=s'      => \$gszStatus,
              't|title=s'       => \$gszTitle,
              'u|changed=s'     => \$gszChanged,
              'o|originator=s'  => \$gszOriginator,
              'y|type=s'        => \$gszType );
$gszTime = POSIX::strftime("%a, %m %d %H:%M", localtime);

  $szBuffer = <<EOT;
BODY, P, TD, TH { background-color: white; font-size: 10px;
                  font-family: Arial, Helvetica, Sans-Serif; }
TH { text-align: left; font-size: 11px; background-color: #e0e0e0; }
PRE { font-family: Lucida Console, Monaco, Courier New, fixed; font-size: 10px; }
H1 { font-size: 18px; }
<h1>Ticket <a href="http://cvstrac/tktview?tn=$gszTicketNumber">#$gszTicketNumber</a> was updated by $gszChanged.</h1>
<table border=0 cellpadding=2 cellspacing=1 bgcolor="black" width="100%">
<tr><th>Title:</th><td width="100%">$gszTitle</td></tr>
  <th>Assigned to:</th>
    <a href="mailto:$gszAssignedMail">$gszAssignedName</a>
<tr><th colspan=2>Description:</th></tr>
<tr><td colspan=2><pre>$gszDescription</pre></td></tr>
<tr><th colspan=2>Remarks:</th></tr>
<tr><td colspan=2><pre>$gszRemarks</pre></td></tr>
Generated by at $gszTime<br>
<a href="http://cvstrac/tktview?tn=$gszTicketNumber">View Ticket</a>

$msg = new MIME::Lite
  From     => '[email protected]',
  To       => $gszContact,
  Cc       => $gszAssignedMail,
  Subject  => "[$gszProject tracker] Ticket $gszTicketNumber updated by $gszChanged",
  Type     => "text/html",
  Data     => $szBuffer;
$msg->attr( 'content-type.charset' => "ISO-8859-1" );

$msg->send( 'smtp', '');


To make it work, just plonk it somewhere (say /usr/local/bin) and configure the ticket change notification in CVSTrac to read (mind the \, it's there only to ensure readability here):

/usr/local/bin/ -n '%a' -a '%A' -c '%c' -d '%d' -i '%n' -p '%p' -r '%r' \
-s '%s' -t '%t' -u '%u' -y '%y' -o '%w'

And that's it.

This page is referenced in:

  • HOWTONov 18th 2006