chicanery 0.0.5 → 0.0.6

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/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chicanery (0.0.5)
4
+ chicanery (0.0.6)
5
5
  nokogiri (~> 1)
6
6
 
7
7
  GEM
@@ -0,0 +1,35 @@
1
+ require 'chicanery/git'
2
+
3
+ include Chicanery::Git
4
+
5
+ git_repo 'chicanery', '.', branches: [:master]
6
+
7
+ def now
8
+ Time.now.to_i
9
+ end
10
+
11
+ def say message
12
+ `growlnotify -t "some new chicanery ..." --image ~/icons/chicanery.png -m \"#{message}\"`
13
+ end
14
+
15
+ start = now
16
+ maximum = ARGV.shift.to_i
17
+
18
+ say "Uncommitted changes will be automatically reverted after #{maximum} seconds"
19
+
20
+ when_run do |state|
21
+ start = now if `git status`.chomp.split("\n").last == 'nothing to commit, working directory clean'
22
+ elapsed = now - start
23
+ if elapsed >= maximum
24
+ say "no commits detected in #{elapsed} seconds - reverting all uncommitted changes"
25
+ `afplay ~/build_sounds/ticktock.mp3`
26
+ `git reset --hard`
27
+ `git clean -d -x -f`
28
+ start = now
29
+ end
30
+ end
31
+
32
+ when_commit do |branch, commit, previous|
33
+ say "commit detected - resetting timer"
34
+ start = now
35
+ end
@@ -3,7 +3,7 @@ require 'chicanery/git'
3
3
 
4
4
  include Chicanery::Git
5
5
 
6
- git_repo 'chicanery', '.', remotes: {
6
+ git_repo 'chicanery', '.', branches: [:master], remotes: {
7
7
  github: { url: 'git://github.com/markryall/chicanery.git' }
8
8
  }
9
9
 
@@ -13,6 +13,10 @@ def growlnotify message
13
13
  `growlnotify -t "some new chicanery ..." --image ~/icons/chicanery.png -m \"#{message}\"`
14
14
  end
15
15
 
16
+ when_run do |state|
17
+ puts state.has_failure? ? "something is wrong" : "all builds are fine"
18
+ end
19
+
16
20
  when_commit do |repo, commit, previous|
17
21
  growlnotify "commit #{previous}..#{commit} detected in repo #{repo}"
18
22
  end
@@ -24,8 +24,8 @@ module Chicanery
24
24
  Nokogiri::XML(get).css("Project").each do |project|
25
25
  job = {
26
26
  activity: project[:activity] == 'Sleeping' ? :sleeping : :building,
27
- last_build_status: project[:lastBuildStatus] == 'Success' ? :success : :failure,
28
- last_build_time: project[:lastBuildTime].empty? ? nil : DateTime.parse(project[:lastBuildTime]),
27
+ last_build_status: parse_build_status(project[:lastBuildStatus]),
28
+ last_build_time: project[:lastBuildTime].empty? ? nil : DateTime.parse(project[:lastBuildTime]).to_time.to_i,
29
29
  url: project[:webUrl],
30
30
  last_label: project[:lastBuildLabel]
31
31
  }
@@ -34,6 +34,14 @@ module Chicanery
34
34
  jobs
35
35
  end
36
36
 
37
+ def parse_build_status status
38
+ case status
39
+ when /^Success/ then :success
40
+ when /^Unknown/ then :unknown
41
+ else :failure
42
+ end
43
+ end
44
+
37
45
  def filtered name
38
46
  return false unless options[:include]
39
47
  !options[:include].match(name)
data/lib/chicanery/git.rb CHANGED
@@ -28,22 +28,25 @@ module Chicanery
28
28
  response = {}
29
29
  in_repo do
30
30
  remotes.each do |name, remote|
31
- git "remote add #{name} #{remote[:url]}" unless git("remote | grep #{name}") == name.to_s
32
- git "fetch -q #{name}"
33
31
  (remote[:branches] || ['master']).each do |branch|
34
- response["#{name}/#{branch}"] = head "#{name}/#{branch}"
32
+ response["#{name}/#{branch}"] = remote_head remote[:url], branch
35
33
  end
36
34
  end
37
- branches.each do |branch|
38
- response[branch] = head branch
39
- end
35
+ branches.each { |branch| response[branch] = head branch }
40
36
  end
41
37
  response
42
38
  end
43
39
 
40
+ def remote_head url, branch
41
+ sha "ls-remote #{url} #{branch}"
42
+ end
43
+
44
44
  def head branch
45
- match = /^([^ ]*) /.match git "log -n 1 #{branch} --pretty=oneline"
46
- match[1] if match
45
+ sha "log -n 1 #{branch} --pretty=oneline"
46
+ end
47
+
48
+ def sha command
49
+ git(command).split.first
47
50
  end
48
51
 
49
52
  def git command
@@ -0,0 +1,11 @@
1
+ module Chicanery
2
+ module Summary
3
+ def has_failure?
4
+ self[:servers].map do |name,jobs|
5
+ jobs.map do |name, state|
6
+ state[:last_build_status] == :failure
7
+ end
8
+ end.flatten.inject(false) {|v,a| v || a}
9
+ end
10
+ end
11
+ end
data/lib/chicanery.rb CHANGED
@@ -8,6 +8,7 @@ require 'chicanery/persistence'
8
8
  require 'chicanery/collections'
9
9
  require 'chicanery/handlers'
10
10
  require 'chicanery/state_comparison'
11
+ require 'chicanery/summary'
11
12
 
12
13
  module Chicanery
13
14
  include Persistence
@@ -15,7 +16,7 @@ module Chicanery
15
16
  include Handlers
16
17
  include StateComparison
17
18
 
18
- VERSION = "0.0.5"
19
+ VERSION = "0.0.6"
19
20
 
20
21
  def execute args
21
22
  begin
@@ -37,6 +38,7 @@ module Chicanery
37
38
  compare_jobs current_jobs, previous_state[:servers][server.name] if previous_state[:servers]
38
39
  current_state[:servers][server.name] = current_jobs
39
40
  end
41
+ current_state.extend Chicanery::Summary
40
42
  run_handlers.each {|handler| handler.call current_state }
41
43
  persist current_state
42
44
  break unless poll_period
@@ -19,8 +19,8 @@ describe Chicanery::StateComparison do
19
19
  end
20
20
 
21
21
  describe '#compare_job' do
22
- let(:current_job) { { activity: :sleeping, last_build_time: Time.now, } }
23
- let(:previous_job) { { activity: :sleeping, last_build_time: (Time.now-1) } }
22
+ let(:current_job) { { activity: :sleeping, last_build_time: 10 } }
23
+ let(:previous_job) { { activity: :sleeping, last_build_time: 5 } }
24
24
 
25
25
  before {
26
26
  stub! :notify_failed_handlers
@@ -0,0 +1,29 @@
1
+ describe Chicanery::Summary do
2
+ describe '#failure?' do
3
+ let(:state) { {servers: {} } }
4
+
5
+ before do
6
+ state.extend Chicanery::Summary
7
+ end
8
+
9
+ it 'should be false if there are no jobs' do
10
+ state.should_not have_failure
11
+ end
12
+
13
+ it 'should be false if there are no failures' do
14
+ state[:servers][:server1] = {
15
+ job1: { last_build_status: :success },
16
+ job2: { last_build_status: :success }
17
+ }
18
+ state.should_not have_failure
19
+ end
20
+
21
+ it 'should be true if there is a single failure' do
22
+ state[:servers][:server1] = {
23
+ job1: { last_build_status: :failure },
24
+ job2: { last_build_status: :success }
25
+ }
26
+ state.should have_failure
27
+ end
28
+ end
29
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chicanery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
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-09 00:00:00.000000000 Z
12
+ date: 2012-12-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -108,9 +108,8 @@ files:
108
108
  - Rakefile
109
109
  - bin/chicanery
110
110
  - chicanery.gemspec
111
- - examples/evil.rb
112
- - examples/github.rb
113
- - examples/travis.rb
111
+ - examples/baby_steps.rb
112
+ - examples/chicanery.rb
114
113
  - lib/chicanery.rb
115
114
  - lib/chicanery/cctray.rb
116
115
  - lib/chicanery/collections.rb
@@ -118,9 +117,11 @@ files:
118
117
  - lib/chicanery/handlers.rb
119
118
  - lib/chicanery/persistence.rb
120
119
  - lib/chicanery/state_comparison.rb
120
+ - lib/chicanery/summary.rb
121
121
  - spec/chicanery/collections_spec.rb
122
122
  - spec/chicanery/persistence_spec.rb
123
123
  - spec/chicanery/state_comparison_spec.rb
124
+ - spec/chicanery/summary_spec.rb
124
125
  - spec/chicanery_spec.rb
125
126
  homepage: http://github.com/markryall/chicanery
126
127
  licenses: []
@@ -136,7 +137,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
137
  version: '0'
137
138
  segments:
138
139
  - 0
139
- hash: -2101217152092119930
140
+ hash: -1603803825861310736
140
141
  required_rubygems_version: !ruby/object:Gem::Requirement
141
142
  none: false
142
143
  requirements:
@@ -145,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
146
  version: '0'
146
147
  segments:
147
148
  - 0
148
- hash: -2101217152092119930
149
+ hash: -1603803825861310736
149
150
  requirements: []
150
151
  rubyforge_project:
151
152
  rubygems_version: 1.8.23
@@ -156,4 +157,5 @@ test_files:
156
157
  - spec/chicanery/collections_spec.rb
157
158
  - spec/chicanery/persistence_spec.rb
158
159
  - spec/chicanery/state_comparison_spec.rb
160
+ - spec/chicanery/summary_spec.rb
159
161
  - spec/chicanery_spec.rb
data/examples/evil.rb DELETED
@@ -1,24 +0,0 @@
1
- require 'chicanery/git'
2
-
3
- include Chicanery::Git
4
-
5
- git_repo 'chicanery', '.', branches: [:master]
6
-
7
- start = Time.now.to_i
8
- maximum = ARGV.shift.to_i
9
-
10
- puts "Uncommitted changes will be automatically reverted after #{maximum} seconds"
11
-
12
- when_run do |state|
13
- elapsed = Time.now.to_i - start
14
- if elapsed >= maximum
15
- puts "no commits detected in #{elapsed} seconds - reverting all uncommitted changes"
16
- `git reset --hard`
17
- start = Time.now.to_i
18
- end
19
- end
20
-
21
- when_commit do |branch, commit, previous|
22
- puts "commit detected - resetting timer"
23
- start = Time.now.to_i
24
- end
data/examples/github.rb DELETED
@@ -1,11 +0,0 @@
1
- require 'chicanery/git'
2
-
3
- include Chicanery::Git
4
-
5
- git_repo 'chicanery', '.', branches: [:master], remotes: {
6
- github: { url: 'git://github.com/markryall/chicanery.git' }
7
- }
8
-
9
- when_commit do |branch, commit, previous|
10
- puts "commit #{previous}..#{commit} detected in #{branch}"
11
- end