Posts Tagged ‘subversion’

Update: hacks repository

Tuesday, July 28th, 2009

I decided to move the svn-tools repository inside hacks.

Svn Feed & Svn-tools

Monday, June 1st, 2009

Here is a new script for the subversion post-commit hooks.
It creates a rss feed containing information about the latest commit of collection of repositories.

#!/usr/bin/env bash

DESTINATION="/var/www/hacks/svn-feed"
ENTRIES="$DESTINATION/entries"
RSS="$DESTINATION/feed.xml"

TITLE='MLDB: Svn RSS'
LINK='http://matteolandi.no-ip.org/svn-browse'
DESCRIPTION='RSS feeds of the commits'
LAST_BUILD_DATE="`date -R`"

if [ $# -lt 2 ]; then
        printf "Usage: $0 path revision\n"
        exit 1
fi

REPO="$1"
PROJECT="`basename $REPO`"
REVISION=$2
OLD=$(( $REVISION - 1 ))

TEMP="`mktemp`"

printf "$PROJECT\n" >> $TEMP
svn log file://"$REPO" -r $REVISION >> $TEMP
cat $ENTRIES >> $TEMP
mv $TEMP $ENTRIES

printf "\n" > $RSS
printf "\n" >> $RSS
printf "\n" >> $RSS
printf "\n" >> $RSS
printf "
$LINK\n" >> $RSS
printf "$DESCRIPTION\n" >> $RSS
printf "$LAST_BUILD_DATE\n" >> $RSS

cat $ENTRIES | while read line; do
	repo="$line"
	read line
	read line
	revision=`echo $line | cut -d '|' -f 1 | tr -d ' r'`
	author=`echo $line | cut -d '|' -f 2 | tr -d ' '`
	day=`echo $line | cut -d '|' -f 3 | cut -d '(' -f 2 | cut -d ')' -f 1`
	time=`echo $line | cut -d '|' -f 3 | cut -d ' ' -f 3,4`
	pub_date="$day $time"
	lines=`echo $line | cut -d '|' -f 4 | tr -d ' lines'`
	read line

	printf "\n" >> $RSS
	printf "\n" >> $RSS
	printf "$author\n" >> $RSS
	printf "
$pub_date\n" >> $RSS
	printf "" >> $RSS
	while read line; do
		printf "$line\n" >> $RSS

		lines=$(( $lines - 1 ))
		if [ $lines -eq 0 ]; then
			break
		fi
	done
	printf "\n" >> $RSS
	printf "\n" >> $RSS

	read line
done

printf "\n" >> $RSS
printf "\n" >> $RSS

I decided to create a repository to collect these svn-hacks: track them under the name svn-tools.

Svn Notify

Sunday, May 24th, 2009

Have you ever needed to configure subversion in order to send mails containing details about the latest commit?
Well on the net you can find a lot of scripts useful for this purpose, but i decided to write my own one in order to make it as simple as possible!
External packages needed: nc (netcat).

#!/usr/bin/env bash

SERVER=smtp.tiscali.it
DOMAIN=tiscali.it

if [ $# -lt 3 ]; then
	printf "Usage: $0 path revision address1 address2 ..\n"
	exit 1
fi

REPO="$1"
PROJECT="`basename $REPO`"
FROM="notify-$PROJECT@mldb.net"
REVISION=$2
OLD=$(( $REVISION - 1 ))
shift
shift

MESSAGE="`mktemp`"

printf "HELO $DOMAIN\n" >> $MESSAGE
printf "MAIL FROM: <$FROM>\n" >> $MESSAGE
for i; do
	printf "RCPT TO: <$i>\n" >> $MESSAGE
done
printf "DATA\n" >> $MESSAGE
printf "From: MLDB Commit Notify <$FROM>\n" >> $MESSAGE
printf "To: " >> $MESSAGE
for i; do
	printf "<$i>," >> $MESSAGE
done
printf "\n" >> $MESSAGE
printf "Subject: $PROJECT: revision $REVISION\n" >> $MESSAGE
printf "\n" >> $MESSAGE

svn log file://"$REPO" -r $REVISION >> $MESSAGE
svn diff file://"$REPO" -r $OLD:$REVISION >> $MESSAGE

printf ".\n" >> $MESSAGE
printf "QUIT\n" >> $MESSAGE

nc $SERVER 25 < $MESSAGE

rm $MESSAGE