A jira notification system for irc using camel

Last week, I thought that it would be a nice idea to have JIRA notifications for our Apache projects on IRC (for projects that sometimes use an IRC channel). So I came up with a very simple solution using Camel deployed on top of Karaf.

The application itself consists in a single xml file to be copied in the deploy folder of your Karaf installation. This was one of my requirements for ease of maintenance. This is possible because of the nice hot deployment mechanism for spring xml applications in Karaf.

Now, if you log onto the #camel, #cxf, #servicemix or #activemq IRC channels, you'll see some messages that look like:


jirabot: Claus Ibsen - Created: (CAMEL-2090) camel-jms -
Option autoStartup does not work
(see https://issues.apache.org/activemq/browse/CAMEL-2090 )


Those are all generated by the following applications:


<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
">

<manifest>
DynamicImport-Package=*
</manifest>

<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="imaps://imap.gmail.com:993?username=xxx&amp;password=xxx&amp;consumer.delay=1000&amp;delete=false" />
<convertBodyTo type="java.lang.String"/>
<!-- Remove any cr/lf that would cause regexp to not work -->
<setHeader headerName="tmpsubject">
<mvel>
request.headers.subject.replaceAll("\r\n", " ").replaceAll("\r|\n", "")
</mvel>
</setHeader>
<!-- Extract the user name from the from header -->
<setHeader headerName="tmpfrom">
<mvel>
request.headers.from.replaceAll(".*\"(.*)\".*", "$1").replace("(JIRA)", "")
</mvel>
</setHeader>
<choice>
<!-- Camel -->
<when>
<mvel>
request.headers.tmpsubject.matches(".*jira.*(CAMEL-[0-9]+).*")
</mvel>
<setHeader headerName="irc.target">
<constant>#camel</constant>
</setHeader>
<setHeader headerName="issuelink">
<mvel>
" (see https://issues.apache.org/activemq/browse/" +
request.headers.tmpsubject.replaceAll(".*jira.*(CAMEL-[0-9]+).*", "$1") +
" )"
</mvel>
</setHeader>
</when>
<!-- other projects filtering using the exact same mechanism -->
<!-- Other non jira emails -->
<otherwise>
<setBody><mvel>
request.headers.from + ": " + request.headers.tmpsubject
</mvel></setBody>
<setHeader headerName="irc.target">
<constant>#jirabot.test</constant>
</setHeader>
</otherwise>
</choice>
<setBody>
<mvel>
request.headers.tmpfrom + "- " +
request.headers.tmpsubject.replace("[jira]", "") +
request.headers.issuelink
</mvel>
</setBody>
<to uri="irc:irc.codehaus.org/?nickname=jirabot&username=jirabot" />
</route>
</camelContext>

</beans>


This has been a small and enjoyable exercise. Camel rocks!

Comments

Anonymous said…
Big thanks for this! Really helped me..

Popular posts from this blog

Apache Karaf

Camel Endpoint DSL

ActiveMQ Pooling