Now a small but cool thing. How to get an Atom feed out of a svn commit log? That's pretty easy because svn may output logfiles as XML and because Atom is valid XML too we may use a simple XSLT script to do the job
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8" indent="yes" />
<xsl:template match="text()|@*" />
<xsl:template match="log">
<feed xmlns="http://www.w3.org/2005/Atom">
<title>KDEmod SVN Commit log</title>
<link href="http://kdemod.ath.cx/"/>
<link rel="self" href="http://kdemod.ath.cx/feed.xml"/>
<updated><xsl:value-of select="logentry/date" /></updated>
<author>
<name>KDEmod Team</name>
<email>funkyou@kdemod.ath.cx</email>
<uri>http://kdemod.ath.cx/</uri>
</author>
<id>http://kdemod.ath.cx/</id>
<xsl:apply-templates />
</feed>
</xsl:template>
<xsl:template match="logentry">
<entry xmlns="http://www.w3.org/2005/Atom">
<id>Revision: <xsl:value-of select="@revision" /></id>
<title type="text">
SVN Commit from <xsl:value-of select="author" />
(<xsl:value-of select="count(paths/path)" /> files affected)
</title>
<published><xsl:value-of select="date" /></published>
<author>
<name><xsl:value-of select="author" /></name>
</author>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<h1>SVN Commit from <xsl:value-of select="author" /></h1>
<xsl:apply-templates />
</div>
</content>
<link rel="alternate" href="http://kdemod.ath.cx/news.html" />
</entry>
</xsl:template>
<xsl:template match="paths">
<p xmlns="http://www.w3.org/1999/xhtml"><h2>Files:</h2>
<ul>
<xsl:apply-templates />
</ul></p>
</xsl:template>
<xsl:template match="path">
<li xmlns="http://www.w3.org/1999/xhtml">
<xsl:if test="@action = 'M'">(modified) </xsl:if>
<xsl:if test="@action = 'A'">(added) </xsl:if>
<xsl:if test="@action = 'D'">(deleted) </xsl:if>
<a>
<xsl:attribute name="href">http://kdemod.ath.cx/svn<xsl:value-of select="." /></xsl:attribute>
<xsl:value-of select="." />
</a>
</li>
</xsl:template>
<xsl:template match="msg">
<p xmlns="http://www.w3.org/1999/xhtml"><h2>Message:</h2>
<xsl:value-of select="." />
</p>
</xsl:template>
</xsl:stylesheet>
It's output not very pretty but it does it's work (you may change it as you want, just be sure to write valid XML). Call it as cron job like that:
svn log -v --xml http://kdemod.ath.cx/svn/ | sabcmd svn2atom.xsl >svn.xml
I am using the sablotron xslt processor here but every other one should do as well. (for example on my server I use xsltproc)
0 Kommentare:
Kommentar veröffentlichen