[hook-script] new pre-commit script to add bugzilla urls to log messages
Jon Bendtsen <[email protected]> Fri, 9 Sep 2005 14:10:58 +0200
| Newsgroups | gmane.comp.version-control.subversion.devel,gmane.mail.eyebrowse.user |
|---|---|
| Message-ID | <[email protected]> |
Hi whoever is interested. I have made a pre-commit hook script that adds bugzilla urls to log messages. It is a bash shell script, and it uses cut, sed, grep, echo, ... It works on my debian stable using subversion 1.2.0-1 from testing? This script CHANGES the props file in the transaction directory. It has 2 paramters, first the repository, next the transaction. From those parameters it finds the right props file, and starts to parse it. First it checks if the svn:log is the last of the svn: properties, if not, it aborts. 2. it checks if the extracted logmessage size and the log message size in the props file matches. If not, it aborts, because it extracted the log message wrong. 3. it parses the logmessage finds text and numbers starting with "bug " and any number comming after the word bug. Any non whitespace, commas, points, #, +, and alike aborts the search for more numbers. Any new "bug " restarts the search for numbers. One may specify more than one bug number seperated by space , . + # The bugnumber is appended to the bugurl and added to the logmessage. 4. finaly the new logmessage size is calculated and put into the props file. From here the commit proceeds as usual. The bugurl is specified in the top of the script JonB --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
pre-commit-bugzilla-fix.sh
(application/octet-stream, 3.1 KB)
#!/bin/bash
# replace this url with the address to your bugzilla, or possibly
# some other bug management system.
bugzillaurl='http://frodo/cgi-bin/bugzilla/show_bug.cgi?id='
cd "$1/db/transactions/$2"*
if [ -e props ]; then
true
else
echo "uh oh, there is no props file"
exit 0
fi
svnlog=$(grep "^svn:log$" props)
if [ "$svnlog" == "" ]; then
echo "uh oh, there is no svn:log property"
exit 0
fi
findsvnproperties=$(grep -A1 "^svn:" props | tail -2)
isitsvnlog=$(echo $findsvnproperties | sed "s/^svn:log V [0-9]*//")
if [ "$isitsvnlog" != "" ]; then
echo "uh oh, svnlog is not the last thing, we exit"
exit 0
fi
# the codegroup above is to make sure that we can cut from the
# svn:log line to the END line in the props file.
newpropsfile=$(tempfile)
wheredoesthelogstart=$(grep -n "^svn:log$" props | cut -d":" -f1)
cat props | sed "$wheredoesthelogstart,\$ d" >> $newpropsfile
echo "svn:log" >> $newpropsfile
# The codegroup above copies the beginning of the old propsfile.
log=$(tempfile)
oldlogsize=$(echo $findsvnproperties | sed "s/^svn:log V //")
cat props | sed -e "1,$wheredoesthelogstart d" -e "$ d" | sed -e "1 d" -e "$ d" >> $log
if [ "$oldlogsize" -ne "$(wc -c $log | cut -d" " -f1)" ]; then
echo "uh of, the specified logsize and the calculated logsize differs, we exit"
exit 0
fi
# the code above is just an extra precausion to avoid changes if
# the logsize specified in the props file and the extracted logsize
# does not match. The reason is that if there is a match, the log
# was extracted right from the props file, but if the size differs,
# then the extraction of the log message was wrong, and we want to
# avoid trashing the props file
# This could possible catch future changes to the props file.
tf=$(tempfile)
echoornot="false"
for ord in $(cat $log | sed -e "s/[,|\.|#|*|+]/ /g"); do
if [ "$echoornot" == "true" ]; then
tal=$(echo $ord | tr -d 0-9)
if [ "$tal" == "" ]; then
echo $bugzillaurl$ord >> $tf
else
echoornot="false"
fi
fi
bugornot=$(echo "$ord" | tr A-Z a-z)
if [ "$bugornot" = "bug" ]; then
echoornot="true"
fi
done
anybugs=$(wc -l $tf | cut -d" " -f1)
if [ "$anybugs" -gt "0" ]; then
echo "" >> $log
echo "Automatic parsed bugzilla - MAY be incorrect:" >> $log
cat $tf >> $log
fi
# the codegroup above adds bugzilla urls to the logmessage if
# any bug numbers was found. The code should catch any sort of
# specification with one or more bug numbers. The committer must
# write something along "fix of bug 83434" or "fixes bug #344834, 98434"
# it does NOT work if one writes the word "and" between the 2
# bug numbers.
newlogsize=$(wc -c $log | cut -d" " -f1)
echo "V $newlogsize" >> $newpropsfile
# now we calculate the new logmessage size and update it in the
# props file. The reason is that since the size is in the file,
# someone might need it for other scripts, or possibly subversion
# itself checks if the size and the log message fits.
cat $log >> $newpropsfile
echo "" >> $newpropsfile
echo "END" >> $newpropsfile
cat $newpropsfile > props
rm $newpropsfile $tf $log
exit 0