guard-jenkins 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ coverage
2
+ .DS_Store
data/.rvmrc ADDED
@@ -0,0 +1,2 @@
1
+ rvm gemset use jenkins_status_banner_guard --create
2
+
data/Changelog.yml ADDED
@@ -0,0 +1,3 @@
1
+ Changelog:
2
+ - 0.1.0:
3
+ - initial sprint
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'http://www.rubygems.org/'
2
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ require 'rspec/core/rake_task'
6
+ Rspec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
9
+ task :test => :spec
data/Readme.markdown ADDED
@@ -0,0 +1,55 @@
1
+ # Guard-Jenkins#
2
+
3
+ Thanks for checking out this Jenkins Guard!
4
+
5
+ A
6
+ [RoadMap](https://github.com/justinstoller/guard-jenkins/wiki/Road-Map)
7
+ can be found on the
8
+ [Wiki](https://github.com/justinstoller/guard-jenkins/wiki/Home).
9
+
10
+ And a brief introduction can be found on the project's
11
+ [Homepage](https://justinstoller.github.com/guard-jenkins)
12
+
13
+ ## Usage: ##
14
+
15
+ ```bash
16
+
17
+ # rb-inotify allows guard to learn of fs events in much more
18
+ # performant way than simple polling
19
+ gem install rb-inotify guard-jenkins
20
+
21
+ # in either ~/ or $JENKINS_HOME
22
+ guard init jenkins
23
+ guard [start]
24
+
25
+ ```
26
+
27
+ ## Contributing: ##
28
+ Everyone should pitch in!
29
+
30
+ If you want to do development on this project you will need:
31
+
32
+ Rspec ~> 2.6
33
+ SimpleCov ~> 0.4
34
+
35
+ ### Submit an Issue: ###
36
+ Please file complete bug reports when filing issues
37
+ That includes your complete environment,
38
+ exactly what you were doing when it occurred,
39
+ and for good measure your zodiac sign, hair color, and favorite color.
40
+
41
+ Even better! If you could provide a link to a Gist or patch with tests
42
+ that quickly shows how to replicate the issue, that would be
43
+ perfect
44
+
45
+ ### Add a Feature: ###
46
+ Fork the project.
47
+ Add tests in a similar style to those that already exist (hrm...)
48
+ Add the feature
49
+ Issue a pull request!
50
+
51
+ ### Write Documentation/Show Examples: ###
52
+ Got an amazing jenkins configuration you've buit with this?
53
+ Add it to the
54
+ [wiki](https://github.com/justinstoller/guard-jenkins/wiki/Projects-Using)!
55
+
@@ -0,0 +1,22 @@
1
+ require File.expand_path( 'lib/guard/jenkins/version' )
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = 'guard-jenkins'
5
+ gem.version = Guard::JenkinsVersion::VERSION
6
+ gem.author = 'Justin Stoller'
7
+ gem.email = 'justin.stoller@gmail.com'
8
+ gem.homepage = 'http://justinstoller.github.com/jenkins_status_banner_guard'
9
+ gem.summary = 'a very short optional summary of jenkins_status_banner_guard'
10
+ gem.description = 'a longer required description of what jenkins_status_banner_guard does'
11
+
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- spec`.split("\n")
14
+ gem.require_paths = ['lib']
15
+
16
+ gem.add_development_dependency 'rspec', '~> 2.6'
17
+ gem.add_development_dependency 'simplecov', '~> 0.4'
18
+ gem.add_development_dependency 'rake'
19
+
20
+ gem.add_runtime_dependency 'guard'
21
+ gem.add_runtime_dependency 'nokogiri'
22
+ end
@@ -0,0 +1,139 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+ require 'nokogiri'
4
+
5
+ module Guard
6
+ class Jenkins < Guard
7
+
8
+ def initialize( watchers=[], options={} )
9
+ puts "watchers param for initialize:\n#{watchers.to_s}"
10
+ super
11
+
12
+ @jenkins_path = options[:jenkins].nil? ? '/var/lib/jenkins/' : options[:jenkins]
13
+ @skip_check = options[:skip_check].nil? ? false : true
14
+ @fail_img = options[:fail_img].nil? ? @jenkins_path + 'userContent/images/fail.png' : options[:fail_img]
15
+ @success_img = options[:success_img].nil? ? @jenkins_path + 'userContent/images/success.png' : options[:success_img]
16
+ end
17
+
18
+ def start(*args)
19
+ puts "args to #start:\n#{args.to_s}"
20
+ check_present_jobs unless @skip_check
21
+ end
22
+
23
+ def stop
24
+ true
25
+ end
26
+
27
+ def reload
28
+ check_present_jobs
29
+ end
30
+
31
+ def run_all
32
+ check_present_jobs
33
+ end
34
+
35
+ def run_on_change( paths=[] )
36
+ puts "run on change was called with #{paths.to_s}"
37
+ update_status_for paths
38
+ end
39
+
40
+ def check_present_jobs
41
+ job_names.each do |job|
42
+ update_image_for job
43
+ end
44
+ end
45
+
46
+ def update_image_for(job)
47
+ if success? job
48
+ link_success_img_for job
49
+ else
50
+ link_fail_img_for job
51
+ end
52
+ end
53
+
54
+ def get_job_name_from(path)
55
+ p = path.gsub(/\/builds.*$/, '')
56
+ q = p.gsub(/^jobs\//, '')
57
+ q
58
+ end
59
+
60
+ def update_status_for( paths=[] )
61
+ jobs = paths.map {|path| get_job_name_from path }
62
+ jobs.each do |job|
63
+ update_image_for job
64
+ end
65
+ end
66
+
67
+ def job_names
68
+ names = Dir.new(@jenkins_path + 'jobs')
69
+ names = names.reject {|dir| dir == '.' }
70
+ names = names.reject {|dir| dir == '..' }
71
+ names
72
+ end
73
+
74
+ def last_success_file(job_name)
75
+ if File.exists?( @jenkins_path + 'jobs/' + job_name + '/lastSuccessful/build.xml' )
76
+ File.new( @jenkins_path + 'jobs/' + job_name +
77
+ '/lastSuccessful/build.xml' )
78
+ else
79
+ false
80
+ end
81
+ end
82
+
83
+ def next_build_num(job_name)
84
+ if File.exists?(@jenkins_path + 'jobs/' + job_name + '/nextBuildNumber' )
85
+ nbn_file = File.new( @jenkins_path + 'jobs/' +
86
+ job_name + '/nextBuildNumber' )
87
+ nbn_file.gets.strip.to_i
88
+ else
89
+ 100 # completely arbitrary number greater than 1
90
+ end
91
+ end
92
+
93
+ def last_success_num(build_file)
94
+ if build_file
95
+ doc = Nokogiri::XML build_file
96
+ doc.at_xpath('/build/number').text.to_i
97
+ else
98
+ 0
99
+ end
100
+ end
101
+
102
+ def current_build_num(job_name)
103
+ next_build_num(job_name) - 1
104
+ end
105
+
106
+ def success?(job_name)
107
+ file = last_success_file(job_name)
108
+ if last_success_num(file) == current_build_num(job_name)
109
+ return true
110
+ else
111
+ return false
112
+ end
113
+ end
114
+
115
+ def ensure_dir_for(job_name)
116
+ unless Dir.new(@jenkins_path + 'userContent/jobs').include? job_name
117
+ Dir.mkdir(@jenkins_path + 'userContent/jobs/' + job_name)
118
+ end
119
+ end
120
+
121
+ def link_success_img_for(job_name)
122
+ current_status = @jenkins_path + 'userContent/jobs/' + job_name + '/current_status.png'
123
+ ensure_dir_for job_name
124
+ if File.exists? current_status
125
+ File.delete current_status
126
+ end
127
+ File.symlink( @success_img, current_status )
128
+ end
129
+
130
+ def link_fail_img_for(job_name)
131
+ current_status = @jenkins_path + 'userContent/jobs/' + job_name + '/current_status.png'
132
+ ensure_dir_for job_name
133
+ if File.exists? current_status
134
+ File.delete current_status
135
+ end
136
+ File.symlink( @fail_img, current_status )
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,3 @@
1
+ guard 'jenkins' do
2
+ watch(%r{/var/lib/jenkins/jobs/.*})
3
+ end
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ module JenkinsVersion
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ require 'helper'
2
+
3
+ describe JenkinsStatusBannerGuard do
4
+ describe '#job_names' do
5
+ it 'returns an array of appropriate job dir names' do
6
+
7
+ end
8
+ end
9
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,7 @@
1
+ $:.unshift( File.expand_path( '..', __FILE__ ) )
2
+ $:.unshift( File.expand_path( '../../lib', __FILE__ ) )
3
+ require 'rspec'
4
+ require 'simplecov'
5
+ SimpleCov.start
6
+
7
+ require 'jenkins_status_banner_guard'
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-jenkins
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Justin Stoller
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-18 00:00:00.000000000 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: &19325300 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '2.6'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *19325300
26
+ - !ruby/object:Gem::Dependency
27
+ name: simplecov
28
+ requirement: &19324800 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *19324800
37
+ - !ruby/object:Gem::Dependency
38
+ name: rake
39
+ requirement: &19324420 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *19324420
48
+ - !ruby/object:Gem::Dependency
49
+ name: guard
50
+ requirement: &19323960 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: *19323960
59
+ - !ruby/object:Gem::Dependency
60
+ name: nokogiri
61
+ requirement: &19323540 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ type: :runtime
68
+ prerelease: false
69
+ version_requirements: *19323540
70
+ description: a longer required description of what jenkins_status_banner_guard does
71
+ email: justin.stoller@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rvmrc
78
+ - Changelog.yml
79
+ - Gemfile
80
+ - Rakefile
81
+ - Readme.markdown
82
+ - guard-jenkins.gemspec
83
+ - lib/guard/jenkins.rb
84
+ - lib/guard/jenkins/templates/Guardfile
85
+ - lib/guard/jenkins/version.rb
86
+ - spec/guard/jenkins_status_banner_guard_spec.rb
87
+ - spec/helper.rb
88
+ has_rdoc: true
89
+ homepage: http://justinstoller.github.com/jenkins_status_banner_guard
90
+ licenses: []
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 1.6.2
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: a very short optional summary of jenkins_status_banner_guard
113
+ test_files:
114
+ - spec/guard/jenkins_status_banner_guard_spec.rb
115
+ - spec/helper.rb