Skip to content
Browse files

Added command to fetch current ticket info from Lighthouse

  • Loading branch information...
1 parent da15271 commit 617c2b1d69bc4fa87e273e28714870adb00f691d @dennmart committed Sep 11, 2011
Showing with 63 additions and 2 deletions.
  1. +5 −0 config.js
  2. +5 −1 index.js
  3. +52 −0 lib/lighthouse.js
  4. +1 −0 lib/miscelaneous.js
  5. +0 −1 lib/pivotal.js
View
5 config.js
@@ -24,4 +24,9 @@ config.pivotal = {};
config.pivotal.token = ""; // Pivotal Tracker API token
config.pivotal.project_id = ""; // Project ID you want to get info from (https://www.pivotaltracker.com/projects/<projectid>)
+// Lighthouse settings
+config.lighthouse = {};
+config.lighthouse.token = ""; // Lighthouse Token (generated from your user profile)
+config.lighthouse.project_id = ""; // Project ID you want to get info from (https://something.lighthouseapp.com/projects/<projectid>)
+
module.exports = config;
View
6 index.js
@@ -6,7 +6,8 @@ var happyHour = require("./lib/happy_hour.js"),
weather = require("./lib/weather.js"),
hudson = require("./lib/hudson.js"),
analytics = require("./lib/google_analytics.js"),
- pivotal = require("./lib/pivotal.js");
+ pivotal = require("./lib/pivotal.js"),
+ lighthouse = require("./lib/lighthouse.js");
require('sugar');
client.room(config.campfire.room_id, function (room) {
@@ -38,6 +39,9 @@ client.room(config.campfire.room_id, function (room) {
// Displays information about the current iteration from Pivotal Tracker.
} else if (msg.match(/pivotal current/i)) {
pivotal.currentIteration(room);
+ // Displays ticket information for current milestone from Lighthouse.
+ } else if (msg.match(/lighthouse tickets/i)) {
+ lighthouse.currentMilestone(room);
// Shows all the commands available to rpbot.
} else if (msg.match(/commands/i)) {
misc.listCommands(room);
View
52 lib/lighthouse.js
@@ -0,0 +1,52 @@
+var config = require("../config");
+var https = require('https'),
+ querystring = require('querystring'),
+ xml2js = require('xml2js');
+
+exports.currentMilestone = function(room) {
+ var params = querystring.stringify({
+ 'q': 'milestone:next state:open', // Only get current tickets in the new, open and committed states.
+ 'limit': 1000 // Just using a big enough number to fetch all tickets and not need any pagination.
+ });
+
+ var httpsOptions = {
+ host: 'repairpal.lighthouseapp.com',
+ port: 443,
+ path: '/projects/' + config.lighthouse.project_id + '/tickets.xml?' + params,
+ headers: {
+ 'X-LighthouseToken': config.lighthouse.token
+ }
+ };
+
+ var getRequest = https.get(httpsOptions, function(res) {
+ res.setEncoding('utf8');
+
+ res.on('data', function (chunk) {
+ parser.parseString(chunk);
+ });
+
+ res.on('error', function(e) {
+ console.log(e);
+ room.speak("There was an error getting the ticket info from Lighthouse. Try again later.");
+ });
+ });
+
+ var parser = new xml2js.Parser();
+ parser.addListener('end', function(result) {
+ var totalTickets = 0;
+ var ticketOwners = [];
+ var message = "";
+ var tickets = result.ticket;
+
+ tickets.each(function(ticket) {
+ ticketOwners.add(ticket['assigned-user-name']);
+ });
+
+ message += "Remaining tickets in Lighthouse - Current Milestone (new, open and committed states):\n\n";
+ ticketOwners.unique().each(function(name) {
+ message += name + " - " + ticketOwners.count(name) + " tickets\n";
+ });
+
+ room.paste(message);
+ });
+};
View
1 lib/miscelaneous.js
@@ -9,6 +9,7 @@ exports.listCommands = function(room) {
commands += " gi joe Gets a random GI Joe PSA YouTube video\n";
commands += " ie7 usage Gets the percentage of Internet Explorer 7 usage from Google Analytics\n";
commands += " pivotal current Displays stats of the current iteration from Pivotal Tracker\n";
+ commands += " lighthouse tickets Displays stats of open tickets in current milestone from Lighthouse\n";
commands += " commands You're looking at it...\n";
room.paste(commands);
};
View
1 lib/pivotal.js
@@ -1,6 +1,5 @@
var config = require("../config");
var https = require('https'),
- querystring = require('querystring'),
xml2js = require('xml2js');
exports.currentIteration = function(room) {

0 comments on commit 617c2b1

Please sign in to comment.
Something went wrong with that request. Please try again.