chicanery 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,9 +1,9 @@
1
1
  *.gem
2
2
  *.rbc
3
+ *.example
3
4
  .bundle
4
5
  .config
5
6
  .yardoc
6
- Gemfile.lock
7
7
  InstalledFiles
8
8
  _yardoc
9
9
  coverage
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ state
data/Gemfile.lock ADDED
@@ -0,0 +1,46 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ chicanery (0.0.2)
5
+ nokogiri (~> 1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
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
+ 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
+ nokogiri (1.5.5)
29
+ rake (0.9.2.2)
30
+ rspec (2.11.0)
31
+ rspec-core (~> 2.11.0)
32
+ rspec-expectations (~> 2.11.0)
33
+ rspec-mocks (~> 2.11.0)
34
+ rspec-core (2.11.1)
35
+ rspec-expectations (2.11.3)
36
+ diff-lcs (~> 1.1.3)
37
+ rspec-mocks (2.11.3)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ aruba (~> 0)
44
+ chicanery!
45
+ rake (~> 0)
46
+ rspec (~> 2)
data/bin/chicanery CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  $:.unshift File.dirname(__FILE__)+'/../lib'
4
4
 
5
- require 'chicanery/cli'
6
-
7
- Chicanery::Cli.execute *ARGV
5
+ require 'chicanery'
6
+ extend Chicanery
7
+ execute *ARGV
data/chicanery.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'chicanery/version'
4
+ require 'chicanery'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "chicanery"
@@ -17,8 +17,9 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
 
20
- gem.add_dependency 'nokogiri', '~>1.5'
20
+ gem.add_dependency 'nokogiri', '~>1'
21
21
 
22
- gem.add_development_dependency 'rake', '~>0.9'
22
+ gem.add_development_dependency 'rake', '~>0'
23
23
  gem.add_development_dependency 'rspec', '~>2'
24
+ gem.add_development_dependency 'aruba', '~>0'
24
25
  end
data/cucumber.yml ADDED
@@ -0,0 +1,2 @@
1
+ default: -r features -t ~@wip
2
+ wip: -r features -t @wip --wip
@@ -0,0 +1 @@
1
+ puts "loading configuration from #{__FILE__}"
@@ -0,0 +1,21 @@
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
+ """
@@ -0,0 +1,28 @@
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
@@ -0,0 +1,3 @@
1
+ require 'aruba/cucumber'
2
+
3
+ ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
@@ -0,0 +1,36 @@
1
+ require 'net/http'
2
+ require 'nokogiri'
3
+ require 'date'
4
+
5
+ module Chicanery
6
+ class Cctray
7
+ attr_reader :name, :uri, :user, :password
8
+
9
+ def initialize name, url, user, password
10
+ @name, @uri, @user, @password = name, URI(url), user, password
11
+ end
12
+
13
+ def get
14
+ req = Net::HTTP::Get.new(uri.path)
15
+ req.basic_auth user, password
16
+ res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https', verify_mode: OpenSSL::SSL::VERIFY_NONE) do |https|
17
+ https.request(req)
18
+ end
19
+ res.body
20
+ end
21
+
22
+ def jobs
23
+ jobs = {}
24
+ Nokogiri::XML(get).css("Project").each do |project|
25
+ jobs[project[:name]]= {
26
+ activity: project[:activity],
27
+ last_build_status: project[:lastBuildStatus] == 'Success' ? :success : :failure,
28
+ last_build_time: DateTime.parse(project[:lastBuildTime]),
29
+ url: project[:webUrl],
30
+ last_label: project[:lastBuildLabel]
31
+ }
32
+ end
33
+ jobs
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,15 @@
1
+ module Chicanery
2
+ module Handlers
3
+ %w{run succeeded failed broken fixed}.each do |status|
4
+ class_eval <<-EOF
5
+ def when_#{status} &block
6
+ #{status}_handlers << block
7
+ end
8
+
9
+ def #{status}_handlers
10
+ @#{status}_handlers ||= []
11
+ end
12
+ EOF
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ require 'yaml'
2
+
3
+ module Chicanery
4
+ module Persistence
5
+ def persist state
6
+ File.open 'state', 'w' do |file|
7
+ file.puts state.to_yaml
8
+ end
9
+ end
10
+
11
+ def restore
12
+ return {} unless File.exist? 'state'
13
+ YAML.load_file 'state'
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ module Chicanery
2
+ module Servers
3
+ def server new_server
4
+ servers << new_server
5
+ end
6
+
7
+ def servers
8
+ @servers ||= []
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ module Chicanery
2
+ module StateComparison
3
+ def compare_jobs current_jobs, previous_jobs
4
+ return unless previous_jobs
5
+ current_jobs.each do |job_name, job|
6
+ compare_job job_name, job, previous_jobs[job_name]
7
+ end
8
+ end
9
+
10
+ def compare_job name, current, previous
11
+ return unless current[:last_build_time] > previous[:last_build_time]
12
+ succeeded_handlers.each {|handler| handler.call name, current } if current[:last_build_status] == :success
13
+ failed_handlers.each {|handler| handler.call name, current } if current[:last_build_status] == :failure
14
+ broken_handlers.each {|handler| handler.call name, current } if current[:last_build_status] == :failure and previous[:last_build_status] == :success
15
+ fixed_handlers.each {|handler| handler.call name, current } if current[:last_build_status] == :success and previous[:last_build_status] == :failure
16
+ end
17
+ end
18
+ end
data/lib/chicanery.rb CHANGED
@@ -1,5 +1,28 @@
1
- require "chicanery/version"
1
+ require 'chicanery/persistence'
2
+ require 'chicanery/servers'
3
+ require 'chicanery/handlers'
4
+ require 'chicanery/state_comparison'
2
5
 
3
6
  module Chicanery
4
- # Your code goes here...
5
- end
7
+ include Persistence
8
+ include Servers
9
+ include Handlers
10
+ include StateComparison
11
+
12
+ VERSION = "0.0.2"
13
+
14
+ def execute *args
15
+ load args.shift
16
+ previous_state = restore
17
+ current_state = {
18
+ servers: {}
19
+ }
20
+ servers.each do |server|
21
+ current_jobs = server.jobs
22
+ compare_jobs current_jobs, previous_state[:servers][server.name] if previous_state[:servers]
23
+ current_state[:servers][server.name] = current_jobs
24
+ end
25
+ run_handlers.each {|handler| handler.call current_state }
26
+ persist current_state
27
+ end
28
+ end
data/spec/broken.xml CHANGED
@@ -5,12 +5,12 @@
5
5
  <Project name="sampleproject :: specs :: specs" activity="Sleeping" lastBuildStatus="Success" lastBuildLabel="55" lastBuildTime="2012-11-10T12:39:46" webUrl="http://192.168.1.2:8153/go/tab/build/detail/sampleproject/55/specs/1/specs" />
6
6
  <Project name="sampleproject :: features" activity="Sleeping" lastBuildStatus="Failure" lastBuildLabel="55" lastBuildTime="2012-11-10T13:06:00" webUrl="http://192.168.1.2:8153/go/pipelines/sampleproject/55/features/1">
7
7
  <messages>
8
- <message text="suren reddy &lt;suren@sampleproject.com&gt;" kind="Breakers" />
8
+ <message text="build breaker &lt;buildbreaker@sampleproject.com&gt;" kind="Breakers" />
9
9
  </messages>
10
10
  </Project>
11
11
  <Project name="sampleproject :: features :: features" activity="Sleeping" lastBuildStatus="Failure" lastBuildLabel="55" lastBuildTime="2012-11-10T13:06:00" webUrl="http://192.168.1.2:8153/go/tab/build/detail/sampleproject/55/features/1/features">
12
12
  <messages>
13
- <message text="suren reddy &lt;suren@sampleproject.com&gt;" kind="Breakers" />
13
+ <message text="build breaker &lt;buildbreaker@sampleproject.com&gt;" kind="Breakers" />
14
14
  </messages>
15
15
  </Project>
16
16
  <Project name="sampleproject :: staging" activity="Sleeping" lastBuildStatus="Success" lastBuildLabel="51" lastBuildTime="2012-10-23T00:23:22" webUrl="http://192.168.1.2:8153/go/pipelines/sampleproject/51/staging/1" />
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.1
4
+ version: 0.0.2
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-10 00:00:00.000000000 Z
12
+ date: 2012-11-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '1.5'
21
+ version: '1'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: '1.5'
29
+ version: '1'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rake
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: '0.9'
37
+ version: '0'
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: '0.9'
45
+ version: '0'
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: rspec
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -59,6 +59,22 @@ 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'
62
78
  description: trigger various events related to a continuous integration environment
63
79
  email:
64
80
  - mark@ryall.name
@@ -69,14 +85,23 @@ extra_rdoc_files: []
69
85
  files:
70
86
  - .gitignore
71
87
  - Gemfile
88
+ - Gemfile.lock
72
89
  - LICENSE.txt
73
90
  - README.md
74
91
  - Rakefile
75
92
  - bin/chicanery
76
93
  - 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
77
99
  - lib/chicanery.rb
78
- - lib/chicanery/cli.rb
79
- - lib/chicanery/version.rb
100
+ - lib/chicanery/cctray.rb
101
+ - lib/chicanery/handlers.rb
102
+ - lib/chicanery/persistence.rb
103
+ - lib/chicanery/servers.rb
104
+ - lib/chicanery/state_comparison.rb
80
105
  - spec/broken.xml
81
106
  - spec/building.xml
82
107
  homepage: http://github.com/markryall/chicanery
@@ -93,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
118
  version: '0'
94
119
  segments:
95
120
  - 0
96
- hash: -250293994565924049
121
+ hash: -836833897029006138
97
122
  required_rubygems_version: !ruby/object:Gem::Requirement
98
123
  none: false
99
124
  requirements:
@@ -102,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
127
  version: '0'
103
128
  segments:
104
129
  - 0
105
- hash: -250293994565924049
130
+ hash: -836833897029006138
106
131
  requirements: []
107
132
  rubyforge_project:
108
133
  rubygems_version: 1.8.23
@@ -110,5 +135,8 @@ signing_key:
110
135
  specification_version: 3
111
136
  summary: polls various resources related to a ci environment and performs custom notifications
112
137
  test_files:
138
+ - features/ci.feature
139
+ - features/step_definitions/ci_steps.rb
140
+ - features/support/env.rb
113
141
  - spec/broken.xml
114
142
  - spec/building.xml
data/lib/chicanery/cli.rb DELETED
@@ -1,7 +0,0 @@
1
- module Chicanery
2
- module Cli
3
- def self.execute *args
4
- puts args
5
- end
6
- end
7
- end
@@ -1,3 +0,0 @@
1
- module Chicanery
2
- VERSION = "0.0.1"
3
- end