CVS/Bugzilla Integration
UPDATED: Please check out version 2 of buglog at the end of this article. (added support for CVSWeb)
To begin, I dislike the term “integration” when talking about development tools. It has been abused by marketing drones (read:Rational) to the point of being nearly meaningless. My version control system is not “integrated” with my XML editor just because I save my documents in a repository. Similarly my sock is not integrated with my foot just because I pull it over my toes. But this is a losing battle, and this is closer to the real meaning of integration then most other examples. So I use the term here:
Previous Work
My mandatory “has this been done before” Google search turned up little. An outdated (and abandoned) Bugzilla fork CVSZilla was available. Numerous copies existed of the Bugzilla 2.16 documentation referencing using the email gateway. (without examples) But nothing really useful.
General Overview
For reasons outside the scope of this article, I did not want to set up the email gateway. Fortunately my Bugzilla and CVS servers (like I assume most people’s) reside on the same box. So instead of using the email gateway, I update the MySQL database directly.
CVS allows you to run arbitrary scripts via loginfo. The script I wrote commits that log information directly into the longdescs Buzilla table.
Configuring CVS loginfo
The “loginfo” file controls where “cvs commit” log information is sent. The first entry on a line is a regular expression which must match the directory that the change is being made to, relative to the $CVSROOT. If a match is found, then the remainder of the line is a filter program that should expect log information on its standard input. I pipe this to a shell script buglog.sh.
ALL (id; echo %{sVv}; cat) | $CVSROOT/CVSROOT/buglog.sh
Writing buglog.sh
This script should find all references to bugs and commit the log as a comment to each. The regular expression I wrote supports “bug #1″, “bug#1″ and “bug:1″.
OUTFILE=/tmp/$RANDOM
cat | tr -d "'" > $OUTFILE
#echo [buglog] here is our cvslog:
#cat $OUTFILE
for arg in `grep -o " ?(#|:)[0-9]*" $OUTFILE | tr -d bug|[#:]` do
# echo [buglog] found bug #$arg
mysql -ubugs -pbugs -e "insert into longdescs (bug_id,who,bug_when,thetext) \
values ('$arg','38',now(),'`cat $OUTFILE`');" bugs
done
rm $OUTFILE
You can see that several values are hard-coded into this script. You’ll need to customize the username and password for your database as well as the user_id for your pseudo CVS account in Bugzilla.
Future Work
I really should check to make sure the bug exists first, before I commit a log entry against it. And I need to protect against SQL injection attacks. But for a quick hack I’m pretty happy.
UPDATE: buglog2.sh
My new version of buglog now provides links to our instance of CVSweb. This way you can see not just what file changed, but have one-click access to the HTML diff between it and its previous version.
Additional update (11/30/2004): I’ve broken out the hard-coded variables, added case-insensitivity for the “bug #” comment and fixed a bug where the link pointed to a non-existent diff of a new CVS file.
Append this to loginfo:
ALL (cat) | $CVSROOT/CVSROOT/buglog2.sh %{sVv}
The code for buglog2.sh:
CVSWEB=http://somewhere.uni.verse/cgi-bin/cvsweb/
BUGZILLA_COMMENT_OWNER="38"
MYSQL_USER="bugzilla"
MYSQL_PASS="bugpasswd"
#IFS=" "
DIR=`echo $1 | sed -e "s/ .*//"`
COMMENT=`whoami`" "`echo commited: $1`"n"
for fn in $1; do
if [[ "$SOMEDIR" = "" ]] ; then
SOMEDIR=$fn
elif [[ `echo $fn | grep -o ",NONE"` == ",NONE" ]] ; then
COMMENT=$COMMENT" "`echo $CVSWEB$SOMEDIR/$fn | sed -e "s/,NONE.*//"`"n"
else
COMMENT=$COMMENT" "`echo $CVSWEB$SOMEDIR/$fn | sed -e "s/,/.diff?r1=/" | sed -e "s/,/&r2=/"`";f=hn"
fi
done
OUTFILE=/tmp/$RANDOM cat | tr -d "'" > $OUTFILE
for arg in `grep -o "<[Bb][Uu][Gg]> ?(#|:)[0-9]*" $OUTFILE | tr -d [Bb][Uu][Gg]|[#:]` do
mysql -u$MYSQL_USER -p$MYSQL_PASS -e "insert into longdescs (bug_id,who,bug_when,thetext) \
values ('$arg','$BUGZILLA_COMMENT_OWNER',now(),'$COMMENT');" bugs
echo [buglog] updating bug #$arg
done
rm $OUTFILE








October 29th, 2008 at 9:09 pm
OUTFILE=/tmp/$RANDOM cat | tr -d “‘” > $OUTFILE
cat | ..
should have cat ..?? what is it ..??
Please reply…