chicanery 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.2"
4
+ - "1.9.3"
data/Gemfile.lock CHANGED
@@ -1,30 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chicanery (0.0.3)
4
+ chicanery (0.0.4)
5
5
  nokogiri (~> 1)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- aruba (0.5.0)
11
- childprocess (= 0.2.3)
12
- cucumber (>= 1.1.1)
13
- ffi (>= 1.0.11)
14
- rspec-expectations (>= 2.7.0)
15
- builder (3.1.4)
16
- childprocess (0.2.3)
17
- ffi (~> 1.0.6)
18
- cucumber (1.2.1)
19
- builder (>= 2.1.2)
20
- diff-lcs (>= 1.1.3)
21
- gherkin (~> 2.11.0)
22
- json (>= 1.4.6)
23
10
  diff-lcs (1.1.3)
24
- ffi (1.0.11)
25
- gherkin (2.11.5)
26
- json (>= 1.4.6)
27
- json (1.7.5)
28
11
  nokogiri (1.5.5)
29
12
  rake (0.9.2.2)
30
13
  rspec (2.11.0)
@@ -40,7 +23,6 @@ PLATFORMS
40
23
  ruby
41
24
 
42
25
  DEPENDENCIES
43
- aruba (~> 0)
44
26
  chicanery!
45
27
  rake (~> 0)
46
28
  rspec (~> 2)
data/README.md CHANGED
@@ -1,24 +1,78 @@
1
- # Chicanery
1
+ # Chicanery [![Build Status](https://secure.travis-ci.org/markryall/chicanery.png)](http://travis-ci.org/markryall/chicanery)
2
2
 
3
- TODO: Write a gem description
3
+ This is a command line tool to trigger any kind of action in response to any interesting event in a software development project (such as build server events, commit events, deployment events, etc.).
4
+
5
+ This is intended to run unattended on a server and is not really intended for local notifications on a developer's machine. If this is what you're looking for, take a look at [build reactor](https://github.com/AdamNowotny/BuildReactor) instead.
6
+
7
+ Any kind of action can be taken in response to these events - playing a sound, announcement in an irc session, firing a projectile at a developer, emitting an odour etc.
8
+
9
+ State is persisted between executions so that it be scheduled to run regularly with crontab or it can simply be run as a long polling process.
4
10
 
5
11
  ## Installation
6
12
 
7
- Add this line to your application's Gemfile:
13
+ $ gem install chicanery
8
14
 
9
- gem 'chicanery'
15
+ ## Usage
10
16
 
11
- And then execute:
17
+ Create a configuration file. This file is just a ruby file that can make use of a few configuration and callback methods:
12
18
 
13
- $ bundle
19
+ require 'chicanery/cctray'
14
20
 
15
- Or install it yourself as:
21
+ server Chicanery::Cctray.new 'tddium', 'https://cihost.com/cctray.xml'
16
22
 
17
- $ gem install chicanery
23
+ when_succeeded do |job_name, job|
24
+ puts "#{job_name} has succeeded"
25
+ end
18
26
 
19
- ## Usage
27
+ when_failed do |job_name, job|
28
+ puts "#{job_name} has failed"
29
+ end
30
+
31
+ when_broken do |job_name, job|
32
+ `afplay ~/build_sounds/ambulance.mp3`
33
+ puts "#{job_name} is broken"
34
+ end
35
+
36
+ when_fixed do |job_name, job|
37
+ `afplay ~/build_sounds/applause.mp3`
38
+ puts "#{job_name} is fixed"
39
+ end
40
+
41
+ Now you can schedule the following command with cron:
42
+
43
+ chicanery myconfiguration
44
+
45
+ Or continuously poll every 10 seconds:
46
+
47
+ chicanery myconfiguration 10
48
+
49
+ You'll notice a file called 'state' is created which represents the state at the last execution. This is then restored during the next execution to detect events such as a new build succeeding/failing.
50
+
51
+ ## Supported CI servers
52
+
53
+ Currently only ci servers that can provide [cctray reporting format](http://confluence.public.thoughtworks.org/display/CI/Multiple+Project+Summary+Reporting+Standard) are supported.
54
+
55
+ This includes thoughtworks go, tddium, travisci, jenkins, cc.net and several others:
56
+
57
+ For a jenkins or hudson server, monitor http://jenkins-server:8080/cc.xml
58
+
59
+ For a go server, monitor https://go-server:8154/go/cctray.xml
60
+
61
+ For a travis ci project, monitor https://api.travis-ci.org/repositories/owner/project/cc.xml
62
+
63
+ For a tddium project, monitor the link 'Configure with CCMenu' which will look something like https://api.tddium.com/cc/long_uuid_string/cctray.xml
64
+
65
+ Basic authentication is supported by passing :user => 'user', :password => 'password' to the Chicanery::Cctray constructor. https is supported without performing certificate verification (some ci servers such as thoughtworks go generates a self signed cert that would otherwise be rejected without significant messing around).
66
+
67
+ ## Plans for world domination
20
68
 
21
- TODO: Write usage instructions here
69
+ * monitoring a git repository for push notifications
70
+ * monitoring a mercurial repository for push notifications
71
+ * monitoring a subversion repository for commit notifications
72
+ * monitoring heroku for deployment event notification
73
+ * monitoring more ci servers (atlassian bamboo, jetbrains team city, etc.)
74
+ * integration with the blinky gem to control a delcom build light
75
+ * other interesting notifier plugins or examples
22
76
 
23
77
  ## Contributing
24
78
 
data/Rakefile CHANGED
@@ -1 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ task :default do
4
+ sh 'bundle exec rspec spec'
5
+ end
data/chicanery.gemspec CHANGED
@@ -21,5 +21,4 @@ Gem::Specification.new do |gem|
21
21
 
22
22
  gem.add_development_dependency 'rake', '~>0'
23
23
  gem.add_development_dependency 'rspec', '~>2'
24
- gem.add_development_dependency 'aruba', '~>0'
25
24
  end
@@ -0,0 +1,26 @@
1
+ require 'chicanery/cctray'
2
+
3
+ server Chicanery::Cctray.new 'travis', 'https://api.travis-ci.org/repositories/markryall/chicanery/cc.xml'
4
+
5
+ when_started do |job_name, job|
6
+ `afplay ~/build_sounds/startup.mp3`
7
+ puts "job #{job_name} has started"
8
+ end
9
+
10
+ when_succeeded do |job_name, job|
11
+ puts "job #{job_name} #{job[:last_label]} has succeeded"
12
+ end
13
+
14
+ when_failed do |job_name, job|
15
+ puts "job #{job_name} #{job[:last_label]} has failed"
16
+ end
17
+
18
+ when_broken do |job_name, job|
19
+ `afplay ~/build_sounds/ambulance.mp3`
20
+ puts "job #{job_name} is broken"
21
+ end
22
+
23
+ when_fixed do |job_name, job|
24
+ `afplay ~/build_sounds/applause.mp3`
25
+ puts "job #{job_name} is fixed"
26
+ end
data/lib/chicanery.rb CHANGED
@@ -9,7 +9,7 @@ module Chicanery
9
9
  include Handlers
10
10
  include StateComparison
11
11
 
12
- VERSION = "0.0.3"
12
+ VERSION = "0.0.4"
13
13
 
14
14
  def execute *args
15
15
  load args.shift
@@ -26,7 +26,7 @@ module Chicanery
26
26
  end
27
27
  run_handlers.each {|handler| handler.call current_state }
28
28
  persist current_state
29
- exit unless poll_period
29
+ break unless poll_period
30
30
  sleep poll_period.to_i
31
31
  end
32
32
  end
@@ -23,9 +23,9 @@ module Chicanery
23
23
  jobs = {}
24
24
  Nokogiri::XML(get).css("Project").each do |project|
25
25
  job = {
26
- activity: project[:activity],
26
+ activity: project[:activity] == 'Sleeping' ? :sleeping : :building,
27
27
  last_build_status: project[:lastBuildStatus] == 'Success' ? :success : :failure,
28
- last_build_time: DateTime.parse(project[:lastBuildTime]),
28
+ last_build_time: project[:lastBuildTime].empty? ? nil : DateTime.parse(project[:lastBuildTime]),
29
29
  url: project[:webUrl],
30
30
  last_label: project[:lastBuildLabel]
31
31
  }
@@ -35,7 +35,7 @@ module Chicanery
35
35
  end
36
36
 
37
37
  def filtered name
38
- return true unless options[:include]
38
+ return false unless options[:include]
39
39
  !options[:include].match(name)
40
40
  end
41
41
  end
@@ -1,6 +1,6 @@
1
1
  module Chicanery
2
2
  module Handlers
3
- %w{run succeeded failed broken fixed}.each do |status|
3
+ %w{run started succeeded failed broken fixed}.each do |status|
4
4
  class_eval <<-EOF
5
5
  def when_#{status} &block
6
6
  #{status}_handlers << block
@@ -9,6 +9,10 @@ module Chicanery
9
9
  def #{status}_handlers
10
10
  @#{status}_handlers ||= []
11
11
  end
12
+
13
+ def notify_#{status}_handlers *args
14
+ #{status}_handlers.each {|handler| handler.call *args }
15
+ end
12
16
  EOF
13
17
  end
14
18
  end
@@ -3,17 +3,20 @@ module Chicanery
3
3
  def compare_jobs current_jobs, previous_jobs
4
4
  return unless previous_jobs
5
5
  current_jobs.each do |job_name, job|
6
- compare_job job_name, job, previous_jobs[job_name]
6
+ compare_job job_name, job, previous_jobs[job_name] if previous_jobs[job_name]
7
7
  end
8
8
  end
9
9
 
10
10
  def compare_job name, current, previous
11
- return unless current and previous
12
- return unless current[:last_build_time] > previous[:last_build_time]
13
- succeeded_handlers.each {|handler| handler.call name, current } if current[:last_build_status] == :success
14
- failed_handlers.each {|handler| handler.call name, current } if current[:last_build_status] == :failure
15
- broken_handlers.each {|handler| handler.call name, current } if current[:last_build_status] == :failure and previous[:last_build_status] == :success
16
- fixed_handlers.each {|handler| handler.call name, current } if current[:last_build_status] == :success and previous[:last_build_status] == :failure
11
+ return unless current[:last_build_time] != previous[:last_build_time]
12
+ if current[:activity] == :building and previous[:activity] == :sleeping
13
+ notify_started_handlers name, current
14
+ return
15
+ end
16
+ notify_succeeded_handlers name, current if current[:last_build_status] == :success
17
+ notify_failed_handlers name, current if current[:last_build_status] == :failure
18
+ notify_broken_handlers name, current if current[:last_build_status] == :failure and previous[:last_build_status] == :success
19
+ notify_fixed_handlers name, current if current[:last_build_status] == :success and previous[:last_build_status] == :failure
17
20
  end
18
21
  end
19
22
  end
@@ -0,0 +1,20 @@
1
+ require 'chicanery/state_comparison'
2
+
3
+ describe Chicanery::StateComparison do
4
+ include Chicanery::StateComparison
5
+
6
+ let(:current_jobs) { {} }
7
+ let(:previous_jobs) { {} }
8
+
9
+ it 'should do nothing when there are no jobs in current state' do
10
+ should_not_receive :compare_job
11
+ previous_jobs[:job] = {}
12
+ compare_jobs current_jobs, previous_jobs
13
+ end
14
+
15
+ it 'should do nothing when there is no previous state' do
16
+ should_not_receive :compare_job
17
+ current_jobs[:job] = {}
18
+ compare_jobs current_jobs, previous_jobs
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ require 'chicanery'
2
+
3
+ describe Chicanery do
4
+ include Chicanery
5
+
6
+ describe '#execute' do
7
+ it 'should load configuration and exit immediately when nothing is configured no poll period is provided' do
8
+ should_receive(:load).with 'configuration'
9
+ execute 'configuration'
10
+ end
11
+ end
12
+ 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.3
4
+ version: 0.0.4
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-11-17 00:00:00.000000000 Z
12
+ date: 2012-11-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -59,22 +59,6 @@ dependencies:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: '2'
62
- - !ruby/object:Gem::Dependency
63
- name: aruba
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ~>
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
- type: :development
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ~>
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
62
  description: trigger various events related to a continuous integration environment
79
63
  email:
80
64
  - mark@ryall.name
@@ -84,6 +68,7 @@ extensions: []
84
68
  extra_rdoc_files: []
85
69
  files:
86
70
  - .gitignore
71
+ - .travis.yml
87
72
  - Gemfile
88
73
  - Gemfile.lock
89
74
  - LICENSE.txt
@@ -91,11 +76,7 @@ files:
91
76
  - Rakefile
92
77
  - bin/chicanery
93
78
  - chicanery.gemspec
94
- - cucumber.yml
95
- - examples/go_server.rb
96
- - features/ci.feature
97
- - features/step_definitions/ci_steps.rb
98
- - features/support/env.rb
79
+ - examples/travis.rb
99
80
  - lib/chicanery.rb
100
81
  - lib/chicanery/cctray.rb
101
82
  - lib/chicanery/handlers.rb
@@ -104,6 +85,8 @@ files:
104
85
  - lib/chicanery/state_comparison.rb
105
86
  - spec/broken.xml
106
87
  - spec/building.xml
88
+ - spec/chicanery/state_comparison_spec.rb
89
+ - spec/chicanery_spec.rb
107
90
  homepage: http://github.com/markryall/chicanery
108
91
  licenses: []
109
92
  post_install_message:
@@ -118,7 +101,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
118
101
  version: '0'
119
102
  segments:
120
103
  - 0
121
- hash: -2729598607174781804
104
+ hash: -3725593527818179587
122
105
  required_rubygems_version: !ruby/object:Gem::Requirement
123
106
  none: false
124
107
  requirements:
@@ -127,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
110
  version: '0'
128
111
  segments:
129
112
  - 0
130
- hash: -2729598607174781804
113
+ hash: -3725593527818179587
131
114
  requirements: []
132
115
  rubyforge_project:
133
116
  rubygems_version: 1.8.23
@@ -135,8 +118,7 @@ signing_key:
135
118
  specification_version: 3
136
119
  summary: polls various resources related to a ci environment and performs custom notifications
137
120
  test_files:
138
- - features/ci.feature
139
- - features/step_definitions/ci_steps.rb
140
- - features/support/env.rb
141
121
  - spec/broken.xml
142
122
  - spec/building.xml
123
+ - spec/chicanery/state_comparison_spec.rb
124
+ - spec/chicanery_spec.rb
data/cucumber.yml DELETED
@@ -1,2 +0,0 @@
1
- default: -r features -t ~@wip
2
- wip: -r features -t @wip --wip
@@ -1 +0,0 @@
1
- puts "loading configuration from #{__FILE__}"
data/features/ci.feature DELETED
@@ -1,21 +0,0 @@
1
- Feature: ci
2
-
3
- In order to know I have working software
4
- As a software delivery team member
5
- I want to receive notifications from my ci build
6
-
7
- @wip
8
- Scenario: no previous state and passing build
9
- Given I have ci jobs:
10
- | name | status | activity |
11
- | job1 | success | sleeping |
12
- | job2 | success | sleeping |
13
- And a stdout ci handler
14
- When I engage in chicanery
15
- Then the exit status should be 0
16
- And the stdout should contain:
17
- """
18
- job1 is ok
19
- job2 is ok
20
- all jobs are ok
21
- """
@@ -1,28 +0,0 @@
1
- require 'erb'
2
-
3
- Given /^I have ci jobs:$/ do |table|
4
- @jobs = table.hashes
5
- end
6
-
7
- Given /^a stdout ci handler$/ do
8
- @handlers = <<EOF
9
- when_anything do |state|
10
- state.jobs each do |job|
11
- puts "#{job.name} is #{job.status}"
12
- end
13
- end
14
- EOF
15
- end
16
-
17
- When /^I engage in chicanery$/ do
18
- jobs, handlers = @jobs, @handlers
19
- template = ERB.new <<EOF
20
- <% @jobs.each do |job| %>
21
- job "<%= job['name'] %>
22
- <% end %>
23
-
24
- <% @handlers %>
25
- EOF
26
- write_file 'configuration', template.result(binding)
27
- run_simple 'chicanery configuration'
28
- end
@@ -1,3 +0,0 @@
1
- require 'aruba/cucumber'
2
-
3
- ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"