Improving your bug tracking process
We’re running mantis at work. Each customer project gets a private project, developers are assigned to categories, customers are invited. Everything flows just fine.
Then one day it struck me – what if the developer is away for a week and the customer files an urgent bug report… Who gets notified? The answer is: The developer who isn’t there.
A simple solution is to force all project managers to check on their projects every day to make sure reports don’t fall between chairs. There are two things wrong with that solution imho:
* It’s error prone as it assumes people will always do what they are told and never forget.
* It doesn’t entail a single piece of new technology…
As I already had some scripts doing data extraction from the mantis database I figured something along the following would work:
* For each project; list all managers with an internal email address.
* For each project, select new bugs and list them with some info about the bug.
* Send the bug reports to the managers for the project.
Sounds easy enough, doesn’t it.
Here’s the script to get all the project managers
-
-
SELECT
-
project.id, project.name, user.email, userlist.`access_level`
-
FROM
-
`mantis_project_user_list_table` AS userlist,
-
mantis_user_table AS user,
-
mantis_project_table AS project
-
WHERE
-
user.id = userlist.user_id AND
-
project.id = userlist.project_id AND
-
userlist.`access_level` > 55 AND
-
(user.email LIKE "%mydomain.tld" OR user.email LIKE "%.myotherdomain.tld")
-
ORDER BY
-
project.name
-
Save it as projectmanagers.sql
Worth noting is the filtering on email addresses. In some cases we assign manager rights to the project champion on the customer side. Yu may or may not want them to get the bug report email. Your call.
Here’s a shell script to get the list and then call an awk script to do the rest.
-
-
#!/bin/sh
-
-
#
-
#Written by Jesper Hogstrom 2008
-
#
-
-
#This will change depending on where your installation of mantis resides
-
mantisconfig=/var/www/mantis-1.1.2/config_inc.php
-
rootdir=`dirname $0`
-
-
function getconfig {
-
configoption=$1
-
cat ${mantisconfig}| \
-
grep -v ‘^#’|\
-
grep ${configoption}| \
-
awk -F = ‘{print $2}’| \
-
awk ‘{print substr($1,2,length($1)-3)}’
-
}
-
-
#Note that all these options MUST be set in config_inc.php!!
-
db_user=`getconfig g_db_username`
-
db_password=`getconfig db_password`
-
db_database=`getconfig g_database_name`
-
#db_host=`getconfig g_hostname` – currently not used, default is localhost
-
mantisbaseurl=`getconfig g_path`
-
-
function executesql {
-
sql=$1
-
cat $sql|mysql -u$db_user -p$db_password -D$db_database –skip-column-names
-
}
-
-
executesql ${rootdir}/projectmanagers.sql > /tmp/projman
-
#cat /tmp/projman
-
awk -f ${rootdir}/bugreports.awk \
-
–assign=db_user=${db_user} \
-
–assign=db_password=${db_password} \
-
–assign=db_database=${db_database} \
-
–assign=rootdir=${rootdir} \
-
–assign=mantisbaseurl=${mantisbaseurl////\\\\/} \
-
/tmp/projman
-
-
Save it as bugreports and make it executable with chmod +x bugreports
There are some things worth noting:
* I specify the path to the mantis configuration file. This is to avoid having to specify the db credentials twice. I guess I could have extracted the php-variables using php, but I don’t know much php. This works, assuming you formatted your config_inc.php file in a reasonable way.
* The bulk of the work is obviously done elsewhere. You do know about awk, don’t you?
* Getting the slashes right in mantisbaseurl took a few minutes
Here comes the awk script.
-
-
#Written by Jesper Hogstrom 2008
-
BEGIN {
-
FS="\t";
-
mailfile="/tmp/mantismail";
-
sqltemp="/tmp/mantissql";
-
sqlscript=rootdir "/bugreports.rsql"
-
}
-
{
-
#For debugging purposes, name each file differently.
-
mailfile="/tmp/mantismail_" $1 "_" NR;
-
print "Investigating " $2 " (" $1 ") for " $3
-
-
# Refresh the script file to pick out only the current project
-
print mantisbaseurl
-
system("sed -e ’s/PROJNUM/" $1 "/g’ -e ’s/BASEURL/" mantisbaseurl "/g’ " sqlscript " > " sqltemp);
-
-
# Preparing mail
-
print "To: " $3 > mailfile
-
print "Subject: New bug reports for " $2 >> mailfile
-
system("cat " sqltemp "|mysql -u" db_user " -p" db_password " -D" db_database " –skip-column-names >> " mailfile);
-
-
-
#Don’t send empty emails
-
linecount=0
-
while ((getline line < mailfile) > 0)
-
linecount+=1
-
close(mailfile)
-
-
# Send mail
-
if (linecount > 2)
-
{
-
print " – Found " linecount – 2 " bugs to send."
-
system("cat " mailfile " | sendmail -t " $3);
-
}
-
}
-
-
Save it as bugreports.awk
This script will operate on all lines in the /tmp/projman file (with all the project managers in it) and do the following:
* Replace some stuff in a file named bugreports.rsql using sed.
* Put mail headers in a text file
* Execute the expanded sql-file and put the result in the text file that makes up the mail
* Could the number of lines in the mail
* If there are any lines above and beyond the headers, send the mail to the manager.
-
-
SELECT
-
concat(bug.id, " (BASEURL/view.php?id=", bug.id, ")") AS "bug#",
-
project.name,
-
username AS owner,
-
severity,
-
date(date_submitted),
-
datediff(now(), date_submitted) AS "age (days)",
-
summary
-
-
FROM
-
mantis_bug_table AS bug,
-
mantis_user_table AS user,
-
mantis_project_table AS project
-
WHERE
-
project_id IN (PROJNUM) AND
-
resolution = 10 AND
-
datediff(now(), date_submitted) < 5 AND
-
user.id = handler_id AND
-
project.id = project_id
-
ORDER BY
-
datediff(now(), date_submitted);
-
Save it as bugreports.rsql
This will select all bugs in status new (i.e. resolution = 10) that are younger than 5 days and come from a project with the number PROJNUM. We actually use sed to replace PROJNUM with the actual project id and also BASEURL with the g_path variable in config_inc.php.
The mail you send will look something like
123 (http://mydomain.tld/mantis/view.php?id=123) Project_1 \ developer1 70 2008-10-09 1 \ System stops when power cord is removed. 148 (http://http://mydomain.tld/mantis/view.php?id=148) Project_1 \ developer2 50 2008-10-08 2 \ Saving big images consumes a lot of disk.
I put line breaks in there manually
I admit it could be done somewhat more glitzy with fireworks and images and what have you. However, it’s merely a status report and there is no need to add more – possibly the column headers.
The scripts make very few assumptions about how you have configured things. Feel free to change what doesn’t suit you (like age of bugs, status, who gets mail).
I run my script nightly by symlinking it to /etc/cron.daily.
–Jesper Högström