#!/usr/bin/env ruby =begin ======================================================================= # TORK-NOTIFY 1 2016-02-13 20.0.1 ## NAME tork-notify - notifies you of test status changes ## SYNOPSIS `tork-notify` [*OPTION*]... ## DESCRIPTION This program serves as an example of how to receive and process messages sent by the various programs in the tork(1) suite. It notifies you when previously passing tests fail (or vice versa) through libnotify, xmessage, or growl. If none are available on your system, then the notification is printed to stdout. ## OPTIONS `-h` [*PATTERN*], `--help` [*PATTERN*] Show this help manual and optionally search for *PATTERN* regular expression. ## EXIT STATUS See tork-remote(1). ## SEE ALSO tork-remote(1), tork-engine(1) =end ========================================================================= $0 = File.basename(__FILE__) # for easier identification in ps(1) output require 'binman' BinMan.help require 'json' IO.popen('tork-remote tork-engine', 'r+') do |remote| while message = remote.gets event, test_file, *details = JSON.load(message) # make notifications edge-triggered: pass => fail or vice versa. # we do not care about pass => pass or fail => fail transitions. icon = case event.to_sym when :pass! then 'dialog-information' when :fail! then 'dialog-error' end if icon _, _, line_numbers, log_file = details.first title = [event.upcase, test_file].join(' ') statistics = File.readlines(log_file).grep(/^\d+ \w+,/).join. gsub(/\e\[\d+(;\d+)?m/, '') # strip ANSI SGR escape codes # run in background; see http://stackoverflow.com/q/16745840 Thread.new(icon, title, statistics) do |icon, title, statistics| system 'notify-send', '-i', icon, title, statistics or system 'growlnotify', '-a', 'Xcode', '-m', statistics, title or system 'xmessage', '-timeout', '5', '-title', title, statistics or puts title, statistics, nil end end end end exit $?.exitstatus