city_watch 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +47 -0
- data/README.md +10 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/bin/city_watch +28 -0
- data/city_watch.gemspec +141 -0
- data/lib/city_watch.rb +15 -0
- data/lib/city_watch/build_monitor.rb +15 -0
- data/lib/city_watch/page.rb +29 -0
- data/lib/city_watch/watcher.rb +33 -0
- data/spec/LICENSE.txt +20 -0
- data/spec/city_watch/build_monitor_spec.rb +32 -0
- data/spec/city_watch/page_spec.rb +28 -0
- data/spec/city_watch/watcher_spec.rb +45 -0
- data/spec/fixtures/page.html +14 -0
- data/spec/fixtures/running_builds.xml +5 -0
- data/spec/spec_helper.rb +16 -0
- metadata +492 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
city_watch (0.0.0)
|
5
|
+
city_watch
|
6
|
+
daemons (~> 1.1.0)
|
7
|
+
growl (~> 1.0.3)
|
8
|
+
nokogiri (~> 1.4.4)
|
9
|
+
rest-client (~> 1.6.1)
|
10
|
+
thor (~> 0.14.6)
|
11
|
+
|
12
|
+
GEM
|
13
|
+
remote: http://rubygems.org/
|
14
|
+
specs:
|
15
|
+
daemons (1.1.0)
|
16
|
+
diff-lcs (1.1.2)
|
17
|
+
git (1.2.5)
|
18
|
+
growl (1.0.3)
|
19
|
+
jeweler (1.5.2)
|
20
|
+
bundler (~> 1.0.0)
|
21
|
+
git (>= 1.2.5)
|
22
|
+
rake
|
23
|
+
mime-types (1.16)
|
24
|
+
nokogiri (1.4.4)
|
25
|
+
rake (0.8.7)
|
26
|
+
rcov (0.9.9)
|
27
|
+
rest-client (1.6.1)
|
28
|
+
mime-types (>= 1.16)
|
29
|
+
rspec (2.3.0)
|
30
|
+
rspec-core (~> 2.3.0)
|
31
|
+
rspec-expectations (~> 2.3.0)
|
32
|
+
rspec-mocks (~> 2.3.0)
|
33
|
+
rspec-core (2.3.1)
|
34
|
+
rspec-expectations (2.3.0)
|
35
|
+
diff-lcs (~> 1.1.2)
|
36
|
+
rspec-mocks (2.3.0)
|
37
|
+
thor (0.14.6)
|
38
|
+
|
39
|
+
PLATFORMS
|
40
|
+
ruby
|
41
|
+
|
42
|
+
DEPENDENCIES
|
43
|
+
bundler (~> 1.0.0)
|
44
|
+
city_watch!
|
45
|
+
jeweler (~> 1.5.2)
|
46
|
+
rcov
|
47
|
+
rspec (~> 2.3.0)
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "city_watch"
|
16
|
+
gem.homepage = "http://github.com/richmolj/city_watch"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{one-line summary of your gem}
|
19
|
+
gem.description = %Q{longer description of your gem}
|
20
|
+
gem.email = "richmolj@gmail.com"
|
21
|
+
gem.authors = ["Lee Richmond"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
gem.add_runtime_dependency 'thor', '~> 0.14.6'
|
25
|
+
gem.add_runtime_dependency 'daemons', '~> 1.1.0'
|
26
|
+
gem.add_runtime_dependency 'growl', '~> 1.0.3'
|
27
|
+
gem.add_runtime_dependency 'rest-client', '~> 1.6.1'
|
28
|
+
gem.add_runtime_dependency 'nokogiri', '~> 1.4.4'
|
29
|
+
end
|
30
|
+
Jeweler::RubygemsDotOrgTasks.new
|
31
|
+
|
32
|
+
require 'rspec/core'
|
33
|
+
require 'rspec/core/rake_task'
|
34
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
35
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
36
|
+
end
|
37
|
+
|
38
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
39
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
40
|
+
spec.rcov = true
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :spec
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "city_watch #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/city_watch
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'city_watch'
|
4
|
+
|
5
|
+
class CityWatchCommandLine < Thor
|
6
|
+
desc "start www.yoururl.com 'your build title'", "start watching teamcity"
|
7
|
+
def start(url, build_title, project_id)
|
8
|
+
CityWatch.url = url
|
9
|
+
CityWatch.build_title = build_title
|
10
|
+
CityWatch.build_title = project_id
|
11
|
+
daemon
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "stop" ,"stop watching teamcity"
|
15
|
+
def stop
|
16
|
+
daemon
|
17
|
+
end
|
18
|
+
|
19
|
+
no_tasks do
|
20
|
+
def daemon
|
21
|
+
Daemons.run_proc('city_watch', :dir => '/tmp/pids') do
|
22
|
+
CityWatch::Watcher.start
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
CityWatchCommandLine.start
|
data/city_watch.gemspec
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{city_watch}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Lee Richmond"]
|
12
|
+
s.date = %q{2011-03-07}
|
13
|
+
s.default_executable = %q{city_watch}
|
14
|
+
s.description = %q{longer description of your gem}
|
15
|
+
s.email = %q{richmolj@gmail.com}
|
16
|
+
s.executables = ["city_watch"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"README.md"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
".rspec",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"README.md",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"bin/city_watch",
|
29
|
+
"city_watch.gemspec",
|
30
|
+
"lib/city_watch.rb",
|
31
|
+
"lib/city_watch/build_monitor.rb",
|
32
|
+
"lib/city_watch/page.rb",
|
33
|
+
"lib/city_watch/watcher.rb",
|
34
|
+
"spec/LICENSE.txt",
|
35
|
+
"spec/city_watch/build_monitor_spec.rb",
|
36
|
+
"spec/city_watch/page_spec.rb",
|
37
|
+
"spec/city_watch/watcher_spec.rb",
|
38
|
+
"spec/fixtures/page.html",
|
39
|
+
"spec/fixtures/running_builds.xml",
|
40
|
+
"spec/spec_helper.rb"
|
41
|
+
]
|
42
|
+
s.homepage = %q{http://github.com/richmolj/city_watch}
|
43
|
+
s.licenses = ["MIT"]
|
44
|
+
s.require_paths = ["lib"]
|
45
|
+
s.rubygems_version = %q{1.4.2}
|
46
|
+
s.summary = %q{one-line summary of your gem}
|
47
|
+
s.test_files = [
|
48
|
+
"spec/city_watch/build_monitor_spec.rb",
|
49
|
+
"spec/city_watch/page_spec.rb",
|
50
|
+
"spec/city_watch/watcher_spec.rb",
|
51
|
+
"spec/spec_helper.rb"
|
52
|
+
]
|
53
|
+
|
54
|
+
if s.respond_to? :specification_version then
|
55
|
+
s.specification_version = 3
|
56
|
+
|
57
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
58
|
+
s.add_runtime_dependency(%q<city_watch>, [">= 0"])
|
59
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
60
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
61
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
62
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
63
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
64
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
65
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
66
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
67
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
68
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
69
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
70
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
71
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
72
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
73
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
74
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
75
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
76
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
77
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
78
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
79
|
+
s.add_runtime_dependency(%q<thor>, ["~> 0.14.6"])
|
80
|
+
s.add_runtime_dependency(%q<daemons>, ["~> 1.1.0"])
|
81
|
+
s.add_runtime_dependency(%q<growl>, ["~> 1.0.3"])
|
82
|
+
s.add_runtime_dependency(%q<rest-client>, ["~> 1.6.1"])
|
83
|
+
s.add_runtime_dependency(%q<nokogiri>, ["~> 1.4.4"])
|
84
|
+
else
|
85
|
+
s.add_dependency(%q<city_watch>, [">= 0"])
|
86
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
87
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
88
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
89
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
90
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
91
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
92
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
93
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
94
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
95
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
96
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
97
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
98
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
99
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
100
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
101
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
102
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
103
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
104
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
105
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
106
|
+
s.add_dependency(%q<thor>, ["~> 0.14.6"])
|
107
|
+
s.add_dependency(%q<daemons>, ["~> 1.1.0"])
|
108
|
+
s.add_dependency(%q<growl>, ["~> 1.0.3"])
|
109
|
+
s.add_dependency(%q<rest-client>, ["~> 1.6.1"])
|
110
|
+
s.add_dependency(%q<nokogiri>, ["~> 1.4.4"])
|
111
|
+
end
|
112
|
+
else
|
113
|
+
s.add_dependency(%q<city_watch>, [">= 0"])
|
114
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
115
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
116
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
117
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
118
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
119
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
120
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
121
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
122
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
123
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
124
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
125
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
126
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
127
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
128
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
129
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
130
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
131
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
132
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
133
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
134
|
+
s.add_dependency(%q<thor>, ["~> 0.14.6"])
|
135
|
+
s.add_dependency(%q<daemons>, ["~> 1.1.0"])
|
136
|
+
s.add_dependency(%q<growl>, ["~> 1.0.3"])
|
137
|
+
s.add_dependency(%q<rest-client>, ["~> 1.6.1"])
|
138
|
+
s.add_dependency(%q<nokogiri>, ["~> 1.4.4"])
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
data/lib/city_watch.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'daemons'
|
3
|
+
require 'growl'
|
4
|
+
require 'rest_client'
|
5
|
+
require 'nokogiri'
|
6
|
+
|
7
|
+
require 'city_watch/page'
|
8
|
+
require 'city_watch/build_monitor'
|
9
|
+
require 'city_watch/watcher'
|
10
|
+
|
11
|
+
module CityWatch
|
12
|
+
class << self
|
13
|
+
attr_accessor :url, :build_title, :project_id
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module CityWatch
|
2
|
+
class BuildMonitor
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
xml = RestClient.get("#{CityWatch.url}/ajax.html?getRunningBuilds=1")
|
6
|
+
@doc = Nokogiri::XML(xml)
|
7
|
+
end
|
8
|
+
|
9
|
+
def failure?(build_id)
|
10
|
+
@doc.xpath("//*[@buildId='#{build_id}']").first.
|
11
|
+
attributes['successful'].value == 'false'
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module CityWatch
|
2
|
+
class Page
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
html = RestClient.get("#{CityWatch.url}/project.html?projectId=#{CityWatch.project_id}")
|
6
|
+
@doc = Nokogiri::HTML(html)
|
7
|
+
end
|
8
|
+
|
9
|
+
# Todo: this is gross.
|
10
|
+
def build_id
|
11
|
+
@doc.xpath("//a[contains(.,'#{CityWatch.build_title}')]").
|
12
|
+
first.
|
13
|
+
parent.
|
14
|
+
parent.
|
15
|
+
next_sibling.
|
16
|
+
next_sibling.
|
17
|
+
children.
|
18
|
+
first.
|
19
|
+
children[2].
|
20
|
+
children[1].
|
21
|
+
attributes['id'].
|
22
|
+
value.
|
23
|
+
split(':')[1].
|
24
|
+
split(':')[0].
|
25
|
+
to_i
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module CityWatch
|
2
|
+
class Watcher
|
3
|
+
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def start
|
7
|
+
loop do
|
8
|
+
if failure?
|
9
|
+
growl
|
10
|
+
sleep 10 while failure?
|
11
|
+
end
|
12
|
+
sleep 10
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def failure?
|
17
|
+
page = CityWatch::Page.new
|
18
|
+
monitor = CityWatch::BuildMonitor.new
|
19
|
+
monitor.failure?(page.build_id)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def growl
|
25
|
+
Growl.send "notify_warning", "TeamCity build '#{CityWatch.build_title}' failed!",
|
26
|
+
:title => "City Watch",
|
27
|
+
:sticky => true
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
data/spec/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Lee Richmond
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe CityWatch::BuildMonitor do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@html = File.read('spec/fixtures/running_builds.xml')
|
7
|
+
RestClient.stub!(:get).with("#{CityWatch.url}/ajax.html?getRunningBuilds=1").and_return(@html)
|
8
|
+
end
|
9
|
+
|
10
|
+
context "an instance of a BuildMonitor" do
|
11
|
+
before do
|
12
|
+
@build_monitor = CityWatch::BuildMonitor.new
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#initialize" do
|
16
|
+
it "should get xml of the build statuses" do
|
17
|
+
@build_monitor.instance_variable_get(:@doc).should be_a(Nokogiri::XML::Document)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#failure?" do
|
22
|
+
it "should return false if there was not a failure" do
|
23
|
+
@build_monitor.should_not be_failure(247776)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return true if there was a failure" do
|
27
|
+
@build_monitor.should be_failure(247774)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe CityWatch::Page do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@html = File.read('spec/fixtures/page.html')
|
7
|
+
RestClient.stub!(:get).with("#{CityWatch.url}/project.html?projectId=#{CityWatch.project_id}").and_return(@html)
|
8
|
+
end
|
9
|
+
|
10
|
+
context "an instance of CityWatch::Client" do
|
11
|
+
before do
|
12
|
+
@page = CityWatch::Page.new
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#initialize" do
|
16
|
+
it "should grab the html of the TC page" do
|
17
|
+
@page.instance_variable_get(:@doc).should be_a(Nokogiri::HTML::Document)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#build_id" do
|
22
|
+
it "should parse the html to get the build id" do
|
23
|
+
@page.build_id.should == 247644
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe CityWatch::Watcher do
|
4
|
+
|
5
|
+
describe ".start" do
|
6
|
+
before do
|
7
|
+
CityWatch::Watcher.should_receive(:loop).and_yield(nil)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should growl if there is a failure" do
|
11
|
+
CityWatch::Watcher.should_receive(:sleep).with(10).twice
|
12
|
+
Growl.should_receive(:send).with("notify_warning", "TeamCity build '#{CityWatch.build_title}' failed!",
|
13
|
+
:title => "City Watch",
|
14
|
+
:sticky => true)
|
15
|
+
|
16
|
+
CityWatch::Watcher.should_receive(:failure?).and_return(true, true, false)
|
17
|
+
CityWatch::Watcher.start
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should not growl if there is no failure" do
|
21
|
+
CityWatch::Watcher.should_receive(:sleep).with(10).once
|
22
|
+
Growl.should_not_receive(:send)
|
23
|
+
CityWatch::Watcher.should_receive(:failure?).and_return(false)
|
24
|
+
CityWatch::Watcher.start
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe ".failure?" do
|
29
|
+
def setup(opts)
|
30
|
+
page = CityWatch::Page.should_receive(:new).and_return(mock(:build_id => 1))
|
31
|
+
monitor = CityWatch::BuildMonitor.should_receive(:new).and_return(mock(:failure? => opts[:failure]))
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return true when there is a failure" do
|
35
|
+
setup(:failure => true)
|
36
|
+
CityWatch::Watcher.should be_failure
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should return false when there is not a failure" do
|
40
|
+
setup(:failure => false)
|
41
|
+
CityWatch::Watcher.should_not be_failure
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,5 @@
|
|
1
|
+
<response>
|
2
|
+
<build buildId="247776" text="Running" successful="true" remainingTime="26s" exceededEstimatedDurationTime="< 1s" elapsedTime="18s" completedPercent="42" hasArtifacts="false"/>
|
3
|
+
<build buildId="247774" text="Running" successful="false" remainingTime="21m:03s" exceededEstimatedDurationTime="< 1s" elapsedTime="2m:28s" completedPercent="11" hasArtifacts="false"/>
|
4
|
+
<build buildId="247773" text="Changes are already collected" successful="true" remainingTime="4m:09s" exceededEstimatedDurationTime="< 1s" elapsedTime="5m:23s" completedPercent="57" hasArtifacts="false"/>
|
5
|
+
</response>
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'city_watch'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
CityWatch.build_title = 'Spec Build'
|
15
|
+
CityWatch.url = 'www.fake.com'
|
16
|
+
CityWatch.project_id = 1
|
metadata
ADDED
@@ -0,0 +1,492 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: city_watch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Lee Richmond
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-03-07 00:00:00 -05:00
|
19
|
+
default_executable: city_watch
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
type: :runtime
|
23
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
requirement: *id001
|
33
|
+
prerelease: false
|
34
|
+
name: city_watch
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
type: :development
|
37
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 2
|
45
|
+
- 3
|
46
|
+
- 0
|
47
|
+
version: 2.3.0
|
48
|
+
requirement: *id002
|
49
|
+
prerelease: false
|
50
|
+
name: rspec
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
type: :development
|
53
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 23
|
59
|
+
segments:
|
60
|
+
- 1
|
61
|
+
- 0
|
62
|
+
- 0
|
63
|
+
version: 1.0.0
|
64
|
+
requirement: *id003
|
65
|
+
prerelease: false
|
66
|
+
name: bundler
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
type: :development
|
69
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ~>
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 7
|
75
|
+
segments:
|
76
|
+
- 1
|
77
|
+
- 5
|
78
|
+
- 2
|
79
|
+
version: 1.5.2
|
80
|
+
requirement: *id004
|
81
|
+
prerelease: false
|
82
|
+
name: jeweler
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
type: :development
|
85
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
requirement: *id005
|
95
|
+
prerelease: false
|
96
|
+
name: rcov
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
type: :development
|
99
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ~>
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
hash: 3
|
105
|
+
segments:
|
106
|
+
- 2
|
107
|
+
- 3
|
108
|
+
- 0
|
109
|
+
version: 2.3.0
|
110
|
+
requirement: *id006
|
111
|
+
prerelease: false
|
112
|
+
name: rspec
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
type: :development
|
115
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ~>
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
hash: 23
|
121
|
+
segments:
|
122
|
+
- 1
|
123
|
+
- 0
|
124
|
+
- 0
|
125
|
+
version: 1.0.0
|
126
|
+
requirement: *id007
|
127
|
+
prerelease: false
|
128
|
+
name: bundler
|
129
|
+
- !ruby/object:Gem::Dependency
|
130
|
+
type: :development
|
131
|
+
version_requirements: &id008 !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
133
|
+
requirements:
|
134
|
+
- - ~>
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
hash: 7
|
137
|
+
segments:
|
138
|
+
- 1
|
139
|
+
- 5
|
140
|
+
- 2
|
141
|
+
version: 1.5.2
|
142
|
+
requirement: *id008
|
143
|
+
prerelease: false
|
144
|
+
name: jeweler
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
type: :development
|
147
|
+
version_requirements: &id009 !ruby/object:Gem::Requirement
|
148
|
+
none: false
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
hash: 3
|
153
|
+
segments:
|
154
|
+
- 0
|
155
|
+
version: "0"
|
156
|
+
requirement: *id009
|
157
|
+
prerelease: false
|
158
|
+
name: rcov
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
type: :development
|
161
|
+
version_requirements: &id010 !ruby/object:Gem::Requirement
|
162
|
+
none: false
|
163
|
+
requirements:
|
164
|
+
- - ~>
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
hash: 3
|
167
|
+
segments:
|
168
|
+
- 2
|
169
|
+
- 3
|
170
|
+
- 0
|
171
|
+
version: 2.3.0
|
172
|
+
requirement: *id010
|
173
|
+
prerelease: false
|
174
|
+
name: rspec
|
175
|
+
- !ruby/object:Gem::Dependency
|
176
|
+
type: :development
|
177
|
+
version_requirements: &id011 !ruby/object:Gem::Requirement
|
178
|
+
none: false
|
179
|
+
requirements:
|
180
|
+
- - ~>
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
hash: 23
|
183
|
+
segments:
|
184
|
+
- 1
|
185
|
+
- 0
|
186
|
+
- 0
|
187
|
+
version: 1.0.0
|
188
|
+
requirement: *id011
|
189
|
+
prerelease: false
|
190
|
+
name: bundler
|
191
|
+
- !ruby/object:Gem::Dependency
|
192
|
+
type: :development
|
193
|
+
version_requirements: &id012 !ruby/object:Gem::Requirement
|
194
|
+
none: false
|
195
|
+
requirements:
|
196
|
+
- - ~>
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
hash: 7
|
199
|
+
segments:
|
200
|
+
- 1
|
201
|
+
- 5
|
202
|
+
- 2
|
203
|
+
version: 1.5.2
|
204
|
+
requirement: *id012
|
205
|
+
prerelease: false
|
206
|
+
name: jeweler
|
207
|
+
- !ruby/object:Gem::Dependency
|
208
|
+
type: :development
|
209
|
+
version_requirements: &id013 !ruby/object:Gem::Requirement
|
210
|
+
none: false
|
211
|
+
requirements:
|
212
|
+
- - ">="
|
213
|
+
- !ruby/object:Gem::Version
|
214
|
+
hash: 3
|
215
|
+
segments:
|
216
|
+
- 0
|
217
|
+
version: "0"
|
218
|
+
requirement: *id013
|
219
|
+
prerelease: false
|
220
|
+
name: rcov
|
221
|
+
- !ruby/object:Gem::Dependency
|
222
|
+
type: :development
|
223
|
+
version_requirements: &id014 !ruby/object:Gem::Requirement
|
224
|
+
none: false
|
225
|
+
requirements:
|
226
|
+
- - ~>
|
227
|
+
- !ruby/object:Gem::Version
|
228
|
+
hash: 3
|
229
|
+
segments:
|
230
|
+
- 2
|
231
|
+
- 3
|
232
|
+
- 0
|
233
|
+
version: 2.3.0
|
234
|
+
requirement: *id014
|
235
|
+
prerelease: false
|
236
|
+
name: rspec
|
237
|
+
- !ruby/object:Gem::Dependency
|
238
|
+
type: :development
|
239
|
+
version_requirements: &id015 !ruby/object:Gem::Requirement
|
240
|
+
none: false
|
241
|
+
requirements:
|
242
|
+
- - ~>
|
243
|
+
- !ruby/object:Gem::Version
|
244
|
+
hash: 23
|
245
|
+
segments:
|
246
|
+
- 1
|
247
|
+
- 0
|
248
|
+
- 0
|
249
|
+
version: 1.0.0
|
250
|
+
requirement: *id015
|
251
|
+
prerelease: false
|
252
|
+
name: bundler
|
253
|
+
- !ruby/object:Gem::Dependency
|
254
|
+
type: :development
|
255
|
+
version_requirements: &id016 !ruby/object:Gem::Requirement
|
256
|
+
none: false
|
257
|
+
requirements:
|
258
|
+
- - ~>
|
259
|
+
- !ruby/object:Gem::Version
|
260
|
+
hash: 7
|
261
|
+
segments:
|
262
|
+
- 1
|
263
|
+
- 5
|
264
|
+
- 2
|
265
|
+
version: 1.5.2
|
266
|
+
requirement: *id016
|
267
|
+
prerelease: false
|
268
|
+
name: jeweler
|
269
|
+
- !ruby/object:Gem::Dependency
|
270
|
+
type: :development
|
271
|
+
version_requirements: &id017 !ruby/object:Gem::Requirement
|
272
|
+
none: false
|
273
|
+
requirements:
|
274
|
+
- - ">="
|
275
|
+
- !ruby/object:Gem::Version
|
276
|
+
hash: 3
|
277
|
+
segments:
|
278
|
+
- 0
|
279
|
+
version: "0"
|
280
|
+
requirement: *id017
|
281
|
+
prerelease: false
|
282
|
+
name: rcov
|
283
|
+
- !ruby/object:Gem::Dependency
|
284
|
+
type: :development
|
285
|
+
version_requirements: &id018 !ruby/object:Gem::Requirement
|
286
|
+
none: false
|
287
|
+
requirements:
|
288
|
+
- - ~>
|
289
|
+
- !ruby/object:Gem::Version
|
290
|
+
hash: 3
|
291
|
+
segments:
|
292
|
+
- 2
|
293
|
+
- 3
|
294
|
+
- 0
|
295
|
+
version: 2.3.0
|
296
|
+
requirement: *id018
|
297
|
+
prerelease: false
|
298
|
+
name: rspec
|
299
|
+
- !ruby/object:Gem::Dependency
|
300
|
+
type: :development
|
301
|
+
version_requirements: &id019 !ruby/object:Gem::Requirement
|
302
|
+
none: false
|
303
|
+
requirements:
|
304
|
+
- - ~>
|
305
|
+
- !ruby/object:Gem::Version
|
306
|
+
hash: 23
|
307
|
+
segments:
|
308
|
+
- 1
|
309
|
+
- 0
|
310
|
+
- 0
|
311
|
+
version: 1.0.0
|
312
|
+
requirement: *id019
|
313
|
+
prerelease: false
|
314
|
+
name: bundler
|
315
|
+
- !ruby/object:Gem::Dependency
|
316
|
+
type: :development
|
317
|
+
version_requirements: &id020 !ruby/object:Gem::Requirement
|
318
|
+
none: false
|
319
|
+
requirements:
|
320
|
+
- - ~>
|
321
|
+
- !ruby/object:Gem::Version
|
322
|
+
hash: 7
|
323
|
+
segments:
|
324
|
+
- 1
|
325
|
+
- 5
|
326
|
+
- 2
|
327
|
+
version: 1.5.2
|
328
|
+
requirement: *id020
|
329
|
+
prerelease: false
|
330
|
+
name: jeweler
|
331
|
+
- !ruby/object:Gem::Dependency
|
332
|
+
type: :development
|
333
|
+
version_requirements: &id021 !ruby/object:Gem::Requirement
|
334
|
+
none: false
|
335
|
+
requirements:
|
336
|
+
- - ">="
|
337
|
+
- !ruby/object:Gem::Version
|
338
|
+
hash: 3
|
339
|
+
segments:
|
340
|
+
- 0
|
341
|
+
version: "0"
|
342
|
+
requirement: *id021
|
343
|
+
prerelease: false
|
344
|
+
name: rcov
|
345
|
+
- !ruby/object:Gem::Dependency
|
346
|
+
type: :runtime
|
347
|
+
version_requirements: &id022 !ruby/object:Gem::Requirement
|
348
|
+
none: false
|
349
|
+
requirements:
|
350
|
+
- - ~>
|
351
|
+
- !ruby/object:Gem::Version
|
352
|
+
hash: 43
|
353
|
+
segments:
|
354
|
+
- 0
|
355
|
+
- 14
|
356
|
+
- 6
|
357
|
+
version: 0.14.6
|
358
|
+
requirement: *id022
|
359
|
+
prerelease: false
|
360
|
+
name: thor
|
361
|
+
- !ruby/object:Gem::Dependency
|
362
|
+
type: :runtime
|
363
|
+
version_requirements: &id023 !ruby/object:Gem::Requirement
|
364
|
+
none: false
|
365
|
+
requirements:
|
366
|
+
- - ~>
|
367
|
+
- !ruby/object:Gem::Version
|
368
|
+
hash: 19
|
369
|
+
segments:
|
370
|
+
- 1
|
371
|
+
- 1
|
372
|
+
- 0
|
373
|
+
version: 1.1.0
|
374
|
+
requirement: *id023
|
375
|
+
prerelease: false
|
376
|
+
name: daemons
|
377
|
+
- !ruby/object:Gem::Dependency
|
378
|
+
type: :runtime
|
379
|
+
version_requirements: &id024 !ruby/object:Gem::Requirement
|
380
|
+
none: false
|
381
|
+
requirements:
|
382
|
+
- - ~>
|
383
|
+
- !ruby/object:Gem::Version
|
384
|
+
hash: 17
|
385
|
+
segments:
|
386
|
+
- 1
|
387
|
+
- 0
|
388
|
+
- 3
|
389
|
+
version: 1.0.3
|
390
|
+
requirement: *id024
|
391
|
+
prerelease: false
|
392
|
+
name: growl
|
393
|
+
- !ruby/object:Gem::Dependency
|
394
|
+
type: :runtime
|
395
|
+
version_requirements: &id025 !ruby/object:Gem::Requirement
|
396
|
+
none: false
|
397
|
+
requirements:
|
398
|
+
- - ~>
|
399
|
+
- !ruby/object:Gem::Version
|
400
|
+
hash: 13
|
401
|
+
segments:
|
402
|
+
- 1
|
403
|
+
- 6
|
404
|
+
- 1
|
405
|
+
version: 1.6.1
|
406
|
+
requirement: *id025
|
407
|
+
prerelease: false
|
408
|
+
name: rest-client
|
409
|
+
- !ruby/object:Gem::Dependency
|
410
|
+
type: :runtime
|
411
|
+
version_requirements: &id026 !ruby/object:Gem::Requirement
|
412
|
+
none: false
|
413
|
+
requirements:
|
414
|
+
- - ~>
|
415
|
+
- !ruby/object:Gem::Version
|
416
|
+
hash: 15
|
417
|
+
segments:
|
418
|
+
- 1
|
419
|
+
- 4
|
420
|
+
- 4
|
421
|
+
version: 1.4.4
|
422
|
+
requirement: *id026
|
423
|
+
prerelease: false
|
424
|
+
name: nokogiri
|
425
|
+
description: longer description of your gem
|
426
|
+
email: richmolj@gmail.com
|
427
|
+
executables:
|
428
|
+
- city_watch
|
429
|
+
extensions: []
|
430
|
+
|
431
|
+
extra_rdoc_files:
|
432
|
+
- README.md
|
433
|
+
files:
|
434
|
+
- .document
|
435
|
+
- .rspec
|
436
|
+
- Gemfile
|
437
|
+
- Gemfile.lock
|
438
|
+
- README.md
|
439
|
+
- Rakefile
|
440
|
+
- VERSION
|
441
|
+
- bin/city_watch
|
442
|
+
- city_watch.gemspec
|
443
|
+
- lib/city_watch.rb
|
444
|
+
- lib/city_watch/build_monitor.rb
|
445
|
+
- lib/city_watch/page.rb
|
446
|
+
- lib/city_watch/watcher.rb
|
447
|
+
- spec/LICENSE.txt
|
448
|
+
- spec/city_watch/build_monitor_spec.rb
|
449
|
+
- spec/city_watch/page_spec.rb
|
450
|
+
- spec/city_watch/watcher_spec.rb
|
451
|
+
- spec/fixtures/page.html
|
452
|
+
- spec/fixtures/running_builds.xml
|
453
|
+
- spec/spec_helper.rb
|
454
|
+
has_rdoc: true
|
455
|
+
homepage: http://github.com/richmolj/city_watch
|
456
|
+
licenses:
|
457
|
+
- MIT
|
458
|
+
post_install_message:
|
459
|
+
rdoc_options: []
|
460
|
+
|
461
|
+
require_paths:
|
462
|
+
- lib
|
463
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
464
|
+
none: false
|
465
|
+
requirements:
|
466
|
+
- - ">="
|
467
|
+
- !ruby/object:Gem::Version
|
468
|
+
hash: 3
|
469
|
+
segments:
|
470
|
+
- 0
|
471
|
+
version: "0"
|
472
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
473
|
+
none: false
|
474
|
+
requirements:
|
475
|
+
- - ">="
|
476
|
+
- !ruby/object:Gem::Version
|
477
|
+
hash: 3
|
478
|
+
segments:
|
479
|
+
- 0
|
480
|
+
version: "0"
|
481
|
+
requirements: []
|
482
|
+
|
483
|
+
rubyforge_project:
|
484
|
+
rubygems_version: 1.4.2
|
485
|
+
signing_key:
|
486
|
+
specification_version: 3
|
487
|
+
summary: one-line summary of your gem
|
488
|
+
test_files:
|
489
|
+
- spec/city_watch/build_monitor_spec.rb
|
490
|
+
- spec/city_watch/page_spec.rb
|
491
|
+
- spec/city_watch/watcher_spec.rb
|
492
|
+
- spec/spec_helper.rb
|