hubeye 0.3.3 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -0,0 +1,34 @@
|
|
1
|
+
module Hubeye
|
2
|
+
module Server
|
3
|
+
module Strategies
|
4
|
+
|
5
|
+
class RmRepo
|
6
|
+
def call
|
7
|
+
if @options[:all]
|
8
|
+
rm_all
|
9
|
+
return
|
10
|
+
end
|
11
|
+
repo_name = @matches[1]
|
12
|
+
full_repo_name = server.full_repo_name(repo_name)
|
13
|
+
rm = tracker.delete(full_repo_name)
|
14
|
+
if rm
|
15
|
+
socket.deliver "Stopped watching repository #{full_repo_name}"
|
16
|
+
else
|
17
|
+
socket.deliver "Repository #{full_repo_name} not currently being watched"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def rm_all
|
22
|
+
if tracker.empty?
|
23
|
+
socket.deliver "Not watching any repositories"
|
24
|
+
return
|
25
|
+
end
|
26
|
+
repo_names = tracker.repo_names
|
27
|
+
tracker.clear
|
28
|
+
socket.deliver "Stopped watching repositories #{repo_names.join ', '}"
|
29
|
+
end
|
30
|
+
end # end of RmRepo
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Hubeye
|
4
|
+
module Server
|
5
|
+
module Strategies
|
6
|
+
|
7
|
+
class SaveHook
|
8
|
+
def call
|
9
|
+
hooks = session.hooks
|
10
|
+
if !hooks.empty?
|
11
|
+
file = "#{ENV['HOME']}/.hubeye/hooks/#{@matches[2]}.yml"
|
12
|
+
if File.exists? file
|
13
|
+
override?
|
14
|
+
end
|
15
|
+
File.open(file, "w") do |f_out|
|
16
|
+
YAML.dump(hooks, f_out)
|
17
|
+
end
|
18
|
+
socket.deliver "Saved hook#{@matches[1]} as #{@matches[2]}"
|
19
|
+
else
|
20
|
+
socket.deliver "No hook#{@matches[1]} to save"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def override?
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Hubeye
|
4
|
+
module Server
|
5
|
+
module Strategies
|
6
|
+
|
7
|
+
class SaveRepo
|
8
|
+
def call
|
9
|
+
if !tracker.empty?
|
10
|
+
file = "#{ENV['HOME']}/.hubeye/repos/#{@matches[2]}.yml"
|
11
|
+
if File.exists? file
|
12
|
+
override?
|
13
|
+
end
|
14
|
+
# dump only the repository names, not the shas
|
15
|
+
File.open(file, "w") do |f_out|
|
16
|
+
YAML.dump(tracker.repo_names, f_out)
|
17
|
+
end
|
18
|
+
socket.deliver "Saved repo#{@matches[1]} as #{@matches[2]}"
|
19
|
+
else
|
20
|
+
socket.deliver "No remote repos are being tracked"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def override?
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Hubeye
|
2
|
+
module Server
|
3
|
+
module Strategies
|
4
|
+
|
5
|
+
class Shutdown
|
6
|
+
def call
|
7
|
+
Logger.log "Closing connection to #{socket.peeraddr[2]}"
|
8
|
+
Logger.log "Shutting down... (#{NOW})"
|
9
|
+
Logger.log ""
|
10
|
+
Logger.log ""
|
11
|
+
socket.deliver "Shutting down server"
|
12
|
+
sockets.delete(socket)
|
13
|
+
socket.close
|
14
|
+
unless server.daemonized
|
15
|
+
STDOUT.puts "Shutting down gracefully."
|
16
|
+
end
|
17
|
+
exit 0
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require File.expand_path('../commit', __FILE__)
|
2
|
+
require 'forwardable'
|
3
|
+
require 'json'
|
4
|
+
require 'open-uri'
|
5
|
+
|
6
|
+
module Hubeye
|
7
|
+
module Server
|
8
|
+
class Tracker
|
9
|
+
extend Forwardable
|
10
|
+
def_delegators :@commit_list, :[], :last, :first, :length, :each, :empty?, :clear
|
11
|
+
attr_reader :commit_list
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@commit_list = []
|
15
|
+
end
|
16
|
+
|
17
|
+
# returns one of:
|
18
|
+
# :added
|
19
|
+
# :replaced
|
20
|
+
# :unchanged
|
21
|
+
# :invalid
|
22
|
+
#
|
23
|
+
# A commit won't be added if the repo is already tracked
|
24
|
+
# and the newly searched for commit sha is the same as the
|
25
|
+
# old one. Every call to #add requires a trip to a Github
|
26
|
+
# server.
|
27
|
+
# NOTE: takes full repo_name only
|
28
|
+
def add(repo_name)
|
29
|
+
raw_commit_ary = recent_repo_info(repo_name)
|
30
|
+
return :invalid unless raw_commit_ary
|
31
|
+
commit = Commit.new(repo_name, raw_commit_ary)
|
32
|
+
if tracking?(repo_name) && unchanged?(commit)
|
33
|
+
return :unchanged
|
34
|
+
end
|
35
|
+
state = tracking?(repo_name) ? :replaced : :added
|
36
|
+
# update the list
|
37
|
+
@commit_list.reject! {|cmt| cmt.repo_name == repo_name} if state == :replaced
|
38
|
+
@commit_list << commit
|
39
|
+
state
|
40
|
+
end
|
41
|
+
|
42
|
+
alias << add
|
43
|
+
|
44
|
+
# returns true if deleted, false otherwise.
|
45
|
+
def delete(repo_name)
|
46
|
+
old_length = @commit_list.length
|
47
|
+
@commit_list.delete_if {|cmt| cmt.repo_name == repo_name}
|
48
|
+
new_length = @commit_list.length
|
49
|
+
old_length != new_length
|
50
|
+
end
|
51
|
+
|
52
|
+
# returns the most recently tracked commit object for that full repo
|
53
|
+
# name, or nil if it isn't tracked.
|
54
|
+
def commit(repo_name)
|
55
|
+
@commit_list.each {|cmt| return cmt if cmt.repo_name == repo_name}
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
alias tracking? commit
|
59
|
+
|
60
|
+
# returns a list of repo names being tracked
|
61
|
+
def repo_names
|
62
|
+
@commit_list.map {|cmt| cmt.repo_name }
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
# a new_commit_obj is unchanged if it's sha is found to be in the
|
67
|
+
# commit_list
|
68
|
+
def unchanged?(new_commit_obj)
|
69
|
+
@commit_list.each {|cmt| return true if cmt.sha == new_commit_obj.sha}
|
70
|
+
false
|
71
|
+
end
|
72
|
+
|
73
|
+
def recent_repo_info(full_repo_name)
|
74
|
+
username, repo_name = full_repo_name.split '/'
|
75
|
+
info = nil
|
76
|
+
begin
|
77
|
+
open "https://api.github.com/repos/#{username}/" \
|
78
|
+
"#{repo_name}/commits" do |f|
|
79
|
+
info = JSON.parse f.read
|
80
|
+
end
|
81
|
+
rescue => e
|
82
|
+
return
|
83
|
+
end
|
84
|
+
info
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/tasks/install.rb
CHANGED
@@ -1,28 +1,27 @@
|
|
1
1
|
HUBEYE_ROOT_DIR = File.join(ENV['HOME'], '.hubeye')
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
hubeye_repos_dir = File.join(HUBEYE_ROOT_DIR, 'repos')
|
3
|
+
hubeye_hooks_dir = File.join(HUBEYE_ROOT_DIR, 'hooks')
|
4
|
+
hubeye_log_file = File.join(HUBEYE_ROOT_DIR, 'log')
|
5
|
+
hubeye_conf_file = File.join(HUBEYE_ROOT_DIR, 'hubeyerc')
|
6
6
|
|
7
7
|
task :install => :create_config_file do
|
8
8
|
puts "Done"
|
9
9
|
end
|
10
10
|
|
11
11
|
task :create_config_file do
|
12
|
-
touch
|
12
|
+
touch hubeye_conf_file unless File.exists? hubeye_conf_file
|
13
13
|
end
|
14
14
|
|
15
15
|
task :create_config_file => :make_log
|
16
16
|
|
17
17
|
task :make_log => :message do
|
18
18
|
mkdir HUBEYE_ROOT_DIR unless File.exists? HUBEYE_ROOT_DIR
|
19
|
-
mkdir
|
20
|
-
mkdir
|
19
|
+
mkdir hubeye_hooks_dir unless File.exists? hubeye_hooks_dir
|
20
|
+
mkdir hubeye_repos_dir unless File.exists? hubeye_repos_dir
|
21
21
|
|
22
|
-
touch
|
22
|
+
touch hubeye_log_file unless File.exists? hubeye_log_file
|
23
23
|
end
|
24
24
|
|
25
25
|
task :message do
|
26
26
|
puts "Installing hubeye..."
|
27
27
|
end
|
28
|
-
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Test
|
2
|
+
module Helpers
|
3
|
+
module Server
|
4
|
+
|
5
|
+
class << $stdout
|
6
|
+
alias deliver puts
|
7
|
+
def close; end
|
8
|
+
def read_all
|
9
|
+
gets.chomp
|
10
|
+
end
|
11
|
+
def peeraddr
|
12
|
+
['', '', '']
|
13
|
+
end
|
14
|
+
def addr
|
15
|
+
''
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def _test_client_connect(io_ary)
|
20
|
+
@socket = $stdin
|
21
|
+
# Inform the client of connection
|
22
|
+
basic_inform = "Hubeye running on #{Socket.gethostname} as #{@session.username}"
|
23
|
+
if !@session.tracker.empty?
|
24
|
+
@socket.deliver "#{basic_inform}\nTracking: #{@session.tracker.keys.join ', '}"
|
25
|
+
else
|
26
|
+
@socket.deliver basic_inform
|
27
|
+
end
|
28
|
+
puts "Client connected at #{NOW}" unless @daemonized
|
29
|
+
if @session.continuous
|
30
|
+
Logger.log "Accepted connection from STDIN (#{NOW})"
|
31
|
+
else
|
32
|
+
# wipe the log file and start fresh
|
33
|
+
Logger.relog "Accepted connection from STDIN (#{NOW})"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
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.3.
|
4
|
+
version: 0.3.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-03-05 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! 'Keep your eye on new commits being pushed to Github through an
|
15
15
|
|
@@ -35,11 +35,25 @@ files:
|
|
35
35
|
- lib/hubeye/notification/growl.rb
|
36
36
|
- lib/hubeye/notification/gnomenotify.rb
|
37
37
|
- lib/hubeye/notification/finder.rb
|
38
|
+
- lib/hubeye/server/strategies/add_repo.rb
|
39
|
+
- lib/hubeye/server/strategies/load_hook.rb
|
40
|
+
- lib/hubeye/server/strategies/rm_repo.rb
|
41
|
+
- lib/hubeye/server/strategies/add_hook.rb
|
42
|
+
- lib/hubeye/server/strategies/next.rb
|
43
|
+
- lib/hubeye/server/strategies/exit.rb
|
44
|
+
- lib/hubeye/server/strategies/save_repo.rb
|
45
|
+
- lib/hubeye/server/strategies/load_repo.rb
|
46
|
+
- lib/hubeye/server/strategies/decision.rb
|
47
|
+
- lib/hubeye/server/strategies/list_tracking.rb
|
48
|
+
- lib/hubeye/server/strategies/list_hooks.rb
|
49
|
+
- lib/hubeye/server/strategies/shutdown.rb
|
50
|
+
- lib/hubeye/server/strategies/save_hook.rb
|
38
51
|
- lib/hubeye/server/server.rb
|
39
52
|
- lib/hubeye/server/session.rb
|
53
|
+
- lib/hubeye/server/tracker.rb
|
40
54
|
- lib/hubeye/server/commit.rb
|
41
|
-
- lib/hubeye/hooks/
|
42
|
-
- lib/hubeye/hooks/
|
55
|
+
- lib/hubeye/hooks/git.rb
|
56
|
+
- lib/hubeye/hooks/command.rb
|
43
57
|
- lib/hubeye/log/logger.rb
|
44
58
|
- lib/hubeye/shared/hubeye_protocol.rb
|
45
59
|
- lib/hubeye/helpers/time.rb
|
@@ -53,6 +67,7 @@ files:
|
|
53
67
|
- test/test_helper.rb
|
54
68
|
- test/integration.rb
|
55
69
|
- test/environment.rb
|
70
|
+
- test/helpers/server.rb
|
56
71
|
- test/notification.rb
|
57
72
|
- images/change_icon.jpg
|
58
73
|
- tasks/install.rb
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Hubeye
|
2
|
-
module Hooks
|
3
|
-
module Default
|
4
|
-
|
5
|
-
def self.fetch(local_reponame, remotename, branchname)
|
6
|
-
Dir.chdir(File.expand_path(local_reponame)) do
|
7
|
-
::Kernel.system("git fetch #{remotename} #{branchname}")
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.pull(local_reponame, remotename, branchname)
|
12
|
-
Dir.chdir(File.expand_path(local_reponame)) do
|
13
|
-
::Kernel.system("git pull #{remotename} #{branchname}")
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|