Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: e8cf5ca2df
...
compare: 6c30b31466
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 4 files changed
  • 0 commit comments
  • 2 contributors
Commits on Mar 19, 2012
@dzello dzello Allow user to exclude notifications for stories by an author.
As the second argument to kilt-install the user can specify the name of
an author to not get notifications for (likely yourself). The name must
match the exact name of the author in Pivotal Tracker.

Made a few changes in the spec due to expectations not failing when
:system was stubbed and also had a should_receive on it.
363f427
Commits on Mar 25, 2012
@dzello dzello Use growlnotify's wait flag to determine if a notification was clicked.
And take an action accordingly.
8175cf2
Commits on Mar 26, 2012
@dcrec1 Merge pull request #9 from dzello/master
Make Growl notifications clickable; skip notifications from yourself
6c30b31
Showing with 61 additions and 32 deletions.
  1. +7 −7 bin/kilt-app
  2. +1 −1  bin/kilt-install
  3. +29 −7 lib/kilt.rb
  4. +24 −17 spec/kilt_spec.rb
View
14 bin/kilt-app
@@ -5,12 +5,12 @@ require 'yaml'
require 'kilt'
require 'win32/process' if RUBY_PLATFORM =~ /mswin|mingw|win32/
-fork do
- token = YAML.load_file(File.expand_path("~/.pivotal_tracker"))['token']
-
- Kilt.init token
+fork do
+ yaml = YAML.load_file(File.expand_path("~/.pivotal_tracker"))
- loop do
- sleep 5
- end
+ Kilt.init yaml['token'], yaml['skip_author']
+
+ loop do
+ sleep 5
+ end
end
View
2  bin/kilt-install
@@ -1,5 +1,5 @@
#!/usr/bin/env ruby
filename = File.expand_path "~/.pivotal_tracker"
-File.open(filename, 'w') { |file| file.write "token: #{ARGV.first}" }
+File.open(filename, 'w') { |file| file.write "token: #{ARGV.first}\nskip_author: #{ARGV[1]}\n" }
puts "Successful installed, execute kilt-app to start."
View
36 lib/kilt.rb
@@ -10,15 +10,16 @@ class Kilt
ICON = File.expand_path(File.join(File.dirname(__FILE__), '..', 'img', 'pivotal.png'))
- def self.init(token)
- new token
+ def self.init(token, skip_author=nil)
+ new(token, skip_author)
end
def update
activities = fetch_activities
activities.reverse.each do |activity|
- if activity['id'] > @id.to_i
- notify_about activity['description']
+ if activity['id'] > @id.to_i && activity['author'] != @skip_author
+ activity['stories'] and activity['stories'][0] and (id = activity['stories'][0]['id'])
+ notify_about activity['description'], id
end
end
update_id_from activities
@@ -26,8 +27,9 @@ def update
protected
- def initialize(token)
+ def initialize(token, skip_author)
@token = token
+ @skip_author = skip_author
update_id_from fetch_activities
Rufus::Scheduler.start_new.every('30s') { update }
end
@@ -43,16 +45,36 @@ def fetch_activities
'X-TrackerToken' => @token).body)['activities']
end
- def notify_about(message)
+ def notify_about(message, id=nil)
title = 'Pivotal Tracker'
case RUBY_PLATFORM
when /linux/
system "notify-send '#{title}' '#{message}' --icon #{Kilt::ICON}"
when /darwin/
- system "growlnotify -t '#{title}' -m '#{message}' --image #{Kilt::ICON}"
+ if defined?(NO_FORK)
+ osx_notify(title, message, id)
+ else
+ # fork here so that the child process can wait for a click, but
+ # the main process can continue to display notifications
+ # growlnotify bug - the user must click within 10 seconds for the process
+ # to return "successfully" - see:
+ # http://groups.google.com/group/growldiscuss/browse_thread/thread/9b5af76d3c1667d9
+ fork do
+ osx_notify(title, message, id)
+ exit
+ end
+ end
when /mswin|mingw|win32/
Snarl.show_message title, message, Kilt::ICON
end
end
+ def osx_notify(title, message, id)
+ system "growlnotify -t -w -s '#{title}' -m '#{message}' --image #{Kilt::ICON}"
+ # if the return code is greater than 0 it was clicked before 10s
+ # only handle the click its a valid tracker id
+ if id and $?.to_i > 0
+ system "open https://www.pivotaltracker.com/story/show/#{id}"
+ end
+ end
end
View
41 spec/kilt_spec.rb
@@ -26,20 +26,21 @@
end
it "should fetch new activities" do
- @scheduler.stub(:every) do |time, block|
- block.call
- end
+ @scheduler.stub(:every) {}
RestClient.should_receive(:get).exactly(2).times do
mock(Object, :body => latests_activities)
end
- Kilt.init 'fegegege'
+
+ @client = Kilt.init 'fegegege'
+ @client.stub!(:system)
+ @client.update
end
end
context "on update" do
before :each do
@client = Kilt.init('fake')
- @client.stub! :system
+ @client.stub!(:system)
@client.instance_variable_set "@id", '25906311'
end
@@ -49,26 +50,32 @@
end
it "should notifify about each new activity" do
- @client.should_receive(:system).exactly(2).times
+ @client.should_receive(:notify_about).exactly(2).times {}
+ @client.update
+ end
+
+ it "should not notify a notification who's author matches skip_author" do
+ @client.instance_variable_set "@skip_author", 'Superman'
+ @client.should_receive(:notify_about).exactly(1).times {}
@client.update
end
context "on os x" do
before :all do
- silence_warnings { RUBY_PLATFORM = "darwin" }
+ silence_warnings { RUBY_PLATFORM = "darwin"; NO_FORK = "yep" }
end
-
+
it "should notify growl calling growlnotify with 'Pivotal Tracker' as the name the application, the author and the action" do
- regexp = /growlnotify -t \'Pivotal Tracker\' -m \'\S+. finished lorem ipsum\' --image \S+.pivotal\.png/
- @client.should_receive(:system).with(regexp)
+ regexp = /growlnotify -t -w -s \'Pivotal Tracker\' -m \'\S+. finished lorem ipsum\' --image \S+.pivotal\.png/
+ @client.should_receive(:system).with(regexp).twice {}
@client.update
end
it "should notify newer activities at least" do
- regexp = /growlnotify -t \'Pivotal Tracker\' -m \'SpongeBog finished lorem ipsum\' --image \S+.pivotal\.png/
- regexp2 = /growlnotify -t \'Pivotal Tracker\' -m \'Superman finished lorem ipsum\' --image \S+.pivotal\.png/
- @client.should_receive(:system).with(regexp).ordered
- @client.should_receive(:system).with(regexp2).ordered
+ regexp = /growlnotify -t -w -s \'Pivotal Tracker\' -m \'SpongeBog finished lorem ipsum\' --image \S+.pivotal\.png/
+ regexp2 = /growlnotify -t -w -s \'Pivotal Tracker\' -m \'Superman finished lorem ipsum\' --image \S+.pivotal\.png/
+ @client.should_receive(:system).with(regexp).ordered {}
+ @client.should_receive(:system).with(regexp2).ordered {}
@client.update
end
end
@@ -80,15 +87,15 @@
it "should notify libnotify calling notify-send with 'Pivotal Tracker' as the name the application, the author and the action" do
regexp = /notify-send \'Pivotal Tracker\' \'\S+. finished lorem ipsum\' --icon \S+.pivotal\.png/
- @client.should_receive(:system).with(regexp)
+ @client.should_receive(:system).with(regexp).twice {}
@client.update
end
it "should notify newer activities at least" do
regexp = /notify-send \'Pivotal Tracker\' \'SpongeBog finished lorem ipsum\' --icon \S+.pivotal\.png/
regexp2 = /notify-send \'Pivotal Tracker\' \'Superman finished lorem ipsum\' --icon \S+.pivotal\.png/
- @client.should_receive(:system).with(regexp).ordered
- @client.should_receive(:system).with(regexp2).ordered
+ @client.should_receive(:system).with(regexp).ordered {}
+ @client.should_receive(:system).with(regexp2).ordered {}
@client.update
end
end

No commit comments for this range

Something went wrong with that request. Please try again.