jenkins-status-tool 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -101,26 +101,28 @@ lets say that our Jenkins server is running on ```jenkins-server:1234```
101
101
  ## Embed it
102
102
  you can easily embed the current status of your builds in any html type document.
103
103
 
104
+ **HTML**
105
+
104
106
  ```
105
- <img src="https://jenkins-status-tool-url/projects/PROJECT-NAME/status.png"/>
107
+ <img src="https://jenkins-status-tool-url/project/PROJECT-NAME/status.png"/>
106
108
  ```
107
109
 
108
- TextLite
110
+ **TextLite**
109
111
 
110
112
  ```bash
111
- "!https://jenkins-status-tool-url/projects/PROJECT-NAME/status.png!":http://jenkins.example.com/jobs/PROJET-NAME
113
+ "!https://jenkins-status-tool-url/project/PROJECT-NAME/status.png!":http://jenkins.example.com/jobs/PROJET-NAME
112
114
  ```
113
115
 
114
- RDoc
116
+ **RDoc**
115
117
 
116
118
  ```bash
117
- {<img src="https://jenkins-status-tool-url/projects/PROJECT-NAME/status.png" />}[http://jenkins.example.com/jobs/PROJET-NAME]
119
+ {<img src="https://jenkins-status-tool-url/project/PROJECT-NAME/status.png" />}[http://jenkins.example.com/jobs/PROJET-NAME]
118
120
  ```
119
121
 
120
- MarkDown
122
+ **MarkDown**
121
123
 
122
124
  ```bash
123
- [![Build Status](https://jenkins-status-tool-url/projects/PROJECT-NAME/status.png)](http://jenkins.example.com/jobs/PROJET-NAME)
125
+ [![Build Status](https://jenkins-status-tool-url/project/PROJECT-NAME/status.png)](http://jenkins.example.com/jobs/PROJET-NAME)
124
126
  ```
125
127
 
126
128
  >
@@ -1,22 +1,23 @@
1
- require 'ostruct'
2
1
  require 'singleton'
3
2
 
4
3
  module JenkinsStatusTool
5
- class Config < OpenStruct
4
+ class Config
5
+
6
6
  include Singleton
7
+
8
+ attr_reader :options
7
9
 
8
10
  def initialize
9
- super
10
- self.port = 7676
11
- self.jenkins = "localhost:8080"
12
- self.pid = '/var/run/jenkins-status-tool.pid'
13
- self.root = File.expand_path File.join(JenkinsStatusTool::ROOT, "..")
14
- self.https = false
11
+ @options = Utils.default_options
15
12
  end
16
13
 
17
14
  def https?
18
- self.https
15
+ options[:https]
16
+ end
17
+
18
+ def method_missing(m, *a, &b)
19
+ options.fetch(m) rescue options.send(m,*a,&b)
19
20
  end
20
21
 
21
22
  end
22
- end
23
+ end
@@ -1,24 +1,35 @@
1
1
  require 'rubygems'
2
2
  require 'open-uri'
3
- require 'singleton'
4
3
  require 'json'
5
4
 
6
5
  module JenkinsStatusTool
7
6
  class JenkinsBroker
8
- include Singleton
9
7
 
10
8
  def project_info project
11
- json["jobs"].select {|o| o["name"] == project}.first rescue Hash.new
9
+ find_job project or Hash.new
12
10
  end
13
11
 
14
12
  def raw relative_path
15
- open("http://#{Config.instance.jenkins}/#{relative_path}").read rescue nil
13
+ open("http://#{jenkins}/#{relative_path}").read rescue nil
16
14
  end
17
-
15
+
18
16
  private
17
+
18
+ def jobs
19
+ json["jobs"] || Array.new { Hash.new }
20
+ end
21
+
22
+ def find_job job
23
+ jobs.select {|o| o["name"] == job}.first
24
+ end
25
+
26
+ def jenkins
27
+ Config.instance.jenkins
28
+ end
29
+
19
30
  def json
20
- JSON.parse open("http://#{Config.instance.jenkins}/api/json").read
31
+ JSON.parse open("http://#{jenkins}/api/json").read
21
32
  end
22
-
33
+
23
34
  end
24
- end
35
+ end
@@ -1,25 +1,29 @@
1
- require 'ostruct'
2
-
3
1
  module JenkinsStatusTool
4
- class JenkinsProject < OpenStruct
2
+ class JenkinsProject
3
+
4
+ attr_reader :project, :jenkins
5
5
 
6
6
  def initialize hash
7
- super
8
- self.project = hash.fetch :project
9
- self.jenkins = JenkinsBroker::instance
7
+ @project = hash.fetch :project
8
+ @jenkins = JenkinsBroker.new
10
9
  end
11
10
 
12
11
  def status
13
12
  case color
14
- when /red/ then :fail
15
- when /blue/ then :pass
16
- when /gray/ then :inactive
13
+ when :red then :fail
14
+ when :blue then :pass
15
+ when :gray then :inactive
17
16
  else :unknown
18
17
  end
19
18
  end
20
19
 
21
20
  def color
22
- data["color"]
21
+ case data["color"]
22
+ when /red/ then :red
23
+ when /blue/ then :blue
24
+ when /gray/ then :gray
25
+ else nil
26
+ end
23
27
  end
24
28
 
25
29
  def rcov_image
@@ -28,7 +32,7 @@ module JenkinsStatusTool
28
32
 
29
33
  private
30
34
  def rcov_path
31
- [job,project,rcov,graph].join "/"
35
+ ["job",project,"rcov","graph"].join "/"
32
36
  end
33
37
 
34
38
  def data
@@ -33,23 +33,23 @@ module JenkinsStatusTool
33
33
  opts.separator "Options:"
34
34
 
35
35
  opts.on('-j', '--jenkins URL', 'Jenkins url, e.g http://jenkins:8080, default is localhost') do |url|
36
- config.jenkins = url
36
+ config[:jenkins] = url
37
37
  end
38
38
 
39
39
  opts.on('-p', '--port URL', 'listening port, default is 7676') do |port|
40
- config.port = port
40
+ config[:port] = port
41
41
  end
42
42
 
43
43
  opts.on("-d", "--daemonize","run in background") do
44
- config.daemonize = true
44
+ config[:daemonize] = true
45
45
  end
46
46
 
47
47
  opts.on("-P", "--pid-file FILE","pid file, default /var/run/jenkins-status-tool.pid") do |file|
48
- config.pid = file
48
+ config[:pid] = file
49
49
  end
50
50
 
51
51
  opts.on('-s', '--https', 'add this switch if you are running behind https forwarder (e.g stunnel)') do
52
- config.https = true
52
+ config[:https] = true
53
53
  end
54
54
 
55
55
  opts.separator ""
@@ -1,17 +1,17 @@
1
- require 'singleton'
2
-
3
1
  module JenkinsStatusTool
4
2
  module Utils
3
+ module_function
5
4
 
6
- class Singleton
7
- include Object::Singleton
8
-
9
- def self.method_missing(m,*a,&b)
10
- instance.send(m,*a,&b)
11
- end
12
-
5
+ def default_options
6
+ {
7
+ :port => 7676,
8
+ :jenkins => "localhost:8080",
9
+ :pid => '/tmp/jenkins-status-tool.pid',
10
+ :root => File.expand_path("../../..",__FILE__),
11
+ :https => false,
12
+ :daemonize => false
13
+ }
13
14
  end
14
15
 
15
16
  end
16
- end
17
-
17
+ end
@@ -1,5 +1,5 @@
1
1
  module JenkinsStatusTool
2
2
  class Version
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
@@ -3,8 +3,8 @@ require 'sinatra/base'
3
3
  module JenkinsStatusTool
4
4
  class WebApp < Sinatra::Base
5
5
 
6
- set :root, Config::instance.root
7
- set :port, Config::instance.port
6
+ set :root, Config.instance.root
7
+ set :port, Config.instance.port
8
8
 
9
9
  get "/" do
10
10
  erb :index
@@ -53,8 +53,8 @@ module JenkinsStatusTool
53
53
  @project ||= JenkinsProject.new symbolize_params
54
54
  end
55
55
 
56
- def config
57
- Config::instance
56
+ def config
57
+ Config.instance
58
58
  end
59
59
 
60
60
  end
@@ -4,8 +4,8 @@ JenkinsStatusTool::GemSpec = Gem::Specification.new do |s|
4
4
  s.name = "jenkins-status-tool"
5
5
  s.version = JenkinsStatusTool.version
6
6
  s.platform = Gem::Platform::RUBY
7
- s.summary = "JenkinsStatusTool"
8
- s.description = "JenkinsStatusTool - get jenkins status"
7
+ s.summary = "A Small web-service that fetch project status from Jenkins/Hudson"
8
+ s.description = "Small tool to get the build status from Jenkins. Useful for embedding Jenkins CI status images on your Github project."
9
9
  s.author = "Eran Barak Levi"
10
10
  s.email = 'eran@kontera.com'
11
11
  s.homepage = 'http://www.kontera.com'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jenkins-status-tool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-05 00:00:00.000000000 Z
12
+ date: 2012-04-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
16
- requirement: &70176230374160 !ruby/object:Gem::Requirement
16
+ requirement: &70231733093720 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70176230374160
24
+ version_requirements: *70231733093720
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &70176230373560 !ruby/object:Gem::Requirement
27
+ requirement: &70231733093140 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,8 +32,9 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70176230373560
36
- description: JenkinsStatusTool - get jenkins status
35
+ version_requirements: *70231733093140
36
+ description: Small tool to get the build status from Jenkins. Useful for embedding
37
+ Jenkins CI status images on your Github project.
37
38
  email: eran@kontera.com
38
39
  executables:
39
40
  - jenkins-status-tool
@@ -84,5 +85,5 @@ rubyforge_project: jenkins-status-tool
84
85
  rubygems_version: 1.8.15
85
86
  signing_key:
86
87
  specification_version: 3
87
- summary: JenkinsStatusTool
88
+ summary: A Small web-service that fetch project status from Jenkins/Hudson
88
89
  test_files: []