-
-
Save pjaspers/4cf99c91eefc6d325d2c to your computer and use it in GitHub Desktop.
Propane helper to colorize build output messages.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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