Skip to content

Instantly share code, notes, and snippets.

@deckerego
Created December 6, 2013 22:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deckerego/7832895 to your computer and use it in GitHub Desktop.
Save deckerego/7832895 to your computer and use it in GitHub Desktop.
Converts a Subversion log to an RSS feed.
#!/bin/sh
MONITOR_PATHS='trunk'
FILE_DIR="$HOME/.svntorss"
XSLT_FILE="$HOME/Documents/Scripts/svnlog.xslt"
REPOSITORY="https://svn/svn/repos"
MAX_RESULTS=20
for MONITOR_PATH in $MONITOR_PATHS; do
SVN_URL="$REPOSITORY/$MONITOR_PATH"
FILE_NAME=`echo "$MONITOR_PATH" | sed 's/\//_/'`
RSS_FILE="$FILE_DIR/$FILE_NAME.rss"
svn log "$SVN_URL" --limit "$MAX_RESULTS" -v --xml | xsltproc "$XSLT_FILE" - > "$RSS_FILE"
done
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:date="http://exslt.org/dates-and-times" xmlns:func="http://exslt.org/functions" xmlns:str="http://exslt.org/strings" extension-element-prefixes="date func str" version="1.0">
<!--
svnlog.xslt by Martin Pittenauer / TheCodingMonkeys
Web: www.codingmonkeys.de, Mail: map@codingmonkeys.de
iso->rfc822 date conversion code heavily inspired by Steven Engelhardt (http://www.deez.info/sengelha/)
Tested with libxslt.
-->
<xsl:output omit-xml-declaration="no" indent="yes" encoding="UTF-8" method="xml" />
<xsl:template match="log">
<rss version="2.0">
<channel>
<title>SVN: SVN Repository</title>
<link>https://svn/viewvc/</link>
<description>svn commit log</description>
<language>en-us</language>
<copyright>2007</copyright>
<generator>svnlog.xslt</generator>
<xsl:apply-templates select="logentry" />
</channel>
</rss>
</xsl:template>
<xsl:template match="logentry">
<item>
<title>Revision <xsl:value-of select="@revision"/> by <xsl:value-of select="author" /></title>
<pubDate>
<xsl:call-template name="rfc822">
<xsl:with-param name="isodate" select="date" />
</xsl:call-template>
</pubDate>
<!-- Accoring to RSS 2.0 specs, author has to be an rfc822 valid email address -->
<author><xsl:value-of select="author" />@localhost</author>
<description disable-output-escaping="yes">&lt;div style="white-space:pre"&gt;<xsl:value-of select="msg" />&lt;/div&gt;&lt;br/&gt;
(&lt;em&gt;<xsl:call-template name="rfc822">
<xsl:with-param name="isodate" select="date" />
</xsl:call-template>&lt;/em&gt;)&lt;br/&gt;&lt;br/&gt;
&lt;table&gt;<xsl:apply-templates select="paths/path" />&lt;/table&gt;
</description>
</item>
</xsl:template>
<xsl:template match="paths/path">
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;<xsl:call-template name="svncommand"><xsl:with-param name="command" select="@action" /></xsl:call-template>&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&amp;nbsp;&lt;a href="https://svn/viewvc<xsl:value-of select="."/>"&gt;<xsl:value-of select="."/>&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
</xsl:template>
<xsl:template name="rfc822">
<xsl:param name="isodate" />
<xsl:variable name="dayOfWeek" select="date:day-abbreviation($isodate)" />
<xsl:variable name="day" select="date:day-in-month($isodate)" />
<xsl:variable name="monthAbbr" select="date:month-abbreviation($isodate)" />
<xsl:variable name="year" select="date:year($isodate)" />
<xsl:variable name="hour" select="date:hour-in-day($isodate)" />
<xsl:variable name="minute" select="date:minute-in-hour($isodate)" />
<xsl:variable name="second" select="round(date:second-in-minute($isodate))" />
<xsl:value-of select="$dayOfWeek" />
<xsl:text>, </xsl:text>
<xsl:value-of select="$day" />
<xsl:text> </xsl:text>
<xsl:value-of select="$monthAbbr" />
<xsl:text> </xsl:text>
<xsl:value-of select="$year" />
<xsl:choose>
<xsl:when test="$hour and $minute and $second">
<xsl:text> </xsl:text>
<xsl:value-of select="str:align($hour, '00', 'right')" />
<xsl:text>:</xsl:text>
<xsl:value-of select="str:align($minute, '00', 'right')" />
<xsl:text>:</xsl:text>
<xsl:value-of select="str:align($second, '00', 'right')" />
<xsl:text> GMT</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text> 00:00:00 GMT</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="svncommand">
<xsl:param name="command"/>
<xsl:choose>
<xsl:when test="$command = 'A'">Added</xsl:when>
<xsl:when test="$command = 'D'">Deleted</xsl:when>
<xsl:when test="$command = 'M'">Modified</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment