hubeye 0.2.5 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  #Hubeye
2
2
  <br />
3
3
  Keep track of repositories on Github, get notified when they change and<br />
4
- (optionally) run local system commands when new commits come in to Github.<br />
4
+ (optionally) run local system commands when new commits get pushed to certain
5
+ repositories.<br />
5
6
  <br />
6
7
 
7
8
  Hubeye is composed of a client and server. Once the server is run,<br />
@@ -11,15 +12,22 @@ prompted by a '>'. Type the name of a Github repository.
11
12
  Example: (what the user enters is preceded by the prompt)
12
13
 
13
14
  >hubeye
14
- commit 77b82b54044c16751228
15
- tree 8ce18af1461b5c741003
16
- parent ea63fe317fe58dff1c95
17
- log tracking info for repos on client quit => luke-gru
15
+ log tracking info for repos on client quit
16
+ => luke-gru
18
17
 
19
- What you see is the latest commit reference, tree reference and parent<br />
20
- commit reference on Github for that repository. Note that the user did<br />
21
- not type a username. This is because the user defined a username in his<br />
22
- ~/.hubeye/hubeyerc file.
18
+ What you see is the latest commit msg and committer for that repository.<br />
19
+ Note that the user did not type a username. This is because she defined <br />
20
+ a username in her ~/.hubeye/hubeyerc file.
21
+
22
+ Once a repo is in the watch list, typing it again will go and see if it has
23
+ changed.
24
+
25
+ >hubeye
26
+ Repository luke-gru/hubeye has not changed.
27
+
28
+ If, however, luke-gru/hubeye was pushed to since she last typed it in, <br />
29
+ it will tell her that there have been changes, and what the new commit <br />
30
+ message is.
23
31
 
24
32
  ##Starting Hubeye
25
33
 
@@ -35,11 +43,11 @@ your terminal (on <b>t</b>op):
35
43
 
36
44
  >hubeye -st
37
45
 
38
- Hubeye runs on port 2000 be default. Change the port like this:
46
+ Hubeye runs on port 4545 by default. Change the port like this:
39
47
 
40
48
  >hubeye -sp 9001
41
49
 
42
- To connect with the client:
50
+ To connect using the client:
43
51
 
44
52
  >hubeye -c
45
53
 
@@ -58,7 +66,7 @@ should be a valid Github username.
58
66
 
59
67
  ###Keeping track of repositories
60
68
 
61
- Hubeye doesn't actually track any repositories unless you disconnect<br />
69
+ Hubeye doesn't actually enter its tracking loop unless you disconnect<br />
62
70
  from the server and leave the server running. This can be done by:
63
71
 
64
72
  >quit
@@ -69,38 +77,44 @@ It can keep track of as many repos as you want; just keep typing<br />
69
77
  them in. If Hubeye finds a change to a repo, it will notify you of the<br />
70
78
  changes using your Desktop notification system (libnotify, growl). It will<br />
71
79
  also log the changes to your $HOME/.hubeye/log file. If the server is run<br />
72
- in a terminal (-t option), the changes will also be logged to the terminal.<br
73
- />
80
+ in a terminal (-t option), the changes will also be logged to the terminal.<br />
74
81
 
75
- To track your own repository, start the client in the root directory<br />
82
+ Note that since the server is still running, you can connect to it using the<br />
83
+ client any time to add more repos to track, or to check the current commits.
84
+
85
+ To track your own repository, start the <i>client</i> in the root directory<br />
76
86
  of your local git repo:
77
87
 
78
88
  >.
79
89
 
80
90
  This only works if a <i>username</i> is added to the hubeyerc, and if the<br />
81
- Github repository name is the same as the local root directory name.<br />
82
- ie: '.' put in '/home/luke/code/hubeye' would track https://www.github.com/
83
- luke-gru/hubeye<br />
84
- if <i>username</i> was set to luke-gru.<br />
91
+ Github repository name is the same as the basename of $PWD<br />
92
+ ie: '.' put in '/home/luke/code/hubeye' would track https://www.github.com/luke-gru/hubeye
93
+ if <i>username</i> were set to luke-gru.<br />
85
94
 
86
95
  You can add another user's repo like this:
87
96
 
88
97
  >rails/rails
89
98
 
90
- This adds https://github.com/rails/rails to the watch list.<br />
99
+ This adds <b>https://github.com/rails/rails</b> to the watch list.<br />
91
100
  Hubeye does not remove a repo from the watch list unless explicitly<br />
92
101
  told to do so:
93
102
 
94
103
  >rm luke-gru/hubeye
95
104
 
96
- To see a list of all repos (with recent commit messages) in the watch (track) list:
105
+ To see a list of all repos that Hubeye is tracking:
97
106
 
98
107
  >tracking
99
108
 
109
+ To see a more detailed list, including commit messages:
110
+
111
+ >tracking -d
112
+
100
113
  ###Desktop Notification
101
114
  <i>On Linux: install libnotify-bin. On Mac: install growl (if not already installed).<br />
102
- The autotest gem is needed for Desktop notification to work in both
103
- cases.</i><br />
115
+ The autotest gem is needed for Desktop notification to work with growl.<br />
116
+ Desktop notification is currently untested with growl, so please send error reports if<br />
117
+ you have any problems, or fork Hubeye and help out!</i>
104
118
 
105
119
  ###Shutting down and persistence between sessions
106
120
 
@@ -119,23 +133,22 @@ A way to interactively save all currently tracked repositories:
119
133
 
120
134
  >save repos as my_work_repos
121
135
 
122
- And then load any time (even after a shutdown; next session, next week, etc...)
136
+ And then load them any time (even after a shutdown, next session, next week, etc...)
123
137
 
124
138
  >load repos my_work_repos
125
139
 
140
+ This puts the repository names in the watch list with their most recent commits,
141
+ not the commits that were being tracked when you saved the repos.
142
+
126
143
  ###Working with hooks
127
144
 
128
145
  >hook add rails/rails dir: /path/to/local/rails cmd: git pull origin master
129
146
 
130
- When <b>https://www.github.com/rails/rails</b> changes, a process will start,
131
- <br />
132
- change to the selected directory and execute the command. The <i>(dir: /my/dir)
133
- <br />
134
- </i> part is optional, and when ignored won't change directories. In this
135
- case,
136
- <br />
137
- the directory will be where the hubeye server was originally
138
- started from.<br />
147
+ When <b>https://www.github.com/rails/rails</b> changes, a process will start, <br />
148
+ change to the selected directory and execute the command. The <i>(dir: /my/dir)</i><br />
149
+ part is optional, and when ignored won't change directories. In that case,<br />
150
+ the directory in which the command is executed will be where the Hubeye server<br />
151
+ was originally started.<br />
139
152
 
140
153
  To see all currently loaded hooks:
141
154
 
@@ -149,8 +162,7 @@ Then, next weekend:
149
162
 
150
163
  >load hooks weekend_projects_hooks
151
164
 
152
- These hooks, of course, will only really do anything if the repositories they
153
- <br />
165
+ These hooks, of course, will only really do anything if the repositories they <br />
154
166
  are hooked to are currently being watched. This is not done automatically.
155
167
 
156
168
  ###All ~/.hubeyerc configurations
@@ -159,31 +171,27 @@ When the server is started, the options are set here.
159
171
 
160
172
  username: luke-gru
161
173
  track: username/reponame, username2/reponame2, myreponame
162
- oncearound = 90
174
+ oncearound: 90
163
175
  load hooks: myhook1, myworkhooks
164
176
  load repos: workprojects, funprojects
165
- desktop notification: on/off
177
+ desktop notification: on
166
178
 
167
- <i>username</i>: username used for Github URLS when the full path is not
168
- given<br />
169
- inside of the client.<br />
179
+ <i>username</i>: username used for Github URLS when the full path is not <br />
180
+ given inside of the client <br />
170
181
 
171
182
  <i>track</i>: default repositories to watch for changes upon server start<br />
172
183
 
173
- <i>oncearound</i>: number of seconds before completing a check of every repo in<br />
174
- the watch list for changes<br />
184
+ <i>oncearound</i>: number of seconds before completing a check of every repo in <br />
185
+ the watch list for changes <br />
175
186
 
176
- <i>load hooks</i>: load hooks on server start. To see how to save hooks in the
177
- <br />
178
- client, see the <i>Working with hooks</i> section<br />
187
+ <i>load hooks</i>: load hooks on server start. To see how to save hooks in the <br />
188
+ client, see the <i>Working with hooks</i> section <br />
179
189
 
180
- <i>load repos</i>: load repos on server start. To see how to save repos in the
181
- <br />
190
+ <i>load repos</i>: load repos on server start. To see how to save repos in the <br />
182
191
  client, see the <i>Shutting down and persistence between sessions</i> section.
183
192
  <br />
184
193
 
185
- <i>desktop notification</i>: whether to notify of repo changes using libnotify
186
- <br />
194
+ <i>desktop notification</i>: whether to notify of repo changes using libnotify <br />
187
195
  or growl. This is set to <i>on</i> by default. However, if no notification<br />
188
- system is found, it is ignored.
196
+ system is found, it is ignored. Set it to <i>off</i> if you don't want it.
189
197
 
data/VERSION.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class Hubeye
2
- # 0.2.5 since Dec. 4, 2011
3
- VERSION = [0,2,5]
2
+ # 0.2.7 since Dec. 4, 2011
3
+ VERSION = [0,2,7]
4
4
  end
5
5
 
data/bin/hubeye CHANGED
@@ -12,7 +12,7 @@ require 'ostruct'
12
12
  unless File.exists?(File.join(ENV['HOME'],'.hubeye'))
13
13
  require 'rake'
14
14
 
15
- require File.join(ROOTDIR, 'tasks/install')
15
+ require File.join(ROOTDIR, 'tasks', 'install')
16
16
  Rake.application['install'].invoke
17
17
  end
18
18
 
@@ -83,7 +83,7 @@ class Hubeye
83
83
  daemonized = options.server_daemonized
84
84
  if options.server_wanted
85
85
  unless port_open?(port)
86
- puts "Other instances are running"
86
+ puts "A service is already running on this port"
87
87
  exit 1
88
88
  end
89
89
  require File.join(LIBDIR, 'server', 'hubeye_server')
@@ -91,15 +91,17 @@ class Hubeye
91
91
  start_server(port, :daemon => true) :
92
92
  start_server(port, :daemon => false)
93
93
  else
94
+ ['INT', 'KILL'].each do |sig|
95
+ trap(sig) { STDOUT.puts; exit 1 }
96
+ end
94
97
  require File.join(LIBDIR, 'client', 'hubeye_client')
95
98
  start_client(host, port)
96
99
  end
97
100
  end
98
101
 
99
-
100
102
  def port_open?(port)
101
- # this is the solution until multi-threading or forking is implemented
102
- # on the TCP server
103
+ # will change this to a more platform-agnostic method, like
104
+ # rescuing busy port exceptions.
103
105
  listening_tcps = `netstat -l --tcp --numeric`
104
106
  if /#{port}/ =~ listening_tcps
105
107
  return false
@@ -107,7 +109,6 @@ class Hubeye
107
109
  true
108
110
  end
109
111
 
110
-
111
112
  def start_server(port, options={})
112
113
  server = HubeyeServer.new(true) # debug: true
113
114
  if options[:daemon]
@@ -62,11 +62,15 @@ class HubeyeClient
62
62
  STDOUT.print '> '
63
63
  STDOUT.flush
64
64
  local = STDIN.gets
65
- if local.match(/^\.$/) # '.' = pwd
66
- # Send the line to the server, daemons gem strips some special chars (/, :)
67
- @s.puts(local.gsub(/\A\.\Z/, "pwd" + Dir.pwd.split('/').last))
68
- else
69
- @s.puts(local.gsub(/\//, 'diiv'))
65
+ begin
66
+ if local.match(/^\.$/) # '.' = pwd
67
+ # Send the line to the server, daemons gem strips some special chars (/, :)
68
+ @s.puts(local.gsub(/\A\.\Z/, "pwd" + Dir.pwd.split('/').last))
69
+ else
70
+ @s.puts(local.gsub(/\//, 'diiv'))
71
+ end
72
+ rescue Errno::EPIPE
73
+ exit 1
70
74
  end
71
75
  @s.flush
72
76
  if local =~ /load repo/
@@ -80,7 +84,6 @@ class HubeyeClient
80
84
  rescue EOFError
81
85
  response = "Bye!"
82
86
  end
83
-
84
87
  if response.chop.strip == "Bye!"
85
88
  puts response.chop
86
89
  @s.close
data/lib/log/logger.rb CHANGED
@@ -1,35 +1,37 @@
1
- class Logger
2
- LOG_DIR = File.join(ENV['HOME'], '.hubeye', 'log')
1
+ module Log
2
+ class Logger
3
+ LOG_DIR = File.join(ENV['HOME'], '.hubeye', 'log')
3
4
 
4
- def self.log(msg)
5
- File.open(LOG_DIR, "a") do |f|
6
- f.puts(msg)
5
+ def self.log(msg)
6
+ File.open(LOG_DIR, "a") do |f|
7
+ f.puts(msg)
8
+ end
7
9
  end
8
- end
9
10
 
10
- def self.relog(msg)
11
- #wipe the file and start anew
12
- File.open(LOG_DIR, "w") do |f|
13
- f.puts(msg)
11
+ def self.relog(msg)
12
+ #wipe the file and start anew
13
+ File.open(LOG_DIR, "w") do |f|
14
+ f.puts(msg)
15
+ end
14
16
  end
15
- end
16
17
 
17
- # If {include_terminal: true}, log to the terminal too (make sure that the
18
- # process is not daemonized). Always log to the logfile.
18
+ # If {include_terminal: true}, log to the terminal too (make sure that the
19
+ # process is not daemonized). Always log to the logfile.
19
20
 
20
- def self.log_change(repo_name, commit_msg, committer, options={})
21
- opts = {:include_terminal => false}.merge options
22
- change_msg = <<-MSG
23
- ===============================
24
- Repository: #{repo_name.downcase.strip} has changed (#{Time.now.strftime("%m/%d/%Y at %I:%M%p")})
25
- Commit msg: #{commit_msg}
26
- Committer : #{committer}
27
- ===============================
28
- MSG
29
- if opts[:include_terminal]
30
- STDOUT.puts change_msg
21
+ def self.log_change(repo_name, commit_msg, committer, options={})
22
+ opts = {:include_terminal => false}.merge options
23
+ change_msg = <<-MSG
24
+ ===============================
25
+ Repository: #{repo_name.downcase.strip} has changed (#{Time.now.strftime("%m/%d/%Y at %I:%M%p")})
26
+ Commit msg: #{commit_msg}
27
+ Committer : #{committer}
28
+ ===============================
29
+ MSG
30
+ if opts[:include_terminal]
31
+ STDOUT.puts change_msg
32
+ end
33
+ log(change_msg)
31
34
  end
32
- log(change_msg)
33
- end
34
35
 
36
+ end
35
37
  end
@@ -1,5 +1,9 @@
1
1
  module Notification
2
2
 
3
+ dir = File.dirname(__FILE__)
4
+ CHANGE_ICON = "change_icon.jpg"
5
+ CHANGE_ICON_PATH = File.expand_path(File.join(dir, "..", "images", CHANGE_ICON))
6
+
3
7
  class Finder
4
8
 
5
9
  def self.find_notify
@@ -46,7 +50,7 @@ module Notification
46
50
  end
47
51
  end
48
52
  if defined? Autotest
49
- return true
53
+ true
50
54
  end
51
55
  end
52
56
 
@@ -62,7 +66,7 @@ module Notification
62
66
  end
63
67
  end
64
68
  if defined? Autotest
65
- return true
69
+ true
66
70
  end
67
71
  end
68
72
  end
@@ -1,11 +1,12 @@
1
- module Autotest::GnomeNotify
1
+ module Notification
2
+ module GnomeNotify
2
3
 
3
- EXPIRATION_IN_SECONDS = 2
4
- CHANGE_ICON = File.join(File.expand_path("images", ::Environment::ROOTDIR), "change_icon.jpg")
4
+ EXPIRATION_IN_SECONDS = 2
5
5
 
6
- def self.notify(title, msg, img=CHANGE_ICON)
7
- options = "-t #{EXPIRATION_IN_SECONDS * 1000} -i #{img}"
8
- system "notify-send #{options} '#{title}' '#{msg}'"
9
- end
6
+ def self.notify(title, msg, img=CHANGE_ICON_PATH)
7
+ options = "-t #{EXPIRATION_IN_SECONDS * 1000} -i #{img}"
8
+ system "notify-send #{options} '#{title}' '#{msg}'"
9
+ end
10
10
 
11
+ end
11
12
  end
@@ -1,11 +1,12 @@
1
- module Autotest::Growl
1
+ module Autotest
2
+ module Growl
2
3
 
3
- EXPIRATION_IN_SECONDS = 2
4
- dir = File.dirname(__FILE__)
5
- CHANGE_ICON = File.expand_path(dir + "/../images/change_icon.jpg")
4
+ EXPIRATION_IN_SECONDS = 2
5
+ IMG = ::Notification::CHANGE_ICON_PATH
6
6
 
7
- def self.growl(title, msg, img=CHANGE_ICON, pri=0, stick="")
8
- system "growlnotify -n autotest --image #{img} -p #{pri} -m #{msg.inspect} #{title} #{stick}"
9
- end
7
+ def self.growl(title, msg, img=IMG, pri=0, stick="")
8
+ system "growlnotify -n autotest --image #{img} -p #{pri} -m #{msg.inspect} #{title} #{stick}"
9
+ end
10
10
 
11
+ end
11
12
  end
@@ -1,3 +1,6 @@
1
+ require "log/logger"
2
+ include Log
3
+
1
4
  class Hubeye
2
5
 
3
6
  # simple interface to Github's api v3 for commits
@@ -53,8 +56,7 @@ class Hubeye
53
56
  require 'open-uri'
54
57
  # hubeye
55
58
  require "config/parser"
56
- require "log/logger"
57
- require "notification/notification"
59
+ require "notification/finder"
58
60
  require "hooks/git_hooks"
59
61
  require "hooks/executer"
60
62
  require "helpers/time"
@@ -110,6 +112,11 @@ class Hubeye
110
112
  opts = {:internal_input => nil}.merge options
111
113
  if !opts[:internal_input]
112
114
  @input = server.socket.gets
115
+ # check if the client pressed ^C or ^D
116
+ if @input.nil?
117
+ @server.remote_connection = false
118
+ throw(:invalid_input)
119
+ end
113
120
  @input.chop!
114
121
  else
115
122
  @input = opts[:internal_input]
@@ -174,7 +181,7 @@ class Hubeye
174
181
  @sockets.delete(@socket)
175
182
  @socket.close
176
183
  unless @server.daemonized
177
- STDOUT.puts "Shutdown gracefully."
184
+ STDOUT.puts "Shutting down gracefully."
178
185
  end
179
186
  exit 0
180
187
  end
@@ -534,8 +541,10 @@ EOS
534
541
  look_for_changes unless @remote_connection
535
542
  end
536
543
  client_connect(@sockets) if waiting
537
- strategy = Strategy.new(self)
538
- strategy.call
544
+ catch(:invalid_input) do
545
+ strategy = Strategy.new(self)
546
+ strategy.call
547
+ end
539
548
  @session.cleanup
540
549
  end
541
550
  end
@@ -564,7 +573,7 @@ EOS
564
573
  end
565
574
  rescue
566
575
  @socket.puts "Not a Github repository name"
567
- return
576
+ throw(:invalid_input)
568
577
  end
569
578
  new_info =
570
579
  {full_repo_name =>
@@ -602,6 +611,13 @@ EOS
602
611
  def setup_env(options={})
603
612
  @daemonized = options[:daemon]
604
613
  @sockets = [@server] # An array of sockets we'll monitor
614
+ ['INT', 'KILL'].each do |sig|
615
+ trap(sig) do
616
+ @sockets.each {|s| s.close}
617
+ STDOUT.puts
618
+ exit 1
619
+ end
620
+ end
605
621
  @session = Session.new
606
622
  unless CONFIG[:default_track].nil?
607
623
  CONFIG[:default_track].each do |repo|
@@ -665,7 +681,7 @@ EOS
665
681
  "#{commit_msg}\n=> #{committer}"
666
682
  case CONFIG[:desktop_notification]
667
683
  when "libnotify"
668
- Autotest::GnomeNotify.notify("Hubeye", change_msg)
684
+ Notification::GnomeNotify.notify("Hubeye", change_msg)
669
685
  Logger.log_change(full_repo_name, commit_msg, committer)
670
686
  when "growl"
671
687
  Autotest::Growl.growl("Hubeye", change_msg)
@@ -680,7 +696,6 @@ EOS
680
696
  # execute any hooks for that repository
681
697
  unless @session.hooks.nil? || @session.hooks.empty?
682
698
  if hooks = @session.hooks[full_repo_name]
683
- hooks = hooks.dup
684
699
  hooks.each do |dir,cmds|
685
700
  # execute() takes [commands], {options} where
686
701
  # options = :directory and :repo
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hubeye
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -32,7 +32,7 @@ files:
32
32
  - lib/client/hubeye_client.rb
33
33
  - lib/notification/growl.rb
34
34
  - lib/notification/gnomenotify.rb
35
- - lib/notification/notification.rb
35
+ - lib/notification/finder.rb
36
36
  - lib/server/hubeye_server.rb
37
37
  - lib/hooks/executer.rb
38
38
  - lib/hooks/git_hooks.rb