hubeye 0.3.0 → 0.3.2

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.
@@ -0,0 +1,59 @@
1
+ module Hubeye
2
+ module Server
3
+ class Session
4
+ attr_accessor :repo_name, :username, :continuous
5
+ attr_writer :tracker, :hooks
6
+
7
+ def initialize
8
+ setup_singleton_methods
9
+ end
10
+
11
+ def tracker
12
+ @tracker ||= {}
13
+ end
14
+
15
+ def hooks
16
+ @hooks ||= {}
17
+ end
18
+
19
+ def cleanup
20
+ reset_username
21
+ reset_repo_name
22
+ end
23
+
24
+ private
25
+ def reset_username
26
+ self.username = CONFIG[:username]
27
+ end
28
+
29
+ def reset_repo_name
30
+ self.repo_name = ""
31
+ end
32
+
33
+ def setup_singleton_methods
34
+ tracker.singleton_class.class_eval do
35
+ def add_or_replace! input, new_sha=nil
36
+ if Hash === input and new_sha.nil?
37
+ repo = input.keys.first
38
+ hash = true
39
+ else
40
+ repo = input
41
+ two_args = true
42
+ end
43
+ if keys.include? repo and self[repo] == new_sha
44
+ return
45
+ elsif keys.include? repo
46
+ ret = {:replace => true}
47
+ else
48
+ ret = {:add => true}
49
+ end
50
+ two_args ? merge!(repo => new_sha) : merge!(input)
51
+ ret
52
+ end
53
+ end
54
+ end
55
+
56
+ end # end of Session class
57
+ end
58
+ end
59
+
@@ -0,0 +1,36 @@
1
+ require 'socket'
2
+
3
+ module HubeyeProtocol
4
+ HEADER_BYTE_SIZE = 4
5
+
6
+ def deliver(body)
7
+ header = header(body)
8
+ mesg = header + body
9
+ self.print mesg
10
+ self.flush
11
+ end
12
+
13
+ def header(body)
14
+ body_size = body.bytesize
15
+ [body_size].pack("N")
16
+ end
17
+
18
+ def read_all
19
+ read_header
20
+ read(@body_size)
21
+ end
22
+
23
+ def read_header
24
+ begin
25
+ @body_size = read(HEADER_BYTE_SIZE).unpack("N").first.to_i
26
+ rescue => e
27
+ STDOUT.puts e.message
28
+ STDOUT.puts e.backtrace
29
+ exit 1
30
+ end
31
+ end
32
+ end
33
+
34
+ class TCPSocket
35
+ include HubeyeProtocol
36
+ end
@@ -1,9 +1,9 @@
1
- # Hubeye::Config::Parser.new uses StringIO.open() when option {:test => true} is set
1
+ # Hubeye::Config::Parser.new uses StringIO.open() when option :test => true is set
2
2
  require 'stringio'
3
3
 
4
4
  class ConfigParserTests < Test::Unit::TestCase
5
5
 
6
- # otherwise, Test::Unit busies the self.instance_variables
6
+ # otherwise, Test::Unit busies the object.instance_variables
7
7
  # array with things like @passed, and many others
8
8
  def instance_vars
9
9
  [:@username, :@default_track, :@hooks,
data/test/environment.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class EnvironmentTests < Test::Unit::TestCase
2
- include Environment
2
+ include Hubeye::Environment
3
3
 
4
4
  def test_proper_rootdir
5
5
  assert_equal File.expand_path(File.dirname(__FILE__) + '/..'), ROOTDIR
@@ -0,0 +1,24 @@
1
+ class HubeyeIntegrationTest < Test::Unit::TestCase
2
+ include Hubeye::Environment
3
+
4
+ EXECUTABLE = File.join(BINDIR, 'hubeye')
5
+
6
+ def interact
7
+ start_server
8
+ sleep 0.5
9
+ start_client
10
+ end
11
+
12
+ def start_server
13
+ system "#{EXECUTABLE} -s"
14
+ end
15
+
16
+ def start_client
17
+ IO.popen("#{EXECUTABLE} -c", "r+") do |p|
18
+ p.write 'fjdksfjlsdj'
19
+ p.close_write
20
+ p.read.chomp
21
+ end
22
+ end
23
+
24
+ end
data/test/notification.rb CHANGED
@@ -1,14 +1,15 @@
1
1
  class NotifyTests < Test::Unit::TestCase
2
+ include Hubeye::Notification
2
3
 
3
4
  def test_libnotify_on_linux
4
5
  if RUBY_PLATFORM =~ /linux/i
5
- assert_equal "libnotify", Notification::Finder.find_notify
6
+ assert_equal "libnotify", Finder.find_notify
6
7
  end
7
8
  end
8
9
 
9
10
  def test_growl_returns_on_darwin
10
11
  if RUBY_PLATFORM =~ /darwin/i
11
- assert_equal "growl", Notification::Finder.find_notify
12
+ assert_equal "growl", Finder.find_notify
12
13
  end
13
14
  end
14
15
 
data/test/runner.rb CHANGED
@@ -1,15 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  # environment file
4
- require File.join(File.expand_path(File.dirname(__FILE__) + '/..'), "lib/environment")
4
+ require File.join(File.expand_path(File.dirname(__FILE__) + '/..'), "lib/hubeye/config/environment")
5
5
 
6
6
  # test/unit
7
7
  require 'test/unit'
8
8
 
9
9
  # test files
10
10
  require_relative 'environment'
11
- require File.join(File.expand_path(File.dirname(__FILE__) + '/..'), "lib/notification/finder")
11
+ require File.join(File.expand_path(File.dirname(__FILE__) + '/..'), "lib/hubeye/notification/finder")
12
12
  require_relative "notification"
13
- require Environment::LIBDIR + '/config/parser'
13
+ require Hubeye::Environment::LIBDIR + '/hubeye/config/parser'
14
14
  require_relative "config_parser"
15
15
 
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.0
4
+ version: 0.3.2
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: 2011-12-04 00:00:00.000000000Z
12
+ date: 2012-01-28 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: ! 'Keep your eye on new commits being pushed to Github through an
15
15
 
@@ -28,17 +28,21 @@ executables:
28
28
  extensions: []
29
29
  extra_rdoc_files: []
30
30
  files:
31
- - lib/config/parser.rb
32
- - lib/client/hubeye_client.rb
33
- - lib/notification/growl.rb
34
- - lib/notification/gnomenotify.rb
35
- - lib/notification/finder.rb
36
- - lib/server/hubeye_server.rb
37
- - lib/hooks/executer.rb
38
- - lib/hooks/git_hooks.rb
39
- - lib/log/logger.rb
40
- - lib/environment.rb
41
- - lib/helpers/time.rb
31
+ - lib/hubeye/config/parser.rb
32
+ - lib/hubeye/config/environment.rb
33
+ - lib/hubeye/client/connection.rb
34
+ - lib/hubeye/client/client.rb
35
+ - lib/hubeye/notification/growl.rb
36
+ - lib/hubeye/notification/gnomenotify.rb
37
+ - lib/hubeye/notification/finder.rb
38
+ - lib/hubeye/server/server.rb
39
+ - lib/hubeye/server/session.rb
40
+ - lib/hubeye/server/commit.rb
41
+ - lib/hubeye/hooks/executer.rb
42
+ - lib/hubeye/hooks/git_hooks.rb
43
+ - lib/hubeye/log/logger.rb
44
+ - lib/hubeye/shared/hubeye_protocol.rb
45
+ - lib/hubeye/helpers/time.rb
42
46
  - bin/hubeye
43
47
  - Rakefile
44
48
  - README.md
@@ -46,6 +50,7 @@ files:
46
50
  - LICENSE
47
51
  - test/config_parser.rb
48
52
  - test/runner.rb
53
+ - test/integration.rb
49
54
  - test/environment.rb
50
55
  - test/notification.rb
51
56
  - images/change_icon.jpg
@@ -1,103 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'socket'
3
-
4
- class HubeyeClient
5
-
6
- class Connection
7
- attr_reader :s, :local, :peer, :peeraddr
8
- def initialize(host, port)
9
- _begin do
10
- # Give the user some feedback while connecting.
11
- STDOUT.print "Connecting..."
12
- STDOUT.flush
13
- @s = TCPSocket.open(host, port)
14
- STDOUT.puts "Done" if @s
15
-
16
- # Now display information about the connection.
17
- @local, @peer = @s.addr, @s.peeraddr
18
-
19
- STDOUT.print "Connected to #{peer[2]}:#{peer[1]}"
20
- STDOUT.puts " using local port #{local[1]}"
21
- end
22
- end
23
-
24
- def receive_welcome
25
- # Wait just a bit, to see if the server sends any initial message.
26
- begin
27
- sleep 1
28
- msg = @s.readpartial(4096)
29
- STDOUT.puts msg.chop
30
- rescue SystemCallError, NoMethodError
31
- STDOUT.puts "The server's not running!"
32
- rescue EOFError
33
- @retried ||= -1
34
- @retried += 1
35
- retry unless @retried >= 1
36
- end
37
- end
38
-
39
- private
40
-
41
- def _begin
42
- begin
43
- yield
44
- rescue
45
- puts $! if @debug
46
- end
47
- end
48
- end
49
-
50
- def start(host, port, debug=false)
51
- @debug = debug
52
- conn = Connection.new(host, port)
53
- conn.receive_welcome
54
- interact(conn.s)
55
- end
56
-
57
- # Now begin a loop of client/server interaction.
58
- def interact(socket)
59
- @s = socket
60
- while @s
61
- loop do
62
- STDOUT.print '> '
63
- STDOUT.flush
64
- local = STDIN.gets
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
74
- end
75
- @s.flush
76
- if local =~ /load repo/
77
- puts "Loading..."
78
- sleep 1
79
- else
80
- sleep 0.5
81
- end
82
- begin
83
- response = @s.readpartial(4096)
84
- rescue EOFError
85
- response = "Bye!"
86
- end
87
- if response.chop.strip == "Bye!"
88
- puts response.chop
89
- @s.close
90
- exit 0
91
- elsif response.chop.strip.match(/shutting/i)
92
- @s.close
93
- exit 0
94
- else
95
- puts response.chop
96
- next
97
- end
98
- end
99
- end
100
- end
101
-
102
- end
103
-
data/lib/environment.rb DELETED
@@ -1,10 +0,0 @@
1
- module Environment
2
-
3
- ROOTDIR = File.expand_path(File.dirname(__FILE__) + '/..')
4
-
5
- LIBDIR = File.join(ROOTDIR, "lib")
6
- BINDIR = File.join(ROOTDIR, "bin")
7
-
8
- $:.unshift(LIBDIR) unless $:.include? LIBDIR
9
-
10
- end
data/lib/helpers/time.rb DELETED
@@ -1,5 +0,0 @@
1
- module Helpers
2
- module Time
3
- NOW = ::Time.now.strftime("%m/%d/%Y at %I:%M%p")
4
- end
5
- end
data/lib/log/logger.rb DELETED
@@ -1,38 +0,0 @@
1
- module Log
2
- class Logger
3
-
4
- LOG_DIR = File.join(ENV['HOME'], '.hubeye', 'log')
5
-
6
- def self.log(msg)
7
- File.open(LOG_DIR, "a") do |f|
8
- f.puts(msg)
9
- end
10
- end
11
-
12
- def self.relog(msg)
13
- #wipe the file and start anew
14
- File.open(LOG_DIR, "w") do |f|
15
- f.puts(msg)
16
- end
17
- end
18
-
19
- # If {include_terminal: true}, log to the terminal too (make sure that the
20
- # process is not daemonized). Always log to the logfile.
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)
34
- end
35
-
36
- end
37
- end
38
-
@@ -1,62 +0,0 @@
1
- module Notification
2
- include Environment
3
-
4
- CHANGE_ICON = "change_icon.jpg"
5
- CHANGE_ICON_PATH = (File.join(ROOTDIR, "images", CHANGE_ICON))
6
-
7
- class Finder
8
- def self.find_notify
9
- if RUBY_PLATFORM =~ /mswin/
10
- return
11
- elsif RUBY_PLATFORM =~ /linux/
12
- libnotify = system('locate libnotify-bin > /dev/null')
13
- if libnotify
14
- require_relative "gnomenotify"
15
- return "libnotify"
16
- elsif LibCheck.autotest_notification
17
- require_relative "growl"
18
- return "growl"
19
- end
20
- elsif RUBY_PLATFORM =~ /darwin/i and LibCheck.autotest_notification
21
- require_relative "growl"
22
- return "growl"
23
- end
24
- end
25
- end
26
-
27
- class LibCheck
28
- class << self
29
- def autotest
30
- begin
31
- require 'autotest'
32
- rescue LoadError
33
- if require 'rubygems'
34
- retry
35
- else
36
- return
37
- end
38
- end
39
- if defined? Autotest
40
- true
41
- end
42
- end
43
-
44
- def autotest_notification
45
- begin
46
- require 'autotest_notification'
47
- rescue LoadError
48
- if require 'rubygems'
49
- retry
50
- else
51
- return
52
- end
53
- end
54
- if defined? Autotest
55
- true
56
- end
57
- end
58
- end
59
- end
60
-
61
- end # end module
62
-
@@ -1,13 +0,0 @@
1
- module Notification
2
- module GnomeNotify
3
-
4
- EXPIRATION_IN_SECONDS = 2
5
-
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
-
11
- end
12
- end
13
-