Class: PuppetModule

Inherits:
WorkflowAction show all
Includes:
ReleaseManager::Git::Utilities, ReleaseManager::Logger
Defined in:
lib/release_manager/puppet_module.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ReleaseManager::Logger

#color, #log_level, #logger

Methods included from ReleaseManager::Git::Utilities

#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 
   = File.join(mod_path, 'metadata.json')
end

Instance Attribute Details

#metadata_fileObject (readonly)

Returns the value of attribute metadata_file.



9
10
11
# File 'lib/release_manager/puppet_module.rb', line 9

def 
  
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/release_manager/puppet_module.rb', line 9

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/release_manager/puppet_module.rb', line 9

def path
  @path
end

#sourceObject



72
73
74
# File 'lib/release_manager/puppet_module.rb', line 72

def source
  ['source']
end

#upstreamObject (readonly)

Returns the value of attribute upstream.



9
10
11
# File 'lib/release_manager/puppet_module.rb', line 9

def upstream
  @upstream
end

#versionObject



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.

Returns:

  • (ControlRepo)
    • 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_remoteObject



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

Returns:

  • (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_versionObject



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
   ['version'] = pieces.join('.')
end

#bump_minor_versionObject



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
   ['version'] = pieces.join('.')
end

#bump_patch_versionObject



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
   ['version'] = pieces.join('.')
end

#commit_metadataString

Returns the oid of the commit that was created.

Returns:

  • (String)

    the oid of the commit that was created



186
187
188
189
190
# File 'lib/release_manager/puppet_module.rb', line 186

def 
  
  add_file()
  create_commit("[ReleaseManager] - bump version to #{version}")
end

#commit_metadata_sourceString

Returns the oid of the commit that was created.

Returns:

  • (String)

    the oid of the commit that was created



193
194
195
196
197
# File 'lib/release_manager/puppet_module.rb', line 193

def 
  
  add_file()
  create_commit("[ReleaseManager] - change source to #{source}")
end

#create_dev_branchObject

ensures the dev branch has been created and is up to date

Raises:



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?
  #puts "#{git_command} checkout -b #{src_branch} upstream/#{src_branch}"
 `#{git_command} checkout -b #{src_branch} upstream/#{src_branch}` unless branch_exists?(src_branch)
  raise GitError unless $?.success?
  # ensure we have updated our local branch
  #puts "#{git_command} checkout #{src_branch}"
 `#{git_command} checkout #{src_branch}`
  raise GitError unless $?.success?
  #puts "#{git_command} rebase upstream/#{src_branch}"
 `#{git_command} rebase upstream/#{src_branch}`
  raise GitError unless $?.success?
end

#git_commandObject



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

Returns:

  • (Boolean)


60
61
62
# File 'lib/release_manager/puppet_module.rb', line 60

def git_upstream_set?
   source == git_upstream_url
end

#git_upstream_urlObject



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_tagObject



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

#metadataObject



41
42
43
44
45
46
47
# File 'lib/release_manager/puppet_module.rb', line 41

def 
  unless 
    raise ModNotFoundException unless File.exists?() 
     ||= JSON.parse(File.read())
  end
  
end

#mod_nameObject



93
94
95
# File 'lib/release_manager/puppet_module.rb', line 93

def mod_name
  ['name']
end

#namespaced_nameObject



36
37
38
# File 'lib/release_manager/puppet_module.rb', line 36

def namespaced_name 
  ['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_upstreamObject



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

Returns:

  • (Boolean)


141
142
143
# File 'lib/release_manager/puppet_module.rb', line 141

def r10k_module?
  name =~ /r10k_control/i
end

#repoObject



22
23
24
# File 'lib/release_manager/puppet_module.rb', line 22

def repo
  @repo ||= Rugged::Repository.new(path)
end

#src_branchObject

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_moduleObject



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

#tagsObject



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

#to_metadata_fileObject



199
200
201
202
# File 'lib/release_manager/puppet_module.rb', line 199

def 
  logger.info("Writing to file #{metadata_file}")
  File.write(, to_s)
end

#to_sObject



137
138
139
# File 'lib/release_manager/puppet_module.rb', line 137

def to_s
  JSON.pretty_generate()
end