kid80-cijoe 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -16,10 +16,43 @@ begin
16
16
  gemspec.authors = ["Chris Wanstrath"]
17
17
  gemspec.add_dependency 'choice'
18
18
  gemspec.add_dependency 'sinatra'
19
- gemspec.add_dependency 'open4'
20
19
  gemspec.version = CIJoe::Version.to_s
21
20
  end
22
21
  rescue LoadError
23
22
  puts "Jeweler not available."
24
23
  puts "Install it with: gem install jeweler"
25
24
  end
25
+
26
+ require 'rake/testtask'
27
+ Rake::TestTask.new(:test) do |test|
28
+ test.libs << 'lib' << 'test'
29
+ test.pattern = 'test/**/test_*.rb'
30
+ test.verbose = true
31
+ end
32
+
33
+ begin
34
+ require 'rcov/rcovtask'
35
+ Rcov::RcovTask.new do |test|
36
+ test.libs << 'test'
37
+ test.pattern = 'test/**/test_*.rb'
38
+ test.verbose = true
39
+ end
40
+ rescue LoadError
41
+ task :rcov do
42
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
43
+ end
44
+ end
45
+
46
+ task :test => :check_dependencies
47
+
48
+ task :default => :test
49
+
50
+ require 'rake/rdoctask'
51
+ Rake::RDocTask.new do |rdoc|
52
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
53
+
54
+ rdoc.rdoc_dir = 'rdoc'
55
+ rdoc.title = "someproject #{version}"
56
+ rdoc.rdoc_files.include('README*')
57
+ rdoc.rdoc_files.include('lib/**/*.rb')
58
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.2.0
data/deps.rip CHANGED
@@ -2,4 +2,3 @@ git://github.com/Manfred/broach.git HEAD
2
2
  git://github.com/sinatra/sinatra.git 0.9.4
3
3
  git://github.com/rack/rack.git 1.0
4
4
  git://github.com/defunkt/choice.git 8b125564
5
- git://github.com/ahoward/open4.git 25c3ed8
data/lib/cijoe.rb CHANGED
@@ -13,12 +13,6 @@
13
13
  #
14
14
  # Seriously, I'm gonna be nuts about keeping this simple.
15
15
 
16
- begin
17
- require 'open4'
18
- rescue LoadError
19
- abort "** Please install open4"
20
- end
21
-
22
16
  require 'cijoe/version'
23
17
  require 'cijoe/config'
24
18
  require 'cijoe/commit'
@@ -74,6 +68,7 @@ class CIJoe
74
68
  @current_build.status = status
75
69
  @current_build.output = output
76
70
  @last_build = @current_build
71
+
77
72
  @current_build = nil
78
73
  write_build 'current', @current_build
79
74
  write_build 'last', @last_build
@@ -89,22 +84,42 @@ class CIJoe
89
84
  Thread.new { build! }
90
85
  end
91
86
 
87
+ def open_pipe(cmd)
88
+ read, write = IO.pipe
89
+
90
+ pid = fork do
91
+ read.close
92
+ STDOUT.reopen write
93
+ exec cmd
94
+ end
95
+
96
+ write.close
97
+
98
+ yield read, pid
99
+ end
100
+
92
101
  # update git then run the build
93
102
  def build!
94
103
  build = @current_build
95
- out, err, status = '', '', nil
104
+ output = ''
96
105
  git_update
97
106
  build.sha = git_sha
98
107
  write_build 'current', build
99
108
 
100
- status = Open4.popen4(runner_command) do |pid, stdin, stdout, stderr|
109
+ open_pipe("#{runner_command} 2>&1") do |pipe, pid|
110
+ puts "#{Time.now.to_i}: Building #{build.short_sha}: pid=#{pid}"
111
+
101
112
  build.pid = pid
102
113
  write_build 'current', build
103
- err, out = stderr.read.strip, stdout.read.strip
114
+ output = pipe.read
104
115
  end
105
116
 
106
- status.exitstatus.to_i == 0 ? build_worked(out) : build_failed(out, err)
117
+ status = $?.exitstatus.to_i
118
+ puts "#{Time.now.to_i}: Built #{build.short_sha}: status=#{status}"
119
+
120
+ status == 0 ? build_worked(output) : build_failed('', output)
107
121
  rescue Object => e
122
+ puts "Exception building: #{e.message} (#{e.class})"
108
123
  build_failed('', e.to_s)
109
124
  end
110
125
 
@@ -153,8 +168,14 @@ class CIJoe
153
168
 
154
169
  # restore current / last build state from disk.
155
170
  def restore
156
- @last_build = read_build('last')
157
- @current_build = read_build('current')
171
+ unless @last_build
172
+ @last_build = read_build('last')
173
+ end
174
+
175
+ unless @current_build
176
+ @current_build = read_build('current')
177
+ end
178
+
158
179
  Process.kill(0, @current_build.pid) if @current_build && @current_build.pid
159
180
  rescue Errno::ESRCH
160
181
  # build pid isn't running anymore. assume previous
data/lib/cijoe/build.rb CHANGED
@@ -21,7 +21,11 @@ class CIJoe
21
21
  end
22
22
 
23
23
  def short_sha
24
- sha[0,7] if sha
24
+ if sha
25
+ sha[0,7]
26
+ else
27
+ "<unknown>"
28
+ end
25
29
  end
26
30
 
27
31
  def clean_output
@@ -2,7 +2,7 @@ class CIJoe
2
2
  module Campfire
3
3
  def self.activate
4
4
  if valid_config?
5
- require 'broach'
5
+ require 'tinder'
6
6
 
7
7
  CIJoe::Build.class_eval do
8
8
  include CIJoe::Campfire
@@ -13,8 +13,9 @@ class CIJoe
13
13
  puts "Can't load Campfire notifier."
14
14
  puts "Please add the following to your project's .git/config:"
15
15
  puts "[campfire]"
16
- puts "\ttoken = your_api_token"
17
- puts "\taccount = whatever"
16
+ puts "\tuser = your@campfire.email"
17
+ puts "\tpass = passw0rd"
18
+ puts "\tsubdomain = whatever"
18
19
  puts "\troom = Awesomeness"
19
20
  puts "\tssl = false"
20
21
  end
@@ -22,22 +23,23 @@ class CIJoe
22
23
 
23
24
  def self.config
24
25
  @config ||= {
25
- :account => Config.campfire.account.to_s,
26
- :token => Config.campfire.token.to_s,
26
+ :subdomain => Config.campfire.subdomain.to_s,
27
+ :user => Config.campfire.user.to_s,
28
+ :pass => Config.campfire.pass.to_s,
27
29
  :room => Config.campfire.room.to_s,
28
- :use_ssl => Config.campfire.ssl.to_s.strip == 'true'
30
+ :ssl => Config.campfire.ssl.to_s.strip == 'true'
29
31
  }
30
32
  end
31
33
 
32
34
  def self.valid_config?
33
- %w( account token room ).all? do |key|
34
- puts config.inspect if config[key.intern].nil?
35
+ %w( subdomain user pass room ).all? do |key|
35
36
  !config[key.intern].empty?
36
37
  end
37
38
  end
38
-
39
+
39
40
  def notify
40
- room.speak "#{short_message}. #{commit.url} #{play_sound}"
41
+ room.speak "#{short_message}. #{commit.url}"
42
+ room.play "#{play_sound}"
41
43
  room.paste full_message if failed?
42
44
  room.leave
43
45
  end
@@ -45,8 +47,12 @@ class CIJoe
45
47
  private
46
48
  def room
47
49
  @room ||= begin
48
- Broach.settings = Campfire.config
49
- Broach::Room.find_by_name(Campfire.config['room'])
50
+ config = Campfire.config
51
+ options = {}
52
+ options[:ssl] = config[:ssl] ? true : false
53
+ campfire = Tinder::Campfire.new(config[:subdomain], options)
54
+ campfire.login(config[:user], config[:pass])
55
+ campfire.find_room_by_name(config[:room])
50
56
  end
51
57
  end
52
58
 
@@ -55,7 +61,7 @@ class CIJoe
55
61
  end
56
62
 
57
63
  def play_sound
58
- "/play #{worked? ? "rimshot" : "trombone"}"
64
+ "#{worked? ? "rimshot" : "trombone"}"
59
65
  end
60
66
 
61
67
  def full_message
@@ -68,4 +74,4 @@ Commit Author: #{commit.author}
68
74
  EOM
69
75
  end
70
76
  end
71
- end
77
+ end
data/lib/cijoe/config.rb CHANGED
@@ -14,11 +14,29 @@ class CIJoe
14
14
  end
15
15
 
16
16
  def to_s
17
- `git config #{config_string}`.chomp
17
+ git_command = "git config #{config_string}"
18
+ result = `#{git_command} 2>&1`.chomp
19
+ process_status = $?
20
+
21
+ if successful_command?(process_status) || config_command_with_empty_value?(result,process_status)
22
+ return result
23
+ else
24
+ raise "Error calling git config, is a recent version of git installed? Command: #{git_command}, Error: #{result}"
25
+ end
18
26
  end
19
27
 
20
28
  def config_string
21
29
  @parent ? "#{@parent.config_string}.#{@command}" : @command
22
30
  end
31
+
32
+ private
33
+
34
+ def successful_command?(process_status)
35
+ process_status.exitstatus.to_i == 0
36
+ end
37
+
38
+ def config_command_with_empty_value?(result, process_status)
39
+ process_status.exitstatus.to_i == 1 && result.empty?
40
+ end
23
41
  end
24
42
  end
@@ -11,10 +11,6 @@
11
11
  padding: 0;
12
12
  }
13
13
 
14
- html, body {
15
- height: 100%;
16
- }
17
-
18
14
  body {
19
15
  background-color: white;
20
16
  font: 13.34px helvetica, arial, clean, sans-serif;
@@ -198,8 +194,8 @@ ul.posts {
198
194
 
199
195
  pre.terminal {
200
196
  border: 1px solid black;
201
- background-color: #333;
202
- color: white;
197
+ background-color: #fff;
198
+ color: #333;
203
199
  padding: 5px;
204
200
  overflow: auto;
205
201
  word-wrap: break-word;
@@ -207,6 +203,6 @@ pre.terminal {
207
203
 
208
204
  pre.terminal code {
209
205
  font-family: 'Bitstream Vera Sans Mono', 'Courier', monospace;
210
- background-color: #333;
206
+ background-color: #fff;
211
207
  }
212
208
 
data/lib/cijoe/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class CIJoe
2
- Version = "0.1.2"
2
+ Version = "0.2.0"
3
3
  end
@@ -2,17 +2,12 @@
2
2
  <html>
3
3
  <head>
4
4
  <link href="<%= cijoe_root %>/screen.css" media="screen" rel="stylesheet" type="text/css" />
5
+ <link rel="shortcut icon" href="<%= cijoe_root %>/favicon.ico" type="image/x-icon" />
5
6
  <title><%= h(joe.project) %>: CI Joe</title>
6
7
  </head>
7
8
  <body>
8
9
  <div class="site">
9
- <div class="title">
10
- <a href="<%= cijoe_root %>/">CI Joe</a>
11
- <span class="extra">because knowing is half the battle</span>
12
- </div>
13
-
14
10
  <div id="home">
15
- <h1><a href="<%= joe.url %>"><%= joe.project %></a></h1>
16
11
  <ul class="posts">
17
12
  <% if joe.current_build %>
18
13
  <li>
@@ -35,30 +30,7 @@
35
30
  <% end %>
36
31
  </ul>
37
32
  </div>
38
-
39
- <div class="footer">
40
- <div class="contact">
41
- <p>
42
- <a href="http://github.com/defunkt/cijoe/tree/master#readme">Documentation</a><br/>
43
- <a href="http://github.com/defunkt/cijoe">Source</a><br/>
44
- <a href="http://github.com/defunkt/cijoe/issues">Issues</a><br/>
45
- <a href="http://twitter.com/defunkt">Twitter</a>
46
- </p>
47
- </div>
48
- <div class="contact">
49
- <p>
50
- Designed by <a href="http://tom.preston-werner.com/">Tom Preston-Werner</a><br/>
51
- Influenced by <a href="http://integrityapp.com/">Integrity</a><br/>
52
- Built with <a href="http://sinatrarb.com/">Sinatra</a><br/>
53
- Keep it simple, Sam.
54
- </p>
55
- </div>
56
- <div class="rss">
57
- <a href="http://github.com/defunkt/cijoe">
58
- <img src="<%= cijoe_root %>/octocat.png" alt="Octocat!" />
59
- </a>
60
- </div>
61
- </div>
33
+
62
34
  </div>
63
35
  </body>
64
36
  </html>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kid80-cijoe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wanstrath