Class: PuppetModule
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#color, #log_level, #logger
#add_file, #add_remote, #author, #author_email, #author_name, #branch_exist?, #checkout_branch, #cherry_pick, #clone, #create_branch, #create_commit, #credentials, #current_branch, #delete_branch, #fetch, #find_or_create_remote, #git_url?, #push_branch, #push_tags, #remote_exists?, #remote_from_name, #remote_from_url, #remote_url_matches?, #remove_file, #transports
Constructor Details
#initialize(mod_path, upstream = nil) ⇒ PuppetModule
Returns a new instance of PuppetModule.
15
16
17
18
19
20
|
# File 'lib/release_manager/puppet_module.rb', line 15
def initialize(mod_path, upstream = nil)
raise ModNotFoundException 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
72
73
74
|
# File 'lib/release_manager/puppet_module.rb', line 72
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
102
103
104
|
# File 'lib/release_manager/puppet_module.rb', line 102
def version
@version
end
|
Class Method Details
.check_requirements(path) ⇒ Object
26
27
28
29
30
|
# File 'lib/release_manager/puppet_module.rb', line 26
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.
205
206
207
208
209
|
# File 'lib/release_manager/puppet_module.rb', line 205
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
49
50
51
52
53
54
|
# File 'lib/release_manager/puppet_module.rb', line 49
def add_upstream_remote
if upstream != source
`#{git_command} remote rm upstream`
end
`#{git_command} remote add upstream #{source}`
end
|
#branch_exists?(name) ⇒ Boolean
145
146
147
148
|
# File 'lib/release_manager/puppet_module.rb', line 145
def branch_exists?(name)
`#{git_command} branch |grep '#{name}$'`
$?.success?
end
|
#bump_major_version ⇒ Object
127
128
129
130
131
132
133
134
135
|
# File 'lib/release_manager/puppet_module.rb', line 127
def bump_major_version
return unless version
pieces = version.split('.')
raise "invalid semver structure #{version}" if pieces.count != 3
pieces[2] = '0'
pieces[1] = '0'
pieces[0] = pieces[0].next
metadata['version'] = pieces.join('.')
end
|
#bump_minor_version ⇒ Object
118
119
120
121
122
123
124
125
|
# File 'lib/release_manager/puppet_module.rb', line 118
def bump_minor_version
return unless version
pieces = version.split('.')
raise "invalid semver structure #{version}" if pieces.count != 3
pieces[2] = '0'
pieces[1] = pieces[1].next
metadata['version'] = pieces.join('.')
end
|
#bump_patch_version ⇒ Object
110
111
112
113
114
115
116
|
# File 'lib/release_manager/puppet_module.rb', line 110
def bump_patch_version
return unless version
pieces = version.split('.')
raise "invalid semver structure #{version}" if pieces.count != 3
pieces[2] = pieces[2].next
metadata['version'] = pieces.join('.')
end
|
Returns the oid of the commit that was created.
186
187
188
189
190
|
# File 'lib/release_manager/puppet_module.rb', line 186
def commit_metadata
to_metadata_file
add_file(metadata_file)
create_commit("[ReleaseManager] - bump version to #{version}")
end
|
Returns the oid of the commit that was created.
193
194
195
196
197
|
# File 'lib/release_manager/puppet_module.rb', line 193
def commit_metadata_source
to_metadata_file
add_file(metadata_file)
create_commit("[ReleaseManager] - change source to #{source}")
end
|
#create_dev_branch ⇒ Object
ensures the dev branch has been created and is up to date
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
# File 'lib/release_manager/puppet_module.rb', line 159
def create_dev_branch
`#{git_command} fetch upstream`
raise GitError unless $?.success?
`#{git_command} checkout -b #{src_branch} upstream/#{src_branch}` unless branch_exists?(src_branch)
raise GitError unless $?.success?
`#{git_command} checkout #{src_branch}`
raise GitError unless $?.success?
`#{git_command} rebase upstream/#{src_branch}`
raise GitError unless $?.success?
end
|
#git_command ⇒ Object
150
151
152
|
# File 'lib/release_manager/puppet_module.rb', line 150
def git_command
@git_command ||= "git --work-tree=#{path} --git-dir=#{path}/.git"
end
|
#git_upstream_set? ⇒ Boolean
60
61
62
|
# File 'lib/release_manager/puppet_module.rb', line 60
def git_upstream_set?
source == git_upstream_url
end
|
#git_upstream_url ⇒ Object
56
57
58
|
# File 'lib/release_manager/puppet_module.rb', line 56
def git_upstream_url
`#{git_command} config --get remote.upstream.url`.chomp
end
|
#latest_tag ⇒ Object
84
85
86
87
88
89
90
|
# File 'lib/release_manager/puppet_module.rb', line 84
def latest_tag
Gem::Version.new('0.0.12') >= Gem::Version.new('0.0.2')
v = tags.sort do |a,b|
Gem::Version.new(a.tr('v', '')) <=> Gem::Version.new(b.tr('v', ''))
end
v.last
end
|
41
42
43
44
45
46
47
|
# File 'lib/release_manager/puppet_module.rb', line 41
def metadata
unless @metadata
raise ModNotFoundException unless File.exists?(metadata_file)
@metadata ||= JSON.parse(File.read(metadata_file))
end
@metadata
end
|
#mod_name ⇒ Object
93
94
95
|
# File 'lib/release_manager/puppet_module.rb', line 93
def mod_name
metadata['name']
end
|
#namespaced_name ⇒ Object
36
37
38
|
# File 'lib/release_manager/puppet_module.rb', line 36
def namespaced_name
metadata['name']
end
|
#pad_version_string(version_string) ⇒ Object
76
77
78
79
80
81
82
|
# File 'lib/release_manager/puppet_module.rb', line 76
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
180
181
182
183
|
# File 'lib/release_manager/puppet_module.rb', line 180
def push_to_upstream
push_branch(source, src_branch)
push_tags(source)
end
|
#r10k_module? ⇒ Boolean
141
142
143
|
# File 'lib/release_manager/puppet_module.rb', line 141
def r10k_module?
name =~ /r10k_control/i
end
|
#repo ⇒ Object
22
23
24
|
# File 'lib/release_manager/puppet_module.rb', line 22
def repo
@repo ||= Rugged::Repository.new(path)
end
|
#src_branch ⇒ Object
if r10k-control this branch will be dev, otherwise master
176
177
178
|
# File 'lib/release_manager/puppet_module.rb', line 176
def src_branch
r10k_module? ? 'dev' : 'master'
end
|
#tag_module ⇒ Object
106
107
108
|
# File 'lib/release_manager/puppet_module.rb', line 106
def tag_module
`git --git-dir=#{path}/.git tag -m 'v#{version}' v#{version}`
end
|
64
65
66
|
# File 'lib/release_manager/puppet_module.rb', line 64
def tags
`#{git_command} tag`.split("\n").map{|v| pad_version_string(v)}
end
|
199
200
201
202
|
# File 'lib/release_manager/puppet_module.rb', line 199
def to_metadata_file
logger.info("Writing to file #{metadata_file}")
File.write(metadata_file, to_s)
end
|
#to_s ⇒ Object
137
138
139
|
# File 'lib/release_manager/puppet_module.rb', line 137
def to_s
JSON.pretty_generate(metadata)
end
|