Skip to content

Instantly share code, notes, and snippets.

@pjaspers
Created August 3, 2012 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save pjaspers/4cf99c91eefc6d325d2c to your computer and use it in GitHub Desktop.
Save pjaspers/4cf99c91eefc6d325d2c to your computer and use it in GitHub Desktop.
Propane helper to colorize build output messages.
// This scans the chat for messages containing build information (think CI)
//
// All messages starting with "Build #" and containing successfull will be
// green, anything other with "Build #" will be red
//
//
Campfire.BuildColorizer = Class.create({
initialize: function(chat) {
this.chat = chat;
var messages = this.chat.transcript.messages;
for (var i = 0; i < messages.length; i++) {
this.detectBuildMessage(messages[i]);
}
},
detectBuildMessage: function(message) {
if (!message.pending() && message.kind === 'text') {
var body = message.bodyElement();
var text = message.bodyElement().innerText;
var match = text.match(/^Build #/);
if (!match) return;
var successMatch = text.match(/successful/);
if (successMatch) {
body.setAttribute("style", "color: green;");
} else {
body.setAttribute("style", "color: red;");
}
}
},
onMessagesInsertedBeforeDisplay: function(messages) {
for (var i = 0; i < messages.length; i++) {
this.detectBuildMessage(messages[i]);
}
},
onMessageAccepted: function(message, messageID) {
this.detectBuildMessage(message);
}
});
Campfire.Responders.push("BuildColorizer");
window.chat.installPropaneResponder("BuildColorizer", "buildcolorizer");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment