Skip to content

Instantly share code, notes, and snippets.

@phoet
Created August 6, 2011 15:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phoet/1129441 to your computer and use it in GitHub Desktop.
Save phoet/1129441 to your computer and use it in GitHub Desktop.
tci
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!
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
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
interval: 60
remote: "http://travis-ci.org/"
repos:
- "phoet/asin"
- "phoet/hamburg_on_ruby"
@razielgn
Copy link

razielgn commented Aug 8, 2011

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

@tdavydik
Copy link

tdavydik commented Aug 8, 2011

Wow, it's awesome!

@phoet
Copy link
Author

phoet commented Aug 8, 2011

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

@joshk
Copy link

joshk commented Aug 8, 2011

@phoet

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

@phoet
Copy link
Author

phoet commented Aug 8, 2011

@joshk will do!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment