hubeye 0.3.3 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +59 -40
- data/VERSION.rb +2 -2
- data/bin/hubeye +7 -12
- data/lib/hubeye/client/client.rb +3 -5
- data/lib/hubeye/config/environment.rb +0 -1
- data/lib/hubeye/hooks/{executer.rb → command.rb} +8 -4
- data/lib/hubeye/hooks/git.rb +19 -0
- data/lib/hubeye/log/logger.rb +1 -0
- data/lib/hubeye/server/commit.rb +17 -39
- data/lib/hubeye/server/server.rb +79 -531
- data/lib/hubeye/server/session.rb +5 -32
- data/lib/hubeye/server/strategies/add_hook.rb +32 -0
- data/lib/hubeye/server/strategies/add_repo.rb +91 -0
- data/lib/hubeye/server/strategies/decision.rb +121 -0
- data/lib/hubeye/server/strategies/exit.rb +23 -0
- data/lib/hubeye/server/strategies/list_hooks.rb +38 -0
- data/lib/hubeye/server/strategies/list_tracking.rb +27 -0
- data/lib/hubeye/server/strategies/load_hook.rb +34 -0
- data/lib/hubeye/server/strategies/load_repo.rb +35 -0
- data/lib/hubeye/server/strategies/next.rb +13 -0
- data/lib/hubeye/server/strategies/rm_repo.rb +34 -0
- data/lib/hubeye/server/strategies/save_hook.rb +31 -0
- data/lib/hubeye/server/strategies/save_repo.rb +31 -0
- data/lib/hubeye/server/strategies/shutdown.rb +23 -0
- data/lib/hubeye/server/tracker.rb +89 -0
- data/tasks/install.rb +8 -9
- data/test/helpers/server.rb +39 -0
- metadata +19 -4
- data/lib/hubeye/hooks/git_hooks.rb +0 -19
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#Hubeye
|
2
|
+
|
2
3
|
<br />
|
3
4
|
Keep track of repositories on Github, get notified when they change and<br />
|
4
5
|
(optionally) run local system commands when new commits get pushed to certain
|
@@ -7,56 +8,56 @@ repositories.<br />
|
|
7
8
|
|
8
9
|
Hubeye is composed of a client and server. Once the server is run,<br />
|
9
10
|
you can connect to it via the client. Once connected, you'll be<br />
|
10
|
-
prompted by a '>'. Type the name of a Github repository.
|
11
|
+
prompted by a '>'. Type in the name of a Github repository.
|
11
12
|
|
12
13
|
Example: (what the user enters is preceded by the prompt)
|
13
14
|
|
14
|
-
>hubeye
|
15
|
+
> hubeye
|
15
16
|
log tracking info for repos on client quit
|
16
17
|
=> luke-gru
|
17
18
|
|
18
|
-
What you see is the latest commit
|
19
|
-
Note that
|
20
|
-
a username in
|
19
|
+
What you see is the latest commit message and committer for that repository.<br />
|
20
|
+
Note that we did not type a username. This is because we defined <br />
|
21
|
+
a username in our ~/.hubeye/hubeyerc file.
|
21
22
|
|
22
23
|
Once a repo is in the watch list, typing it again will go and see if it has
|
23
24
|
changed.
|
24
25
|
|
25
|
-
>hubeye
|
26
|
+
> hubeye
|
26
27
|
Repository luke-gru/hubeye has not changed.
|
27
28
|
|
28
|
-
If, however, luke-gru/hubeye was pushed to since
|
29
|
-
it
|
29
|
+
If, however, luke-gru/hubeye was pushed to since we last typed it in, <br />
|
30
|
+
it'll tell us that there have been changes, and what the new commit <br />
|
30
31
|
message is.
|
31
32
|
|
32
33
|
##Starting Hubeye
|
33
34
|
|
34
35
|
To start the server:
|
35
36
|
|
36
|
-
>hubeye -s
|
37
|
+
> hubeye -s
|
37
38
|
or just
|
38
39
|
|
39
|
-
>hubeye
|
40
|
+
> hubeye
|
40
41
|
|
41
42
|
This starts the server as a daemonized process. To run the server in<br />
|
42
|
-
your
|
43
|
+
your <b>t</b>erminal:
|
43
44
|
|
44
|
-
>hubeye -st
|
45
|
+
> hubeye -st
|
45
46
|
|
46
47
|
Hubeye runs on port 4545 by default. Change the port like this:
|
47
48
|
|
48
|
-
>hubeye -sp 9001
|
49
|
+
> hubeye -sp 9001
|
49
50
|
|
50
51
|
To connect using the client:
|
51
52
|
|
52
|
-
>hubeye -c
|
53
|
+
> hubeye -c
|
53
54
|
|
54
55
|
For more options:
|
55
56
|
|
56
|
-
>hubeye -h
|
57
|
+
> hubeye -h
|
57
58
|
|
58
59
|
|
59
|
-
|
60
|
+
##Basic ~/.hubeye/hubeyerc Configuration
|
60
61
|
|
61
62
|
username: luke-gru
|
62
63
|
|
@@ -64,20 +65,29 @@ This allows the user to type a repository name only, and to receive<br />
|
|
64
65
|
information regarding that <i>username</i>'s repository. The username<br />
|
65
66
|
should be a valid Github username.
|
66
67
|
|
67
|
-
|
68
|
+
##Keeping Track of Repositories
|
69
|
+
|
70
|
+
You can add another user's repo like this:
|
71
|
+
|
72
|
+
> rails/rails
|
73
|
+
or
|
74
|
+
> add rails/rails
|
75
|
+
|
76
|
+
If you want to add multiple repos at once, separated by spaces, use the<br />
|
77
|
+
<i>'add repo1 repo2'</i> syntax
|
68
78
|
|
69
79
|
Hubeye doesn't actually enter its tracking loop unless you disconnect<br />
|
70
80
|
from the server and leave the server running. This can be done by:
|
71
81
|
|
72
|
-
>quit
|
82
|
+
> quit
|
73
83
|
Bye!
|
74
84
|
|
75
|
-
If Hubeye has any repos to
|
85
|
+
If Hubeye has any repos to track, it will watch Github for changes.<br />
|
76
86
|
It can keep track of as many repos as you want; just keep typing<br />
|
77
87
|
them in. If Hubeye finds a change to a repo, it will notify you of the<br />
|
78
88
|
changes using your Desktop notification system (libnotify, growl). It will<br />
|
79
89
|
also log the changes to your $HOME/.hubeye/log file. If the server is run<br />
|
80
|
-
in a terminal (-t option), the changes will also be logged
|
90
|
+
in a terminal (-t option), the changes will also be logged there.<br />
|
81
91
|
|
82
92
|
Note that since the server is still running, you can connect to it using the<br />
|
83
93
|
client any time to add more repos to track, or to check the current commits.
|
@@ -85,30 +95,31 @@ client any time to add more repos to track, or to check the current commits.
|
|
85
95
|
To track your own repository, start the <i>client</i> in the root directory<br />
|
86
96
|
of your local git repo:
|
87
97
|
|
88
|
-
|
98
|
+
> .
|
89
99
|
|
90
100
|
This only works if a <i>username</i> is added to the hubeyerc, and if the<br />
|
91
101
|
Github repository name is the same as the basename of $PWD<br />
|
92
102
|
ie: '.' put in '/home/luke/code/hubeye' would track https://www.github.com/luke-gru/hubeye
|
93
103
|
if <i>username</i> were set to luke-gru.<br />
|
94
104
|
|
95
|
-
You can add another user's repo like this:
|
96
|
-
|
97
|
-
>rails/rails
|
98
105
|
|
99
106
|
This adds <b>https://github.com/rails/rails</b> to the watch list.<br />
|
100
107
|
Hubeye does not remove a repo from the watch list unless explicitly<br />
|
101
108
|
told to do so:
|
102
109
|
|
103
|
-
>rm luke-gru/hubeye
|
110
|
+
> rm luke-gru/hubeye
|
111
|
+
|
112
|
+
To remove all tracked repos, simply:
|
113
|
+
|
114
|
+
> rm -a
|
104
115
|
|
105
116
|
To see a list of all repos that Hubeye is tracking:
|
106
117
|
|
107
|
-
>tracking
|
118
|
+
> tracking
|
108
119
|
|
109
120
|
To see a more detailed list, including commit messages:
|
110
121
|
|
111
|
-
>tracking -d
|
122
|
+
> tracking -d
|
112
123
|
|
113
124
|
###Desktop Notification
|
114
125
|
<i>On Linux: install libnotify-bin. On Mac: install growl (if not already installed).<br />
|
@@ -116,9 +127,9 @@ The autotest gem is needed for Desktop notification to work with growl.<br />
|
|
116
127
|
Desktop notification is currently untested with growl, so please send error reports if<br />
|
117
128
|
you have any problems, or fork Hubeye and help out!</i>
|
118
129
|
|
119
|
-
###Shutting
|
130
|
+
###Shutting Down and Persistence Between Sessions
|
120
131
|
|
121
|
-
>shutdown
|
132
|
+
> shutdown
|
122
133
|
|
123
134
|
Next time you start up the server, the watch list will be empty<br />
|
124
135
|
(and so will the log file). In order to have a default watch list:
|
@@ -131,18 +142,18 @@ These will be watched automatically when starting up the server.<br />
|
|
131
142
|
|
132
143
|
A way to interactively save all currently tracked repositories:
|
133
144
|
|
134
|
-
>save repos as my_work_repos
|
145
|
+
> save repos as my_work_repos
|
135
146
|
|
136
147
|
And then load them any time (even after a shutdown, next session, next week, etc...)
|
137
148
|
|
138
|
-
>load repos my_work_repos
|
149
|
+
> load repos my_work_repos
|
139
150
|
|
140
151
|
This puts the repository names in the watch list with their most recent commits,
|
141
152
|
not the commits that were being tracked when you saved the repos.
|
142
153
|
|
143
|
-
###Working with
|
154
|
+
###Working with Hooks
|
144
155
|
|
145
|
-
>hook add rails/rails dir: /path/to/local/rails cmd: git pull origin master
|
156
|
+
> hook add rails/rails dir: /path/to/local/rails cmd: git pull origin master
|
146
157
|
|
147
158
|
When <b>https://www.github.com/rails/rails</b> changes, a process will start, <br />
|
148
159
|
change to the selected directory and execute the command. The <i>(dir: /my/dir)</i><br />
|
@@ -150,22 +161,30 @@ part is optional, and when ignored won't change directories. In that case,<br />
|
|
150
161
|
the directory in which the command is executed will be where the Hubeye server<br />
|
151
162
|
was originally started.<br />
|
152
163
|
|
164
|
+
If you want to call your own script with a hook and pass it the changed repo<br />
|
165
|
+
name, you can find the changed repo name by accessing <b>ENV['HUBEYE_CHANGED_REPO']</b><br />
|
166
|
+
in your script. Example:
|
167
|
+
|
168
|
+
> hook add rails/rails dir: /path/to/email/script cmd: ./email_me.rb
|
169
|
+
|
170
|
+
In <i>email_me.rb</i>, <b>ENV['HUBEYE_CHANGED_REPO']</b> will be <i>rails/rails</i>.
|
171
|
+
|
153
172
|
To see all currently loaded hooks:
|
154
173
|
|
155
|
-
>hook list
|
174
|
+
> hook list
|
156
175
|
|
157
176
|
To save all hooks for next sessions (after a server shutdown)
|
158
177
|
|
159
|
-
>save hooks as weekend_projects_hooks
|
178
|
+
> save hooks as weekend_projects_hooks
|
160
179
|
|
161
180
|
Then, next weekend:
|
162
181
|
|
163
|
-
>load hooks weekend_projects_hooks
|
182
|
+
> load hooks weekend_projects_hooks
|
164
183
|
|
165
184
|
These hooks, of course, will only really do anything if the repositories they <br />
|
166
185
|
are hooked to are currently being watched. This is not done automatically.
|
167
186
|
|
168
|
-
###All ~/.hubeyerc
|
187
|
+
###All ~/.hubeye/hubeyerc Configurations
|
169
188
|
|
170
189
|
When the server is started, the options are set here.
|
171
190
|
|
@@ -184,14 +203,14 @@ given inside of the client <br />
|
|
184
203
|
<i>oncearound</i>: number of seconds before completing a check of every repo in <br />
|
185
204
|
the watch list for changes <br />
|
186
205
|
|
187
|
-
<i>load hooks</i>: load
|
206
|
+
<i>load hooks</i>: hooks to load on server start. To see how to save hooks in the <br />
|
188
207
|
client, see the <i>Working with hooks</i> section <br />
|
189
208
|
|
190
|
-
<i>load repos</i>: load
|
209
|
+
<i>load repos</i>: repos to load on server start. To see how to save repos in the <br />
|
191
210
|
client, see the <i>Shutting down and persistence between sessions</i> section.
|
192
211
|
<br />
|
193
212
|
|
194
213
|
<i>desktop notification</i>: whether to notify of repo changes using libnotify <br />
|
195
214
|
or growl. This is set to <i>on</i> by default. However, if no notification<br />
|
196
|
-
system is found, it is ignored.
|
215
|
+
system is found, it is ignored.
|
197
216
|
|
data/VERSION.rb
CHANGED
data/bin/hubeye
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__) + "/../"), "lib/hubeye/config/environment")
|
4
4
|
|
5
|
-
|
6
|
-
require File.join(File.expand_path(File.dirname(__FILE__) + "/../"), "lib/hubeye/config/environment")
|
5
|
+
module Hubeye
|
7
6
|
include Environment
|
8
7
|
require File.join(ROOTDIR, 'VERSION')
|
9
8
|
|
10
|
-
# standard lib
|
11
9
|
require 'optparse'
|
12
10
|
require 'ostruct'
|
13
11
|
|
@@ -83,19 +81,17 @@ module Hubeye
|
|
83
81
|
options = Options.parse(ARGV)
|
84
82
|
host = options.host
|
85
83
|
port = options.port
|
86
|
-
daemonized = options.server_daemonized
|
87
84
|
if options.server_wanted
|
88
85
|
unless port_open?(port)
|
89
86
|
puts "A service is already running on this port"
|
90
87
|
exit 1
|
91
88
|
end
|
92
89
|
require File.join('hubeye', 'server', 'server')
|
93
|
-
options.server_daemonized
|
94
|
-
start_server(port, :daemon => true) :
|
95
|
-
start_server(port, :daemon => false)
|
90
|
+
start_server(port, :daemon => options.server_daemonized)
|
96
91
|
else
|
92
|
+
# move this to client script
|
97
93
|
['INT', 'KILL'].each do |sig|
|
98
|
-
trap(sig) { STDOUT.
|
94
|
+
trap(sig) { STDOUT.print("\n"); exit 1 }
|
99
95
|
end
|
100
96
|
require File.join('hubeye', 'client', 'client')
|
101
97
|
start_client(host, port)
|
@@ -112,7 +108,7 @@ module Hubeye
|
|
112
108
|
true
|
113
109
|
end
|
114
110
|
|
115
|
-
def start_server(port, options={}
|
111
|
+
def start_server(port, options={})
|
116
112
|
server = Server::Server.new(true) # debug
|
117
113
|
if options[:daemon]
|
118
114
|
Process.daemon(true) # don't change dir to '/'
|
@@ -120,7 +116,7 @@ module Hubeye
|
|
120
116
|
server.start(port, options)
|
121
117
|
end
|
122
118
|
|
123
|
-
def start_client(host, port
|
119
|
+
def start_client(host, port)
|
124
120
|
client = Client::Client.new(false) # debug
|
125
121
|
client.start(host, port)
|
126
122
|
end
|
@@ -129,4 +125,3 @@ module Hubeye
|
|
129
125
|
end
|
130
126
|
|
131
127
|
Hubeye.start
|
132
|
-
|
data/lib/hubeye/client/client.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
require File.expand_path('../connection', __FILE__)
|
2
3
|
require 'readline'
|
3
|
-
require_relative 'connection'
|
4
4
|
|
5
5
|
module Hubeye
|
6
6
|
module Client
|
@@ -35,14 +35,12 @@ module Hubeye
|
|
35
35
|
end
|
36
36
|
|
37
37
|
private
|
38
|
-
|
39
|
-
# Now begin a loop of client/server interaction.
|
40
38
|
def interact
|
41
39
|
loop do
|
42
40
|
get_input_from_readline
|
43
41
|
begin
|
44
|
-
if @input.match(
|
45
|
-
@input.gsub!(
|
42
|
+
if @input.match(/^(add)?\s*\.$/) # '.' = pwd (of client process)
|
43
|
+
@input.gsub!(/\./, File.split(File.expand_path('.')).last)
|
46
44
|
else
|
47
45
|
@input.gsub!(/\//, 'diiv')
|
48
46
|
end
|
@@ -4,8 +4,8 @@ module Hubeye
|
|
4
4
|
|
5
5
|
class NoHookError < ArgumentError; end
|
6
6
|
|
7
|
-
#options include the directory to execute the command
|
8
|
-
#
|
7
|
+
# options include the directory to execute the command and
|
8
|
+
# the full repo name of the changed repository
|
9
9
|
def self.execute(commands, options={})
|
10
10
|
opts = {:directory => nil, :repo => nil}.merge(options)
|
11
11
|
dir = opts[:directory]
|
@@ -14,14 +14,18 @@ module Hubeye
|
|
14
14
|
commands.each do |cmd|
|
15
15
|
if dir
|
16
16
|
Dir.chdir(File.expand_path(dir)) do
|
17
|
-
|
17
|
+
if repo
|
18
|
+
::Kernel.system "HUBEYE_CHANGED_REPO=#{repo} #{cmd}"
|
19
|
+
else
|
20
|
+
::Kernel.system cmd
|
21
|
+
end
|
18
22
|
end
|
19
23
|
else
|
20
24
|
::Kernel.system cmd
|
21
25
|
end
|
22
26
|
end
|
23
27
|
rescue ArgumentError
|
24
|
-
raise NoHookError "There aren't any hook commands for the repository #{repo}"
|
28
|
+
raise NoHookError.new "There aren't any hook commands for the repository #{repo}"
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Hubeye
|
2
|
+
module Hooks
|
3
|
+
class Git
|
4
|
+
|
5
|
+
def self.fetch(local_repo_name, remote_name, branch_name)
|
6
|
+
Dir.chdir(File.expand_path(local_repo_name)) do
|
7
|
+
system "git fetch #{remote_name} #{branch_name}"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.pull(local_repo_name, remote_name, branch_name)
|
12
|
+
Dir.chdir(File.expand_path(local_repo_name)) do
|
13
|
+
system "git pull #{remote_name} #{branch_name}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/hubeye/log/logger.rb
CHANGED
data/lib/hubeye/server/commit.rb
CHANGED
@@ -1,51 +1,29 @@
|
|
1
1
|
module Hubeye
|
2
2
|
module Server
|
3
3
|
|
4
|
-
|
4
|
+
# simple interface to Github's api v3 for commits
|
5
5
|
class Commit
|
6
|
-
attr_reader :
|
6
|
+
attr_reader :repo_name, :sha, :message, :committer_name
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
|
10
|
-
@
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
else
|
15
|
-
@latest = true
|
16
|
-
end
|
17
|
-
else
|
18
|
-
raise ArgumentError.new "input must be a kind of hash"
|
19
|
-
end
|
8
|
+
def initialize(repo_name, raw_commit_ary)
|
9
|
+
commit_hash = parse_raw_commit_ary(raw_commit_ary)
|
10
|
+
@repo_name = repo_name
|
11
|
+
@sha = commit_hash['sha']
|
12
|
+
@message = commit_hash['commit']['message']
|
13
|
+
@committer_name = commit_hash['commit']['committer']['name']
|
20
14
|
end
|
21
15
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
@raw_input[@repo]['commit']['message']
|
32
|
-
else
|
33
|
-
raise
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def committer_name
|
38
|
-
if @only_sha
|
39
|
-
return
|
40
|
-
elsif @latest
|
41
|
-
@committer_name ||=
|
42
|
-
@raw_input[@repo]['commit']['committer']['name']
|
43
|
-
else
|
44
|
-
raise
|
45
|
-
end
|
16
|
+
private
|
17
|
+
def parse_raw_commit_ary(raw_commit_ary)
|
18
|
+
{'sha' => raw_commit_ary.first['sha'],
|
19
|
+
'commit' =>
|
20
|
+
{'message' => raw_commit_ary.first['commit']['message'],
|
21
|
+
'committer' =>
|
22
|
+
{'name' => raw_commit_ary.first['commit']['committer']['name']}
|
23
|
+
}
|
24
|
+
}
|
46
25
|
end
|
47
26
|
|
48
27
|
end
|
49
28
|
end
|
50
29
|
end
|
51
|
-
|