Skip to content

Instantly share code, notes, and snippets.

@codec
Created January 26, 2012 09:33
Show Gist options
  • Save codec/1681957 to your computer and use it in GitHub Desktop.
Save codec/1681957 to your computer and use it in GitHub Desktop.
JIRA Activity Stream script for Hubot - posts new stream activity to your jabber conference
FeedParser = require('feedparser')
ent = require('ent')
{EventEmitter} = require('events')
class ActivityStream extends EventEmitter
constructor: (@url, @robot) ->
@robot.logger.info("ActivityStream for #{@url}")
self = this
self.guid = "urn:uuid:a1c4b672-fc6d-3a82-8522-0e05350297de"
@on 'guid', (guid) ->
self.guid = guid
@on 'activities', (activities) ->
activities.forEach (activity) ->
if activity.guid is self.guid
activities.splice(activities.indexOf(activity), activities.length-activities.indexOf(activity))
activities.reverse()
activities.forEach (activity) ->
sendto =
type: 'groupchat'
room: '[email protected]'
self.robot.send sendto, "#{activity.title} <#{activity.link}>#{activity.description()}\n"
if activities.indexOf(activity) is activities.length-1
self.emit 'guid', activity.guid
parse: (articles) ->
activities = []
articles.forEach (article) ->
activity =
title: ent.decode(article.title.replace(/<(?:.|\n)*?>/gm, '').replace(/\ \ \ /, ' '))
description: ->
if article.description != null
"\n" + ent.decode(article.description.replace(/<(?:.|\n)*?>/gm, '').replace(/\ \ \ /, ' '))
else
""
link: article.link
guid: article.guid
activities.push activity
@emit 'activities', activities
module.exports = (@robot) ->
parser = new FeedParser
stream = new ActivityStream "https://hubot:[email protected]/activity?maxResults=10&streams=key+IS+EXAMPLE&os_authType=basic",
@robot
parser.on 'end', (articles) ->
stream.parse articles
parser._reset
run = (stream, parser) ->
parser.parseUrl(stream.url)
setInterval (-> run stream, parser), 30000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment