Created
August 6, 2011 15:40
-
-
Save phoet/1129441 to your computer and use it in GitHub Desktop.
tci
This file contains hidden or 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
| ABOUT: | |
| small build monitor using MacRuby and Growl | |
| RUN: | |
| macruby tci.rb | |
| CONFIG: | |
| have a look at the tci.yml right now. | |
| user-preferences are coming! |
This file contains hidden or 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
| framework 'Cocoa' | |
| framework 'Foundation' | |
| class Growl | |
| def initialize(app, notifications, icon = nil) | |
| @application_name = app | |
| @application_icon = icon | |
| @notifications = notifications | |
| @default_notifications = notifications | |
| @center = NSDistributedNotificationCenter.defaultCenter | |
| send_registration! | |
| end | |
| def notify(notification, title, description, options = {}) | |
| dict = { | |
| :ApplicationName => @application_name, | |
| :NotificationName => notification, | |
| :NotificationTitle => title, | |
| :NotificationDescription => description, | |
| :NotificationPriority => options[:priority] || 0, | |
| :NotificationIcon => @application_icon.TIFFRepresentation, | |
| } | |
| dict[:NotificationSticky] = 1 if options[:sticky] | |
| @center.postNotificationName(:GrowlNotification, object:nil, userInfo:dict, deliverImmediately:false) | |
| end | |
| def send_registration! | |
| dict = { | |
| :ApplicationName => @application_name, | |
| :ApplicationIcon => @application_icon.TIFFRepresentation, | |
| :AllNotifications => @notifications, | |
| :DefaultNotifications => @default_notifications | |
| } | |
| @center.postNotificationName(:GrowlApplicationRegistrationNotification, object:nil, userInfo:dict, deliverImmediately:true) | |
| end | |
| end |
This file contains hidden or 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
| require "yaml" | |
| require "json" | |
| require "net/http" | |
| require 'growl' | |
| framework 'AppKit' | |
| IMAGE = 'tci.png' | |
| @config = File.open("tci.yml") { |file| YAML.load(file) } | |
| @interval = @config['interval'].to_f | |
| @repos = @config['repos'] | |
| @results = Hash.new({}) | |
| @queue = Dispatch::Queue.new('de.nofail') | |
| @growl = Growl.new('de.nofail.tci', ['notification'], NSImage.alloc.initWithContentsOfFile(IMAGE)) | |
| @timer = NSTimer.scheduledTimerWithTimeInterval(@interval, | |
| target: self, | |
| selector: 'refresh_results:', | |
| userInfo: nil, | |
| repeats: true) | |
| def setupMenu | |
| menu = NSMenu.new | |
| menu.initWithTitle 'tci' | |
| @repos.each do |repo| | |
| mi = NSMenuItem.new | |
| mi.title = repo | |
| mi.action = 'showStatus:' | |
| mi.target = self | |
| menu.addItem mi | |
| end | |
| mi = NSMenuItem.new | |
| mi.title = 'Reload' | |
| mi.action = 'refresh_results:' | |
| mi.target = self | |
| menu.addItem mi | |
| mi = NSMenuItem.new | |
| mi.title = 'Quit' | |
| mi.action = 'quit:' | |
| mi.target = self | |
| menu.addItem mi | |
| menu | |
| end | |
| def showStatus(sender) | |
| alert = NSAlert.new | |
| alert.messageText = "Build result for #{sender.title}" | |
| alert.informativeText = @results[sender.title] | |
| alert.alertStyle = NSInformationalAlertStyle | |
| alert.addButtonWithTitle("close") | |
| response = alert.runModal | |
| end | |
| def quit(sender) | |
| NSApplication.sharedApplication.terminate(self) | |
| end | |
| def refresh_results(timer) | |
| @repos.each do |repo| | |
| @queue.async do | |
| puts url = "#{@config['remote']}#{repo}.json" | |
| res = Net::HTTP.get_response(URI.parse(url)) | |
| result = JSON.parse(res.body) | |
| if @results[repo].empty? || (result['last_build_finished_at'] && @results[repo]['last_build_id'] != result['last_build_id']) | |
| @growl.notify('notification', repo, result['status']) | |
| @results[repo] = result | |
| puts "new build result, growl-notification for #{result}" | |
| else | |
| puts "result did not change, no growl-notification #{result}" | |
| end | |
| end | |
| end | |
| end | |
| app = NSApplication.sharedApplication | |
| status_bar = NSStatusBar.systemStatusBar | |
| status_item = status_bar.statusItemWithLength(NSVariableStatusItemLength) | |
| status_item.setMenu setupMenu | |
| img = NSImage.new.initWithContentsOfFile IMAGE | |
| status_item.setImage(img) | |
| refresh_results(nil) | |
| app.run |
This file contains hidden or 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
| interval: 60 | |
| remote: "http://travis-ci.org/" | |
| repos: | |
| - "phoet/asin" | |
| - "phoet/hamburg_on_ruby" |
Wow, it's awesome!
Author
i tried to finish the user preferences yesterday, but i had an issue with macruby (this might just be an issue with myself...)
http://stackoverflow.com/questions/6975325/no-input-to-nstextfield-when-running-macruby
Please please please ping me in #travis and lets talk about making this a full app which takes advantage of websockets. We can also build out the api and add authentication if need be!
I love where this is going!
<3 <3 <3
Author
@joshk will do!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

This is so cool. Can't wait to use it! :)