dynport_tools 0.2.21 → 0.2.22

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/Gemfile CHANGED
@@ -12,7 +12,8 @@ gem "term-ansicolor"
12
12
  gem 'diff-lcs'
13
13
 
14
14
  group :development do
15
- gem "rspec", "~> 2.3.0"
15
+ gem "rake"
16
+ gem "rspec", "2.8.0"
16
17
  gem "bundler", "~> 1.0.0"
17
18
  gem "jeweler", "~> 1.6.4"
18
19
  gem "rcov", ">= 0"
@@ -24,14 +24,14 @@ GEM
24
24
  rbx-require-relative (0.0.5)
25
25
  rcov (0.9.9)
26
26
  redis (2.2.1)
27
- rspec (2.3.0)
28
- rspec-core (~> 2.3.0)
29
- rspec-expectations (~> 2.3.0)
30
- rspec-mocks (~> 2.3.0)
31
- rspec-core (2.3.1)
32
- rspec-expectations (2.3.0)
27
+ rspec (2.8.0)
28
+ rspec-core (~> 2.8.0)
29
+ rspec-expectations (~> 2.8.0)
30
+ rspec-mocks (~> 2.8.0)
31
+ rspec-core (2.8.0)
32
+ rspec-expectations (2.8.0)
33
33
  diff-lcs (~> 1.1.2)
34
- rspec-mocks (2.3.0)
34
+ rspec-mocks (2.8.0)
35
35
  ruby-debug (0.10.4)
36
36
  columnize (>= 0.1)
37
37
  ruby-debug-base (~> 0.10.4.0)
@@ -58,10 +58,11 @@ DEPENDENCIES
58
58
  guard
59
59
  jeweler (~> 1.6.4)
60
60
  nokogiri
61
+ rake
61
62
  rb-fsevent
62
63
  rcov
63
64
  redis
64
- rspec (~> 2.3.0)
65
+ rspec (= 2.8.0)
65
66
  ruby-debug
66
67
  spork
67
68
  term-ansicolor
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.21
1
+ 0.2.22
@@ -5,14 +5,14 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "dynport_tools"
8
- s.version = "0.2.21"
8
+ s.version = "0.2.22"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tobias Schwab"]
12
- s.date = "2012-01-31"
12
+ s.date = "2012-02-28"
13
13
  s.description = "Collection of various tools"
14
14
  s.email = "tobias.schwab@dynport.de"
15
- s.executables = ["xmldiff", "redis_dumper"]
15
+ s.executables = ["redis_dumper", "xmldiff"]
16
16
  s.extra_rdoc_files = [
17
17
  "LICENSE.txt",
18
18
  "README.rdoc"
@@ -42,6 +42,8 @@ Gem::Specification.new do |s|
42
42
  "lib/dynport_tools/features.rb",
43
43
  "lib/dynport_tools/have_attributes.rb",
44
44
  "lib/dynport_tools/jenkins.rb",
45
+ "lib/dynport_tools/jenkins/project.rb",
46
+ "lib/dynport_tools/jenkins/remote_project.rb",
45
47
  "lib/dynport_tools/job_dsl.rb",
46
48
  "lib/dynport_tools/log_tracer.rb",
47
49
  "lib/dynport_tools/redis_dumper.rb",
@@ -56,6 +58,8 @@ Gem::Specification.new do |s|
56
58
  "spec/dynport_tools/eta_spec.rb",
57
59
  "spec/dynport_tools/features_spec.rb",
58
60
  "spec/dynport_tools/have_attributes_spec.rb",
61
+ "spec/dynport_tools/jenkins/project_spec.rb",
62
+ "spec/dynport_tools/jenkins/remote_project_spec.rb",
59
63
  "spec/dynport_tools/jenkins_spec.rb",
60
64
  "spec/dynport_tools/job_dsl_spec.rb",
61
65
  "spec/dynport_tools/log_tracer_spec.rb",
@@ -74,7 +78,7 @@ Gem::Specification.new do |s|
74
78
  s.homepage = "http://github.com/tobstarr/dynport_tools"
75
79
  s.licenses = ["MIT"]
76
80
  s.require_paths = ["lib"]
77
- s.rubygems_version = "1.8.11"
81
+ s.rubygems_version = "1.8.17"
78
82
  s.summary = "Collection of various tools"
79
83
 
80
84
  if s.respond_to? :specification_version then
@@ -86,7 +90,8 @@ Gem::Specification.new do |s|
86
90
  s.add_runtime_dependency(%q<typhoeus>, [">= 0"])
87
91
  s.add_runtime_dependency(%q<term-ansicolor>, [">= 0"])
88
92
  s.add_runtime_dependency(%q<diff-lcs>, [">= 0"])
89
- s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
93
+ s.add_development_dependency(%q<rake>, [">= 0"])
94
+ s.add_development_dependency(%q<rspec>, ["= 2.8.0"])
90
95
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
91
96
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
92
97
  s.add_development_dependency(%q<rcov>, [">= 0"])
@@ -105,7 +110,8 @@ Gem::Specification.new do |s|
105
110
  s.add_dependency(%q<typhoeus>, [">= 0"])
106
111
  s.add_dependency(%q<term-ansicolor>, [">= 0"])
107
112
  s.add_dependency(%q<diff-lcs>, [">= 0"])
108
- s.add_dependency(%q<rspec>, ["~> 2.3.0"])
113
+ s.add_dependency(%q<rake>, [">= 0"])
114
+ s.add_dependency(%q<rspec>, ["= 2.8.0"])
109
115
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
110
116
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
111
117
  s.add_dependency(%q<rcov>, [">= 0"])
@@ -125,7 +131,8 @@ Gem::Specification.new do |s|
125
131
  s.add_dependency(%q<typhoeus>, [">= 0"])
126
132
  s.add_dependency(%q<term-ansicolor>, [">= 0"])
127
133
  s.add_dependency(%q<diff-lcs>, [">= 0"])
128
- s.add_dependency(%q<rspec>, ["~> 2.3.0"])
134
+ s.add_dependency(%q<rake>, [">= 0"])
135
+ s.add_dependency(%q<rspec>, ["= 2.8.0"])
129
136
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
130
137
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
131
138
  s.add_dependency(%q<rcov>, [">= 0"])
@@ -50,9 +50,13 @@ class DynportTools::EmbeddedRedis
50
50
  connection
51
51
  end
52
52
 
53
+ def self.system(cmd)
54
+ Kernel.send(:system, cmd)
55
+ end
56
+
53
57
  def do_start!
54
58
  FileUtils.mkdir_p(base_path)
55
- system(%(echo "#{config}" | redis-server -))
59
+ self.class.system(%(echo "#{config}" | redis-server -))
56
60
  sleep 0.1
57
61
  self.started = true
58
62
  log "started redis with pid #{pid}"
@@ -88,7 +92,7 @@ class DynportTools::EmbeddedRedis
88
92
  log "killing redis"
89
93
  if !killed? && pid
90
94
  log "killing #{pid}"
91
- system(%(kill #{pid}))
95
+ self.class.system(%(kill #{pid}))
92
96
  FileUtils.rm_f(socket_path)
93
97
  FileUtils.rm_f(dbfile_path)
94
98
  self.killed = true
@@ -38,10 +38,14 @@ class DynportTools::Jenkins
38
38
  end
39
39
 
40
40
  def post_request(path, options = nil)
41
- @cache = {}
41
+ clear_cache
42
42
  Typhoeus::Request.post(*["#{url}/#{path}", options].compact)
43
43
  end
44
44
 
45
+ def clear_cache
46
+ cache.clear
47
+ end
48
+
45
49
  def cache
46
50
  @cache ||= {}
47
51
  end
@@ -74,221 +78,47 @@ class DynportTools::Jenkins
74
78
  cache[:projects_details] = jobs
75
79
  end
76
80
 
81
+ CONFIGURED_PROJECTS_HASH = :configured_projects_hash
82
+
83
+ def configured_projects_hash=(new_hash)
84
+ @configured_projects_hash = new_hash
85
+ end
86
+
87
+ def configured_projects_hash
88
+ @configured_projects_hash ||= {}
89
+ end
90
+
91
+ def configured_projects
92
+ configured_projects_hash.values
93
+ end
94
+
77
95
  def remote_projects
78
96
  project_details.inject({}) do |hash, (url, project_hash)|
79
- hash.merge!(project_hash[:name] => RemoteProject.new(:url => project_hash[:url], :name => project_hash[:name], :xml => project_hash[:body]))
97
+ hash[project_hash[:name]] = RemoteProject.from_details_hash(project_hash)
98
+ hash
80
99
  end
81
100
  end
82
101
 
83
- class RemoteProject
84
- attr_accessor :url, :name, :xml
85
-
86
- def initialize(options = {})
87
- options.each do |key, value|
88
- self.send(:"#{key}=", value) if self.respond_to?(:"#{key}=")
89
- end
90
- end
91
-
92
- def doc
93
- @doc ||= Nokogiri::XML(xml) if xml
94
- end
95
-
96
- def md5
97
- Digest::MD5.hexdigest(xml) if xml
98
- end
99
-
100
- def days_to_keep
101
- logrotate_value_when_set("daysToKeep")
102
- end
103
-
104
- def num_to_keep
105
- logrotate_value_when_set("numToKeep")
106
- end
107
-
108
- def logrotate_value_when_set(key)
109
- if node = doc.at("/project/logRotator/#{key}")
110
- node.inner_text.to_i if node.inner_text.to_i != -1
111
- end
112
- end
113
-
114
- def commands
115
- doc.xpath("/project/builders/hudson.tasks.Shell/command").map(&:inner_text)
116
- end
117
-
118
- def crontab_patterns
119
- doc.xpath("/project/triggers/hudson.triggers.TimerTrigger/spec").map(&:inner_text)
120
- end
121
-
122
- def disabled?
123
- doc.at("/project/disabled/text()").to_s == "true"
124
- end
125
-
126
- def child_projects
127
- if projects = doc.xpath("/project/publishers/hudson.tasks.BuildTrigger/childProjects").first
128
- projects.inner_text.split(/\s*,\s*/)
129
- else
130
- []
131
- end
132
- end
133
-
134
- def email_addresses
135
- doc.xpath("/project/publishers/hudson.tasks.Mailer/recipients").map { |rec| rec.inner_text.split(",") }.flatten
136
- end
137
-
138
- def node
139
- doc.xpath("/project/assignedNode").map { |n| n.inner_text }.first
140
- end
141
-
142
- def locks
143
- doc.xpath("/project/buildWrappers/hudson.plugins.locksandlatches.LockWrapper/locks/hudson.plugins.locksandlatches.LockWrapper_-LockWaitConfig/name").map(&:inner_text)
144
- end
102
+ def exists_remotely?(project)
103
+ remote_projects.keys.include?(project.name)
145
104
  end
146
105
 
147
- class Project
148
- attr_accessor :name, :commands, :crontab_pattern, :days_to_keep, :num_to_keep, :node, :child_projects, :locks, :disabled, :description,
149
- :email_addresses, :git_repository
150
- DEFAULT_SCM = "hudson.scm.NullSCM"
151
- GIT_SCM = "hudson.plugins.git.GitSCM"
152
-
153
- def initialize(name = nil)
154
- self.name = name
155
- self.commands = []
156
- self.child_projects = []
157
- self.email_addresses = []
158
- self.locks = []
159
- end
160
-
161
- def md5
162
- Digest::MD5.hexdigest(to_xml)
163
- end
164
-
165
- def log_rotate_xml(node)
166
- node.logRotator do
167
- node.daysToKeep days_to_keep || -1
168
- node.numToKeep num_to_keep || -1
169
- node.artifactDaysToKeep -1
170
- node.artifactNumToKeep -1
171
- end
172
- end
173
-
174
- def git_repository_xml(xml)
175
- xml.send("org.spearce.jgit.transport.RemoteConfig") do
176
- xml.string "origin"
177
- xml.int 5
178
- xml.string "fetch"
179
- xml.string "+refs/heads/*:refs/remotes/origin/*"
180
- xml.string "receivepack"
181
- xml.string "git-upload-pack"
182
- xml.string "uploadpack"
183
- xml.string "git-upload-pack"
184
- xml.string "url"
185
- xml.string git_repository
186
- xml.string "tagopt"
187
- xml.string
188
- end
189
- end
190
-
191
- def git_options_xml(xml)
192
- xml.mergeOptions
193
- xml.recursiveSubmodules false
194
- xml.doGenerateSubmoduleConfigurations false
195
- xml.authorOrCommitter false
196
- xml.clean false
197
- xml.wipeOutWorkspace false
198
- xml.pruneBranches false
199
- xml.buildChooser(:class => "hudson.plugins.git.util.DefaultBuildChooser")
200
- xml.gitTool "Default"
201
- xml.submoduleCfg(:class => "list")
202
- xml.relativeTargetDir
203
- xml.excludedRegion
204
- xml.excludedUsers
205
- xml.skipTag false
206
- end
207
-
208
- def git_xml(xml)
209
- xml.scm(:class => GIT_SCM) do
210
- xml.config_version 1
211
- xml.remoteRepositories do
212
- git_repository_xml(xml)
213
- end
214
- xml.branches do
215
- xml.send("hudson.plugins.git.BranchSpec") do
216
- xml.name "master"
217
- end
218
- end
219
- git_options_xml(xml)
220
- end
221
- end
222
-
223
- def to_xml
224
- Nokogiri::XML::Builder.new(:encoding => "UTF-8") do |xml|
225
- xml.project do
226
- xml.actions
227
- xml.description *[description].compact
228
- log_rotate_xml(xml) if days_to_keep || num_to_keep
229
- xml.keepDependencies false
230
- xml.properties
231
- if git_repository
232
- git_xml(xml)
233
- else
234
- xml.scm(:class => DEFAULT_SCM)
235
- end
236
- if node
237
- xml.assignedNode node
238
- xml.canRoam false
239
- else
240
- xml.canRoam true
241
- end
242
- xml.disabled disabled ? true : false
243
- xml.blockBuildWhenDownstreamBuilding false
244
- xml.blockBuildWhenUpstreamBuilding false
245
- xml.triggers(:class => "vector") do
246
- if crontab_pattern
247
- xml.send("hudson.triggers.TimerTrigger") do
248
- xml.spec crontab_pattern
249
- end
250
- end
251
- end
252
- xml.concurrentBuild false
253
- xml.builders do
254
- commands.each do |command|
255
- xml.send("hudson.tasks.Shell") do
256
- xml.command command
257
- end
258
- end
259
- end
260
- xml.publishers do
261
- if child_projects.any?
262
- xml.send("hudson.tasks.BuildTrigger") do
263
- xml.childProjects child_projects.map { |c| c.name }.join(",")
264
- xml.threshold do
265
- xml.name "SUCCESS"
266
- xml.ordinal "0"
267
- xml.color "BLUE"
268
- end
269
- end
270
- end
271
- if email_addresses.any?
272
- xml.send("hudson.tasks.Mailer") do
273
- xml.recipients email_addresses.join(",")
274
- xml.dontNotifyEveryUnstableBuild true
275
- xml.sendToIndividuals false
276
- end
277
- end
278
- end
279
- xml.buildWrappers do
280
- if locks.any?
281
- xml.send("hudson.plugins.locksandlatches.LockWrapper") do
282
- xml.locks do
283
- locks.each do |lock|
284
- xml.send("hudson.plugins.locksandlatches.LockWrapper_-LockWaitConfig") { xml.name lock }
285
- end
286
- end
287
- end
288
- end
289
- end
290
- end
291
- end.to_xml
292
- end
106
+ def projects_to_delete
107
+ configured_projects.select { |project| project.deleted? && exists_remotely?(project) }
108
+ end
109
+
110
+ def projects_to_create
111
+ configured_projects.select { |project| !project.deleted? && !exists_remotely?(project) }
112
+ end
113
+
114
+ def projects_to_update
115
+ configured_projects.select { | project| exists_remotely?(project) && !project.deleted? && (project.md5 != remote_projects[project.name].md5) }
116
+ end
117
+
118
+ def not_configured_projects
119
+ remote_projects.values.select { |project| !configured_projects_hash.keys.include?(project.name) }
293
120
  end
294
- end
121
+ end
122
+
123
+ require "dynport_tools/jenkins/project"
124
+ require "dynport_tools/jenkins/remote_project"
@@ -0,0 +1,151 @@
1
+ class DynportTools::Jenkins::Project
2
+ attr_accessor :name, :commands, :crontab_pattern, :days_to_keep, :num_to_keep, :node, :child_projects, :locks, :disabled
3
+ attr_accessor :description, :email_addresses, :git_repository, :delete
4
+ DEFAULT_SCM = "hudson.scm.NullSCM"
5
+ GIT_SCM = "hudson.plugins.git.GitSCM"
6
+
7
+ def initialize(name = nil)
8
+ self.name = name
9
+ self.commands = []
10
+ self.child_projects = []
11
+ self.email_addresses = []
12
+ self.locks = []
13
+ end
14
+
15
+ def deleted?
16
+ !!@delete
17
+ end
18
+
19
+ def md5
20
+ Digest::MD5.hexdigest(to_xml)
21
+ end
22
+
23
+ def log_rotate_xml(node)
24
+ node.logRotator do
25
+ node.daysToKeep days_to_keep || -1
26
+ node.numToKeep num_to_keep || -1
27
+ node.artifactDaysToKeep -1
28
+ node.artifactNumToKeep -1
29
+ end
30
+ end
31
+
32
+ def git_repository_xml(xml)
33
+ xml.send("org.spearce.jgit.transport.RemoteConfig") do
34
+ xml.string "origin"
35
+ xml.int 5
36
+ xml.string "fetch"
37
+ xml.string "+refs/heads/*:refs/remotes/origin/*"
38
+ xml.string "receivepack"
39
+ xml.string "git-upload-pack"
40
+ xml.string "uploadpack"
41
+ xml.string "git-upload-pack"
42
+ xml.string "url"
43
+ xml.string git_repository
44
+ xml.string "tagopt"
45
+ xml.string
46
+ end
47
+ end
48
+
49
+ def git_options_xml(xml)
50
+ xml.mergeOptions
51
+ xml.recursiveSubmodules false
52
+ xml.doGenerateSubmoduleConfigurations false
53
+ xml.authorOrCommitter false
54
+ xml.clean false
55
+ xml.wipeOutWorkspace false
56
+ xml.pruneBranches false
57
+ xml.buildChooser(:class => "hudson.plugins.git.util.DefaultBuildChooser")
58
+ xml.gitTool "Default"
59
+ xml.submoduleCfg(:class => "list")
60
+ xml.relativeTargetDir
61
+ xml.excludedRegion
62
+ xml.excludedUsers
63
+ xml.skipTag false
64
+ end
65
+
66
+ def git_xml(xml)
67
+ xml.scm(:class => GIT_SCM) do
68
+ xml.config_version 1
69
+ xml.remoteRepositories do
70
+ git_repository_xml(xml)
71
+ end
72
+ xml.branches do
73
+ xml.send("hudson.plugins.git.BranchSpec") do
74
+ xml.name "master"
75
+ end
76
+ end
77
+ git_options_xml(xml)
78
+ end
79
+ end
80
+
81
+ def to_xml
82
+ Nokogiri::XML::Builder.new(:encoding => "UTF-8") do |xml|
83
+ xml.project do
84
+ xml.actions
85
+ xml.description *[description].compact
86
+ log_rotate_xml(xml) if days_to_keep || num_to_keep
87
+ xml.keepDependencies false
88
+ xml.properties
89
+ if git_repository
90
+ git_xml(xml)
91
+ else
92
+ xml.scm(:class => DEFAULT_SCM)
93
+ end
94
+ if node
95
+ xml.assignedNode node
96
+ xml.canRoam false
97
+ else
98
+ xml.canRoam true
99
+ end
100
+ xml.disabled disabled ? true : false
101
+ xml.blockBuildWhenDownstreamBuilding false
102
+ xml.blockBuildWhenUpstreamBuilding false
103
+ xml.triggers(:class => "vector") do
104
+ if crontab_pattern
105
+ xml.send("hudson.triggers.TimerTrigger") do
106
+ xml.spec crontab_pattern
107
+ end
108
+ end
109
+ end
110
+ xml.concurrentBuild false
111
+ xml.builders do
112
+ commands.each do |command|
113
+ xml.send("hudson.tasks.Shell") do
114
+ xml.command command
115
+ end
116
+ end
117
+ end
118
+ xml.publishers do
119
+ if child_projects.any?
120
+ xml.send("hudson.tasks.BuildTrigger") do
121
+ xml.childProjects child_projects.map { |c| c.name }.join(",")
122
+ xml.threshold do
123
+ xml.name "SUCCESS"
124
+ xml.ordinal "0"
125
+ xml.color "BLUE"
126
+ end
127
+ end
128
+ end
129
+ if email_addresses.any?
130
+ xml.send("hudson.tasks.Mailer") do
131
+ xml.recipients email_addresses.join(",")
132
+ xml.dontNotifyEveryUnstableBuild true
133
+ xml.sendToIndividuals false
134
+ end
135
+ end
136
+ end
137
+ xml.buildWrappers do
138
+ if locks.any?
139
+ xml.send("hudson.plugins.locksandlatches.LockWrapper") do
140
+ xml.locks do
141
+ locks.each do |lock|
142
+ xml.send("hudson.plugins.locksandlatches.LockWrapper_-LockWaitConfig") { xml.name lock }
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end.to_xml
150
+ end
151
+ end