Class: PuppetModule
Instance Attribute Summary collapse
#vcs
Class Method Summary
collapse
Instance Method Summary
collapse
adapter_instance, adapter_types, default_instance
#color, #log_level, #logger
#add_all, #add_file, #add_remote, #apply_diff, #apply_patch, #author, #author_email, #author_name, #branch_exist?, #changed_files, #checkout_branch, #cherry_pick, #cli_create_commit, #clone, #create_branch, #create_commit, #create_diff, #create_diff_obj, #create_local_tag, #credentials, #current_branch, #current_branch?, #delete_branch, #fetch, #find_or_create_remote, #find_ref, #get_content, #git_command, #git_url?, #push_branch, #push_tags, #rebase_branch, #remote_exists?, #remote_from_name, #remote_from_url, #remote_url_matches?, #remove_file, #transports, #up2date?
Constructor Details
#initialize(mod_path, upstream = nil) ⇒ PuppetModule
Returns a new instance of PuppetModule.
16
17
18
19
20
21
|
# File 'lib/release_manager/puppet_module.rb', line 16
def initialize(mod_path, upstream = nil)
raise ModNotFoundException.new("#{mod_path} is not a valid puppet module path") if mod_path.nil?
@path = mod_path
@upstream = upstream
@metadata_file = File.join(mod_path, 'metadata.json')
end
|
Instance Attribute Details
Returns the value of attribute metadata_file.
9
10
11
|
# File 'lib/release_manager/puppet_module.rb', line 9
def metadata_file
@metadata_file
end
|
#name ⇒ Object
Returns the value of attribute name.
9
10
11
|
# File 'lib/release_manager/puppet_module.rb', line 9
def name
@name
end
|
#path ⇒ Object
Returns the value of attribute path.
9
10
11
|
# File 'lib/release_manager/puppet_module.rb', line 9
def path
@path
end
|
#source ⇒ Object
75
76
77
|
# File 'lib/release_manager/puppet_module.rb', line 75
def source
metadata['source']
end
|
#upstream ⇒ Object
Returns the value of attribute upstream.
9
10
11
|
# File 'lib/release_manager/puppet_module.rb', line 9
def upstream
@upstream
end
|
#version ⇒ Object
110
111
112
|
# File 'lib/release_manager/puppet_module.rb', line 110
def version
@version
end
|
Class Method Details
.check_requirements(path) ⇒ Object
27
28
29
30
31
|
# File 'lib/release_manager/puppet_module.rb', line 27
def self.check_requirements(path)
pm = new(path)
raise InvalidMetadataSource if pm.source !~ /\Agit\@/
raise UpstreamSourceMatch unless pm.git_upstream_set?
end
|
.create(path, url, branch = 'master') ⇒ ControlRepo
Returns - creates a new control repo object and clones the url unless already cloned.
247
248
249
250
251
|
# File 'lib/release_manager/puppet_module.rb', line 247
def self.create(path, url, branch = 'master')
c = PuppetModule.new(path, url)
c.clone(url, path)
c
end
|
Instance Method Details
#add_upstream_remote ⇒ Object
55
56
57
|
# File 'lib/release_manager/puppet_module.rb', line 55
def add_upstream_remote
add_remote(source,'upstream',true )
end
|
#already_latest? ⇒ Boolean
50
51
52
53
|
# File 'lib/release_manager/puppet_module.rb', line 50
def already_latest?
return false unless latest_tag
up2date?(latest_tag, src_branch)
end
|
#bump_major_version ⇒ Object
Updates the version in memory
160
161
162
|
# File 'lib/release_manager/puppet_module.rb', line 160
def bump_major_version
metadata['version'] = next_version('major')
end
|
#bump_minor_version ⇒ Object
Updates the version in memory
155
156
157
|
# File 'lib/release_manager/puppet_module.rb', line 155
def bump_minor_version
metadata['version'] = next_version('minor')
end
|
#bump_patch_version ⇒ Object
Updates the version in memory
150
151
152
|
# File 'lib/release_manager/puppet_module.rb', line 150
def bump_patch_version
metadata['version'] = next_version('patch')
end
|
Returns the oid of the commit that was created.
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
# File 'lib/release_manager/puppet_module.rb', line 198
def commit_metadata(remote = false)
message = "[ReleaseManager] - bump version to #{version}"
if remote
actions = [{
action: 'update',
file_path: metadata_file.split(repo.workdir).last,
content: JSON.pretty_generate(metadata)
}]
obj = vcs_create_commit(source, src_branch, message, actions)
obj.id if obj
else
to_metadata_file
add_file(metadata_file)
create_commit(message)
end
end
|
Returns the oid of the commit that was created.
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
# File 'lib/release_manager/puppet_module.rb', line 216
def commit_metadata_source(remote = false)
message = "[ReleaseManager] - change source to #{source}"
if remote
actions = [{
action: 'update',
file_path: metadata_file.split(repo.workdir).last,
content: JSON.pretty_generate(metadata)
}]
obj = vcs_create_commit(source, src_branch, message, actions)
obj.id if obj
else
to_metadata_file
add_file(metadata_file)
create_commit(message)
end
end
|
#create_dev_branch ⇒ Object
ensures the dev branch has been created and is up to date
177
178
179
180
181
182
183
|
# File 'lib/release_manager/puppet_module.rb', line 177
def create_dev_branch
fetch('upstream')
create_branch(src_branch, "upstream/#{src_branch}")
checkout_branch(src_branch)
rebase_branch(src_branch, src_branch, 'upstream')
end
|
#git_upstream_set? ⇒ Boolean
63
64
65
|
# File 'lib/release_manager/puppet_module.rb', line 63
def git_upstream_set?
source == git_upstream_url
end
|
#git_upstream_url ⇒ Object
59
60
61
|
# File 'lib/release_manager/puppet_module.rb', line 59
def git_upstream_url
repo.remotes['upstream'].url if remote_exists?('upstream')
end
|
#latest_tag ⇒ String
Returns - the latest tag in a series of versioned tags.
93
94
95
96
97
98
|
# File 'lib/release_manager/puppet_module.rb', line 93
def latest_tag
v = version_tags.sort do |a,b|
Gem::Version.new(a.tr('v', '')) <=> Gem::Version.new(b.tr('v', ''))
end
v.last
end
|
42
43
44
45
46
47
48
|
# File 'lib/release_manager/puppet_module.rb', line 42
def metadata
unless @metadata
raise ModNotFoundException.new("#{path} does not contain a metadata file") unless File.exists?(metadata_file)
@metadata ||= JSON.parse(File.read(metadata_file))
end
@metadata
end
|
#mod_name ⇒ Object
101
102
103
|
# File 'lib/release_manager/puppet_module.rb', line 101
def mod_name
metadata['name']
end
|
#namespaced_name ⇒ Object
37
38
39
|
# File 'lib/release_manager/puppet_module.rb', line 37
def namespaced_name
metadata['name']
end
|
#next_version(level = 'patch') ⇒ Object
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/release_manager/puppet_module.rb', line 115
def next_version(level = 'patch')
return unless version
pieces = version.split('.')
raise "invalid semver structure #{version}" if pieces.count != 3
case level
when 'major'
pieces[2] = '0'
pieces[1] = '0'
pieces[0] = pieces[0].next
when 'minor'
pieces[2] = '0'
pieces[1] = pieces[1].next
when 'patch'
pieces[2] = pieces[2].next
else
raise "expected semver release level major, minor or patch"
end
pieces.join('.')
end
|
#pad_version_string(version_string) ⇒ Object
79
80
81
82
83
84
85
|
# File 'lib/release_manager/puppet_module.rb', line 79
def pad_version_string(version_string)
parts = version_string.split('.').reject {|x| x == '*'}
while parts.length < 3
parts << '0'
end
parts.join '.'
end
|
#push_to_upstream ⇒ Object
191
192
193
194
|
# File 'lib/release_manager/puppet_module.rb', line 191
def push_to_upstream
push_branch(source, src_branch)
push_tags(source)
end
|
#r10k_module? ⇒ Boolean
168
169
170
|
# File 'lib/release_manager/puppet_module.rb', line 168
def r10k_module?
mod_name =~ /r10k[-_]?control/i
end
|
#repo ⇒ Object
23
24
25
|
# File 'lib/release_manager/puppet_module.rb', line 23
def repo
@repo ||= Rugged::Repository.new(path)
end
|
#src_branch ⇒ Object
if r10k-control this branch will be dev, otherwise master
187
188
189
|
# File 'lib/release_manager/puppet_module.rb', line 187
def src_branch
r10k_module? ? 'dev' : 'master'
end
|
#tag_exists?(tag, remote = false) ⇒ Boolean
233
234
235
236
237
238
239
|
# File 'lib/release_manager/puppet_module.rb', line 233
def tag_exists?(tag, remote = false)
if remote
remote_tag_exists?(source, tag)
else
latest_tag == tag
end
end
|
#tag_module(remote = false, id = nil) ⇒ Object
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/release_manager/puppet_module.rb', line 138
def tag_module(remote = false, id = nil)
id ||= repo.head.target_id
if remote
create_tag(source, "v#{version}", id, "v#{version}", nil)
else
create_local_tag("v#{version}", id)
end
end
|
67
68
69
|
# File 'lib/release_manager/puppet_module.rb', line 67
def tags
repo.tags.map{|v| pad_version_string(v.name)}
end
|
241
242
243
244
|
# File 'lib/release_manager/puppet_module.rb', line 241
def to_metadata_file
logger.info("Writing to file #{metadata_file}")
File.write(metadata_file, to_s)
end
|
#to_s ⇒ Object
164
165
166
|
# File 'lib/release_manager/puppet_module.rb', line 164
def to_s
JSON.pretty_generate(metadata)
end
|
Returns - returns a array of version strings with the v in the name.
88
89
90
|
# File 'lib/release_manager/puppet_module.rb', line 88
def version_tags
tags.find_all {|tag| tag =~ /\Av\d/ }
end
|