hercules 0.1.2 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.2
data/hercules.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{hercules}
8
- s.version = "0.1.2"
8
+ s.version = "0.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Diogo Biazus"]
12
- s.date = %q{2010-10-14}
12
+ s.date = %q{2011-01-11}
13
13
  s.default_executable = %q{hercules}
14
14
  s.description = %q{Very simple deployment tool. It was made to deploy rails applications using github, bundler.}
15
15
  s.email = %q{diogob@gmail.com}
data/lib/deployer.rb CHANGED
@@ -39,6 +39,7 @@ module Hercules
39
39
  @log.warn "Branch #{@branch} deployed"
40
40
  dir = "#{git.branches_path}/#{@branch}"
41
41
  Bundler.with_clean_env do
42
+ @log.debug "We do have an after trigger? #{has_before_trigger} Trigger Class: #{@trigger_class.inspect}"
42
43
  after_trigger(dir) if has_after_trigger?
43
44
  end
44
45
  ensure
data/lib/git_handler.rb CHANGED
@@ -67,7 +67,7 @@ module Hercules
67
67
  dir = "#{@options['target_directory']}/checkouts/#{branch}"
68
68
  if (Dir.glob("#{dir}/*").size) > max
69
69
  # Here we must delete the oldest checkout
70
- checkout_to_delete = Dir.glob("#{dir}/*").sort{|a,b| File.new(a).mtime.strftime("%Y%m%d%H%M%S") <=> File.new(b).mtime.strftime("%Y%m%d%H%M%S") }.shift
70
+ checkout_to_delete = Dir.glob("#{dir}/*").sort{|a,b| File.new(a).mtime <=> File.new(b).mtime }.shift
71
71
  FileUtils.rm_r "#{checkout_to_delete}"
72
72
  # Remove log file if it exists
73
73
  # To achieve consistency we must remove the log when and only when we remove the checkout
data/lib/http_handler.rb CHANGED
@@ -19,8 +19,19 @@ module Hercules
19
19
  begin
20
20
  @config.reload
21
21
  resp = EventMachine::DelegatedHttpResponse.new( self )
22
- req = RequestHandler.new({:config => @config, :log => @log, :method => @http_request_method, :path => @http_path_info, :query => @http_query_string, :body => @http_post_content})
23
- return send(resp, req.status, req.message)
22
+ # Block which fulfills the request
23
+ if @http_request_method == "GET"
24
+ req = RequestHandler.new({:config => @config, :log => @log, :method => @http_request_method, :path => @http_path_info, :query => @http_query_string, :body => @http_post_content})
25
+ req.run
26
+ resp.status = req.status
27
+ resp.content = req.message
28
+ resp.send_response
29
+ else
30
+ req = RequestHandler.new({:config => @config, :log => @log, :method => @http_request_method, :path => @http_path_info, :query => @http_query_string, :body => @http_post_content})
31
+ req.run
32
+ resp.content = "Deploy queued"
33
+ resp.send_response
34
+ end
24
35
  rescue Exception => e
25
36
  send(resp, 500, "Error while processing HTTP request: #{e.inspect} \nREQUEST: #{@http_request_method} #{@http_path_info}?#{@http_query_string}\n#{@http_post_content}")
26
37
  @log.error "Backtrace: #{e.backtrace}"
@@ -30,8 +41,6 @@ module Hercules
30
41
  def send resp, status, message
31
42
  if status == 500
32
43
  @log.error "#{status}: #{message}"
33
- else
34
- @log.info "#{status}: #{message}"
35
44
  end
36
45
  resp.status = status
37
46
  resp.content = message
@@ -3,11 +3,14 @@ require 'json'
3
3
  require 'uri'
4
4
  require File.dirname(__FILE__) + '/deployer'
5
5
 
6
+ require 'eventmachine'
7
+
6
8
  module Hercules
7
9
  # Class that knows how to handle deploy requests.
8
10
  # This implementation will just parse a JSON as defined by github http hooks.
9
11
  # In order to use other hook formats this class should be reimplemented.
10
12
  class RequestHandler
13
+ include EM::Deferrable
11
14
  # We must pass the request data (method, path, query and body).
12
15
  # * options is a hash containing all the request data described above plus the logger and the config hash.
13
16
  def initialize(options)
@@ -18,6 +21,11 @@ module Hercules
18
21
  @config = options[:config]
19
22
  end
20
23
 
24
+ def run
25
+ status
26
+ message
27
+ set_deferred_status :succeeded
28
+ end
21
29
  # Returns the message generated as response for the request passed in the initializer.
22
30
  # We also store the message for further queries.
23
31
  def message
@@ -86,6 +86,7 @@ class GitHandlerTest < Test::Unit::TestCase
86
86
  g = Hercules::GitHandler.new(@config['test_project'])
87
87
  g.deploy_branch('master')
88
88
  generate_commit 'new_commit'
89
+ sleep 1 # Just to avoid creating two folders with same mtime
89
90
  g.deploy_branch('master')
90
91
  assert File.exists?(@config['test_project']['target_directory'] + '/branches/master/new_commit')
91
92
  assert_equal 3, Dir.entries(@config['test_project']['target_directory'] + '/checkouts/master').size
@@ -57,20 +57,21 @@ class HttpHandlerTest < Test::Unit::TestCase
57
57
 
58
58
  def post token
59
59
  start_hercules do |pid,log|
60
- res = Net::HTTP.post_form(URI.parse("http://127.0.0.1:8080/test_project/#{token}"), {'payload' => @json_request})
60
+ res = Net::HTTP.post_form(URI.parse("http://127.0.0.1:49456/test_project/#{token}"), {'payload' => @json_request})
61
61
  yield res, log
62
62
  end
63
63
  end
64
64
 
65
65
  def get token
66
66
  start_hercules do |pid,log|
67
- res = Net::HTTP.get(URI.parse("http://127.0.0.1:8080/test_project/#{token}"))
67
+ res = Net::HTTP.get(URI.parse("http://127.0.0.1:49456/test_project/#{token}"))
68
68
  yield res, log
69
69
  end
70
70
  end
71
71
 
72
72
  def test_simple_post
73
73
  post "abc" do |res, log|
74
+ sleep 1
74
75
  log_content = log.read()
75
76
  assert_match /Received POST/, log_content
76
77
  assert_no_match /Repository .* not found/, log_content
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hercules
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
8
  - 2
10
- version: 0.1.2
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Diogo Biazus
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-14 00:00:00 -03:00
18
+ date: 2011-01-11 00:00:00 -02:00
19
19
  default_executable: hercules
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency