ci_status 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,27 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ci_status (0.1.0)
5
+ nokogiri (~> 1.5)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ addressable (2.3.2)
11
+ crack (0.3.1)
12
+ minitest (4.3.3)
13
+ nokogiri (1.5.5)
14
+ rake (10.0.2)
15
+ webmock (1.9.0)
16
+ addressable (>= 2.2.7)
17
+ crack (>= 0.1.7)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ bundler
24
+ ci_status!
25
+ minitest
26
+ rake
27
+ webmock
data/MIT-LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Morten Primdahl
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.
data/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # CI Status
2
+
3
+ Client for generic CI status pages
4
+
5
+ ## Cruise Control
6
+
7
+ ```ruby
8
+ c = CiStatus::CruiseControl.new("http://example.com/cc.xml")
9
+ c.projects.each do |project|
10
+ puts project.name
11
+ puts project.success?
12
+ puts project.time
13
+ end
14
+ ```
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rake/testtask'
4
+ Rake::TestTask.new do |test|
5
+ test.libs << 'lib'
6
+ test.pattern = 'test/**/test_*.rb'
7
+ test.verbose = true
8
+ end
9
+
10
+ task :default do
11
+ sh "bundle exec rake test"
12
+ end
data/ci_status.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new "ci_status", "0.1.0" do |s|
2
+ s.summary = "CI status interface"
3
+ s.description = "Library for reading, parsing and presenting cruise control style build status pages (think CCMenu, CCTray)"
4
+ s.authors = [ "Morten Primdahl" ]
5
+ s.email = "primdahl@me.com"
6
+ s.homepage = "http://github.com/morten/ci_status"
7
+
8
+ s.add_runtime_dependency("nokogiri", "~> 1.5")
9
+
10
+ s.add_development_dependency("rake")
11
+ s.add_development_dependency("bundler")
12
+ s.add_development_dependency("minitest")
13
+ s.add_development_dependency("webmock")
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.license = "MIT"
17
+ end
@@ -0,0 +1,50 @@
1
+ require "open-uri"
2
+ require "nokogiri"
3
+
4
+ module CiStatus
5
+ # Parses the CC format (also used by CCMenu, CCTray etc.)
6
+ class CruiseControl
7
+ attr_accessor :url
8
+
9
+ def initialize(url)
10
+ self.url = url
11
+ end
12
+
13
+ def projects
14
+ @projects ||= document.xpath("/Projects/Project").map do |project|
15
+ Project.new do |p|
16
+ p.name = project["name"]
17
+ p.url = project["webUrl"]
18
+ p.time = project["lastBuildTime"]
19
+ p.status = project["lastBuildStatus"]
20
+ end
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def document
27
+ @document ||= Nokogiri::XML(data)
28
+ end
29
+
30
+ def data
31
+ @data ||= open(url).read
32
+ end
33
+
34
+ class Project
35
+ attr_accessor :name, :url, :time, :status
36
+
37
+ def initialize(&block)
38
+ yield self if block_given?
39
+ end
40
+
41
+ def success?
42
+ status == "Success"
43
+ end
44
+
45
+ def failure?
46
+ status == "Failure"
47
+ end
48
+ end
49
+ end
50
+ end
data/lib/ci_status.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "ci_status/cruise_control"
2
+
3
+ module CiStatus
4
+ end
@@ -0,0 +1,5 @@
1
+ <Projects>
2
+ <Project webUrl="https://jenkins.example.com/job/Analytics/" name="Analytics" lastBuildLabel="19" lastBuildTime="2012-04-02T15:49:54Z" lastBuildStatus="Success" activity="Sleeping"/>
3
+ <Project webUrl="https://jenkins.example.com/job/API/" name="API" lastBuildLabel="128" lastBuildTime="2012-12-10T22:58:09Z" lastBuildStatus="Failure" activity="Sleeping"/>
4
+ <Project webUrl="https://jenkins.example.com/job/AppMarket/" name="AppMarket" lastBuildLabel="752" lastBuildTime="2012-12-12T20:17:19Z" lastBuildStatus="Success" activity="Sleeping"/>
5
+ </Projects>
data/test/helper.rb ADDED
@@ -0,0 +1,22 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+
4
+ Bundler.require(:test)
5
+
6
+ require "minitest/spec"
7
+ require "minitest/mock"
8
+ require "minitest/autorun"
9
+ require "webmock/minitest"
10
+
11
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
12
+ $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), "../lib")))
13
+
14
+ require "ci_status"
15
+
16
+ def fixture_path
17
+ File.join(File.dirname(__FILE__), "fixtures")
18
+ end
19
+
20
+ def cc_fixture
21
+ File.read(File.join(fixture_path, "cc.xml"))
22
+ end
@@ -0,0 +1,26 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), "helper")
2
+
3
+
4
+ describe CiStatus::CruiseControl do
5
+
6
+ before { stub_request(:get, "http://example.com/cc.xml").to_return(:body => cc_fixture) }
7
+ subject { CiStatus::CruiseControl.new("http://example.com/cc.xml") }
8
+
9
+ it "surfaces the input URL" do
10
+ assert_equal "http://example.com/cc.xml", subject.url
11
+ end
12
+
13
+ describe "#projects" do
14
+ it "returns the expected projects" do
15
+ assert_equal 3, subject.projects.size
16
+
17
+ project = subject.projects.first
18
+
19
+ assert_equal "https://jenkins.example.com/job/Analytics/", project.url
20
+ assert_equal "Analytics", project.name
21
+ assert_equal "Success", project.status
22
+ assert project.success?
23
+ end
24
+ end
25
+
26
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ci_status
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Morten Primdahl
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.5'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.5'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: minitest
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
+ - !ruby/object:Gem::Dependency
79
+ name: webmock
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: Library for reading, parsing and presenting cruise control style build
95
+ status pages (think CCMenu, CCTray)
96
+ email: primdahl@me.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - Gemfile
102
+ - Gemfile.lock
103
+ - MIT-LICENSE.txt
104
+ - README.md
105
+ - Rakefile
106
+ - ci_status.gemspec
107
+ - lib/ci_status.rb
108
+ - lib/ci_status/cruise_control.rb
109
+ - test/fixtures/cc.xml
110
+ - test/helper.rb
111
+ - test/test_cruise_control.rb
112
+ homepage: http://github.com/morten/ci_status
113
+ licenses:
114
+ - MIT
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 1.8.23
134
+ signing_key:
135
+ specification_version: 3
136
+ summary: CI status interface
137
+ test_files: []