em-ci 0.0.1
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/README.md +78 -0
- data/lib/cctray/project.rb +34 -0
- data/lib/cctray/server.rb +95 -0
- data/lib/em-ci/version.rb +3 -0
- data/lib/em-ci.rb +40 -0
- metadata +114 -0
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# Test
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'em-ci'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install em-ci
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Basic usage
|
22
|
+
```ruby
|
23
|
+
|
24
|
+
require 'eventmachine'
|
25
|
+
require 'em-ci'
|
26
|
+
|
27
|
+
ci = EmCi.new 'http://jenkins.site/cc.xml'
|
28
|
+
|
29
|
+
# Add a callback
|
30
|
+
ci.on_run do |server|
|
31
|
+
if server.building?
|
32
|
+
puts 'Currently building'
|
33
|
+
elsif server.failure?
|
34
|
+
puts 'Last build failed'
|
35
|
+
elsif server.success?
|
36
|
+
puts 'All builds successful'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
EventMachine.run {
|
41
|
+
# run every 15 seconds
|
42
|
+
ci.start 15
|
43
|
+
}
|
44
|
+
```
|
45
|
+
|
46
|
+
### Multiple projects
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
#...
|
50
|
+
ci.on_run do |server|
|
51
|
+
if server['CustomProject'].sleeping?
|
52
|
+
puts 'Custom Project is sleeping'
|
53
|
+
end
|
54
|
+
|
55
|
+
server.projects.each do |project|
|
56
|
+
# do something with individual project
|
57
|
+
end
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
### Filtering projects
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
# Filter projects by name
|
65
|
+
ci = EmCi.new 'http://jenkins.site/cc.xml', { filter: ['ProjectA', 'ProjectB'] }
|
66
|
+
|
67
|
+
ci.on_run do |server|
|
68
|
+
# only ProjectA and ProjectB will be included in sleeping check
|
69
|
+
server.sleeping?
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
73
|
+
### Authentication
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
ci = EmCi.new 'http://jenkins.site/cc.xml', { auth: ['my-username', 'my-password-or-auth-token'] }
|
77
|
+
```
|
78
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module CcTray
|
2
|
+
class Project
|
3
|
+
attr_accessor :name, :url, :time, :status, :activity, :lastBuildLabel
|
4
|
+
|
5
|
+
def initialize(data)
|
6
|
+
import(data)
|
7
|
+
end
|
8
|
+
|
9
|
+
def import(data)
|
10
|
+
self.name = data[:name]
|
11
|
+
self.url = data[:webUrl]
|
12
|
+
self.time = data[:lastBuildTime]
|
13
|
+
self.status = data[:lastBuildStatus]
|
14
|
+
self.lastBuildLabel = data[:lastBuildLabel]
|
15
|
+
self.activity = data[:activity]
|
16
|
+
end
|
17
|
+
|
18
|
+
def building?
|
19
|
+
activity == 'Building'
|
20
|
+
end
|
21
|
+
|
22
|
+
def sleeping?
|
23
|
+
activity == 'Sleeping'
|
24
|
+
end
|
25
|
+
|
26
|
+
def success?
|
27
|
+
status == 'Success'
|
28
|
+
end
|
29
|
+
|
30
|
+
def failure?
|
31
|
+
status == 'Failure'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require "ox"
|
2
|
+
require 'eventmachine'
|
3
|
+
require 'em-http'
|
4
|
+
require 'em-promise'
|
5
|
+
|
6
|
+
module CcTray
|
7
|
+
class Server
|
8
|
+
|
9
|
+
attr_accessor :url, :options, :projects
|
10
|
+
|
11
|
+
def initialize(url, options = {})
|
12
|
+
self.url = url
|
13
|
+
self.options = options
|
14
|
+
|
15
|
+
self.projects = {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def run
|
19
|
+
deferred = EventMachine::Q.defer
|
20
|
+
|
21
|
+
http = request.get request_options
|
22
|
+
http.errback { deferred.reject 'request failed' }
|
23
|
+
http.callback {
|
24
|
+
parse http.response
|
25
|
+
deferred.resolve self.projects
|
26
|
+
}
|
27
|
+
|
28
|
+
deferred.promise
|
29
|
+
end
|
30
|
+
|
31
|
+
def [](name)
|
32
|
+
projects[name]
|
33
|
+
end
|
34
|
+
|
35
|
+
#summary methods
|
36
|
+
def sleeping?
|
37
|
+
all?.(&:sleeping?)
|
38
|
+
end
|
39
|
+
|
40
|
+
def building?
|
41
|
+
any?(&:building?)
|
42
|
+
end
|
43
|
+
|
44
|
+
def success?
|
45
|
+
all?(&:success?)
|
46
|
+
end
|
47
|
+
|
48
|
+
def failure?
|
49
|
+
any?(&:failure?)
|
50
|
+
end
|
51
|
+
|
52
|
+
protected
|
53
|
+
|
54
|
+
# Generate a new request
|
55
|
+
def request
|
56
|
+
EventMachine::HttpRequest.new(url)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Parse response XML, and break into projects
|
60
|
+
def parse(data)
|
61
|
+
Ox.parse(data).locate("Projects/Project").each do |project|
|
62
|
+
attrs = project.attributes
|
63
|
+
name = attrs[:name]
|
64
|
+
next if options[:filter].is_a?(Array) && !options[:filter].include?(name)
|
65
|
+
if self.projects.has_key? name
|
66
|
+
self.projects[name].import attrs
|
67
|
+
else
|
68
|
+
self.projects[name] = Project.new attrs
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def request_options
|
74
|
+
opts = {}
|
75
|
+
if options.has_key? :auth
|
76
|
+
opts[:head] = { authorization: options[:auth] }
|
77
|
+
end
|
78
|
+
opts
|
79
|
+
end
|
80
|
+
|
81
|
+
def any? &block
|
82
|
+
projects.each_value do |value|
|
83
|
+
return true if block.call value
|
84
|
+
end
|
85
|
+
false
|
86
|
+
end
|
87
|
+
|
88
|
+
def all? &block
|
89
|
+
projects.each_value do |value|
|
90
|
+
return false unless block.call value
|
91
|
+
end
|
92
|
+
true
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
data/lib/em-ci.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require 'em-ci/version'
|
4
|
+
require 'cctray/project'
|
5
|
+
require 'cctray/server'
|
6
|
+
|
7
|
+
module EmCi
|
8
|
+
|
9
|
+
def self.new *args
|
10
|
+
EmCi.new *args
|
11
|
+
end
|
12
|
+
|
13
|
+
class EmCi
|
14
|
+
def initialize(url, options)
|
15
|
+
@server = CcTray::Server.new url, options
|
16
|
+
|
17
|
+
@callbacks = {
|
18
|
+
run: [],
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def start(frequency)
|
23
|
+
run
|
24
|
+
@timer = EventMachine.add_periodic_timer(frequency) { run }
|
25
|
+
end
|
26
|
+
|
27
|
+
def run
|
28
|
+
@server.run.then(
|
29
|
+
lambda { |projects|
|
30
|
+
@callbacks[:run].each { |c| c.call(@server) }
|
31
|
+
},
|
32
|
+
lambda { |message| puts message }
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
def on_run(&block)
|
37
|
+
@callbacks[:run] << block
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: em-ci
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Billiam
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: eventmachine
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.0.3
|
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.0.3
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: em-http-request
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.0.3
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.0.3
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: em-promise
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.1.1
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.1.1
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: ox
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.9.4
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.9.4
|
78
|
+
description: Utility library for monitoring CI servers
|
79
|
+
email:
|
80
|
+
- billiamthesecond@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- lib/cctray/project.rb
|
86
|
+
- lib/cctray/server.rb
|
87
|
+
- lib/em-ci/version.rb
|
88
|
+
- lib/em-ci.rb
|
89
|
+
- README.md
|
90
|
+
homepage: https://github.com/billiam/em-ci
|
91
|
+
licenses: []
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 1.8.24
|
111
|
+
signing_key:
|
112
|
+
specification_version: 3
|
113
|
+
summary: EventMachine-friendly CI server monitor
|
114
|
+
test_files: []
|