git-runner 0.1.0 → 0.1.1

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 CHANGED
@@ -63,6 +63,14 @@ Name | Gem |
63
63
  [Deploy](https://github.com/JamesBrooks/git-runner-deploy) | git-runner-deploy | Application deployment using capistrano
64
64
 
65
65
 
66
+ ## Requirements
67
+
68
+ * git
69
+ * Ruby 1.9
70
+ * Developed and "tested" using 1.9.3 (formal testing incoming soon).
71
+ * It *might* work with 1.8.7 if `Object#tap` is patched in.
72
+
73
+
66
74
  ## Installation
67
75
 
68
76
  This section needs a lot more fleshing out as installation overly trivial. The main thing to worry about is making sure that `hooks/post-update` in each of your repositories is able to run `git-runner` (and pass it's arguments on).
@@ -105,6 +113,7 @@ tmp_directory | /tmp/git-runner | Working directory for git-runner
105
113
 
106
114
  ## TODOs
107
115
 
116
+ * TESTS!
108
117
  * Support to monitor a command (stdout and stderr) as the command is running, not just at the end.
109
118
  * Instruction file path is globally set, make this overwritable on a per-repository basis?
110
119
  * Instruction prefix is globally set, make this overwritable on a per-repository basis?
@@ -5,6 +5,7 @@ require "git-runner/configuration"
5
5
  require "git-runner/hooks"
6
6
  require "git-runner/instruction"
7
7
  require "git-runner/text"
8
+ require "git-runner/threading"
8
9
  require "git-runner/version"
9
10
 
10
11
  module GitRunner
@@ -1,6 +1,6 @@
1
1
  module GitRunner
2
2
  class Base
3
- attr_accessor :refs
3
+ attr_accessor :refs, :current_branch
4
4
 
5
5
 
6
6
  def initialize(refs=[])
@@ -9,20 +9,10 @@ module GitRunner
9
9
 
10
10
  def run
11
11
  begin
12
- load_git_runner_gems
13
12
  Text.begin
14
13
 
15
- if refs && refs.is_a?(Array)
16
- repository_path = Dir.pwd
17
-
18
- # Only process HEAD references
19
- refs.select { |str| str =~ /^refs\/heads\// }.each do |ref|
20
- branch_name = ref.split('/').last
21
- branch = Branch.new(repository_path, branch_name)
22
-
23
- branch.run
24
- end
25
- end
14
+ load_git_runner_gems
15
+ process_refs
26
16
 
27
17
 
28
18
  rescue GitRunner::Instruction::Failure => ex
@@ -35,6 +25,7 @@ module GitRunner
35
25
  handle_unknown_exception(ex)
36
26
 
37
27
  ensure
28
+ join_threads
38
29
  Text.finish
39
30
  end
40
31
  end
@@ -46,6 +37,24 @@ module GitRunner
46
37
  Gem::Specification._all.map(&:name).select { |gem| gem =~ /^git-runner-/ }.each { |name| require(name) }
47
38
  end
48
39
 
40
+ def process_refs
41
+ if refs && refs.is_a?(Array)
42
+ repository_path = Dir.pwd
43
+
44
+ # Only process HEAD references
45
+ refs.select { |str| str =~ /^refs\/heads\// }.each do |ref|
46
+ branch_name = ref.split('/').last
47
+
48
+ self.current_branch = Branch.new(repository_path, branch_name)
49
+ self.current_branch.run
50
+ end
51
+ end
52
+ end
53
+
54
+ def join_threads
55
+ GitRunner::Threading.join
56
+ end
57
+
49
58
  def handle_instruction_failure_exception(ex)
50
59
  Text.new_line
51
60
  Text.out("Stopping runner, no further instructions will be performed\n")
@@ -84,6 +93,11 @@ module GitRunner
84
93
 
85
94
  File.open(error_log, 'w') { |file| yield(file) }
86
95
 
96
+ GitRunner::Hooks.fire(:after_write_error_log, {
97
+ base: self,
98
+ log_file: error_log
99
+ })
100
+
87
101
  Text.out("An error log has been created: #{error_log}")
88
102
  error_log
89
103
  end
@@ -7,13 +7,36 @@ module GitRunner
7
7
  @registrations ||= Hash.new { |hash, key| hash[key] = [] }
8
8
  end
9
9
 
10
- def register(name, object, method)
11
- registrations[name] << [ object, method ]
10
+ def register(name, callable)
11
+ unless callable.respond_to?(:call) && callable.respond_to?(:arity)
12
+ raise InvalidCallable.new("Supplied callable is not callable, should respond to #call and #arity")
13
+ end
14
+
15
+ if callable.arity > 1
16
+ raise InvalidCallable.new("Supplied callable takes #{callable.arity} argument(s), should accept either 1 or 0.")
17
+ end
18
+
19
+ registrations[name] << callable
12
20
  end
13
21
 
14
- def fire(name)
22
+ def fire(name, data=nil)
15
23
  return unless registrations.keys.include?(name)
16
- registrations[name].each { |object, method| object.send(method) }
24
+
25
+ registrations[name].each do |callable|
26
+ if callable.arity == 1
27
+ callable.call(data)
28
+ else
29
+ callable.call
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+
37
+ module GitRunner
38
+ module Hooks
39
+ class InvalidCallable < StandardError
17
40
  end
18
41
  end
19
42
  end
@@ -0,0 +1,21 @@
1
+ module GitRunner
2
+ module Threading
3
+ extend self
4
+
5
+
6
+ def spawn
7
+ raise ThreadError.new('must be called with a block') unless block_given?
8
+ thread_group.add(Thread.new { yield })
9
+ end
10
+
11
+ def thread_group
12
+ @thread_group ||= ThreadGroup.new
13
+ end
14
+
15
+ def join
16
+ # TODO: Timeout with failure alerts
17
+
18
+ thread_group.list.each(&:join)
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module GitRunner
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
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-10-12 00:00:00.000000000 Z
12
+ date: 2012-10-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: session
@@ -54,6 +54,7 @@ files:
54
54
  - lib/git-runner/instructions/base.rb
55
55
  - lib/git-runner/instructions/display.rb
56
56
  - lib/git-runner/text.rb
57
+ - lib/git-runner/threading.rb
57
58
  - lib/git-runner/version.rb
58
59
  homepage: https://github.com/JamesBrooks/git-runner
59
60
  licenses: []