Class: PuppetModule

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

Instance Attribute Summary collapse

Attributes included from ReleaseManager::VCSManager

#vcs

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ReleaseManager::VCSManager

adapter_instance, adapter_types, default_instance

Methods included from ReleaseManager::Logger

#color, #log_level, #logger

Methods included from ReleaseManager::Git::Utilities

#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?, #update_cli_index

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 
   = 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



75
76
77
# File 'lib/release_manager/puppet_module.rb', line 75

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



104
105
106
# File 'lib/release_manager/puppet_module.rb', line 104

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.

Returns:

  • (ControlRepo)
    • creates a new control repo object and clones the url unless already cloned



234
235
236
237
238
# File 'lib/release_manager/puppet_module.rb', line 234

def self.create(path, url, branch = 'master')
  c = PuppetModule.new(path, url)
  c.clone(url, path)
  c
end

Instance Method Details

#add_upstream_remoteObject



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

Returns:

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

Updates the version in memory



141
142
143
144
145
146
147
148
149
# File 'lib/release_manager/puppet_module.rb', line 141

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

Updates the version in memory



131
132
133
134
135
136
137
138
# File 'lib/release_manager/puppet_module.rb', line 131

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

Updates the version in memory



122
123
124
125
126
127
128
# File 'lib/release_manager/puppet_module.rb', line 122

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_metadata(remote = false) ⇒ String

Returns the oid of the commit that was created.

Parameters:

  • remote (Boolean) (defaults to: false)

    if true creates the commit on the remote repo

Returns:

  • (String)

    the oid of the commit that was created



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/release_manager/puppet_module.rb', line 185

def (remote = false)
  message = "[ReleaseManager] - bump version to #{version}"
  if remote
    actions = [{
      action: 'update',
      file_path: .split(repo.workdir).last,
      content: JSON.pretty_generate()
    }]
    obj = vcs_create_commit(source, src_branch, message, actions)
    obj.id if obj
  else
    
    add_file()
    create_commit(message)
  end
end

#commit_metadata_source(remote = false) ⇒ String

Returns the oid of the commit that was created.

Returns:

  • (String)

    the oid of the commit that was created



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/release_manager/puppet_module.rb', line 203

def (remote = false)
  message = "[ReleaseManager] - change source to #{source}"
  if remote
    actions = [{
      action: 'update',
      file_path: .split(repo.workdir).last,
      content: JSON.pretty_generate()
    }]
    obj = vcs_create_commit(source, src_branch, message, actions)
    obj.id if obj
  else
    
    add_file()
    create_commit(message)
  end
end

#create_dev_branchObject

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



164
165
166
167
168
169
170
# File 'lib/release_manager/puppet_module.rb', line 164

def create_dev_branch
  fetch('upstream')
  create_branch(src_branch, "upstream/#{src_branch}")
  # ensure we have updated our local branch
  checkout_branch(src_branch)
  rebase_branch(src_branch, src_branch, 'upstream')
end

#git_upstream_set?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/release_manager/puppet_module.rb', line 63

def git_upstream_set?
   source == git_upstream_url
end

#git_upstream_urlObject



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_tagObject



87
88
89
90
91
92
# File 'lib/release_manager/puppet_module.rb', line 87

def latest_tag
  v = tags.sort do |a,b|
   Gem::Version.new(a.tr('v', '')) <=> Gem::Version.new(b.tr('v', ''))
  end
  v.last
end

#metadataObject



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

def 
  unless 
    raise ModNotFoundException.new("#{path} does not contain a metadata file") unless File.exists?()
     ||= JSON.parse(File.read())
  end
  
end

#mod_nameObject



95
96
97
# File 'lib/release_manager/puppet_module.rb', line 95

def mod_name
  ['name']
end

#namespaced_nameObject



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

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



178
179
180
181
# File 'lib/release_manager/puppet_module.rb', line 178

def push_to_upstream
  push_branch(source, src_branch)
  push_tags(source)
end

#r10k_module?Boolean

Returns:

  • (Boolean)


155
156
157
# File 'lib/release_manager/puppet_module.rb', line 155

def r10k_module?
  mod_name =~ /r10k[-_]?control/i
end

#repoObject



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

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

#src_branchObject

if r10k-control this branch will be dev, otherwise master



174
175
176
# File 'lib/release_manager/puppet_module.rb', line 174

def src_branch
  r10k_module? ? 'dev' : 'master'
end

#tag_exists?(tag, remote = false) ⇒ Boolean

Returns:

  • (Boolean)


220
221
222
223
224
225
226
# File 'lib/release_manager/puppet_module.rb', line 220

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

Parameters:

  • remote (Boolean) (defaults to: false)
    • create the tag remotely using the remote VCS

  • id (String) (defaults to: nil)
    • the commit id to tag to



110
111
112
113
114
115
116
117
118
119
# File 'lib/release_manager/puppet_module.rb', line 110

def tag_module(remote = false, id = nil)
  id ||= repo.head.target_id
  if remote
    # TODO add release_notes as the last argument, currently nil
    # where we get the latest from the changelog
    create_tag(source, "v#{version}", id, "v#{version}", nil)
  else
    create_local_tag("v#{version}", id)
  end
end

#tagsObject



67
68
69
# File 'lib/release_manager/puppet_module.rb', line 67

def tags
  repo.tags.map{|v| pad_version_string(v.name)}
end

#to_metadata_fileObject



228
229
230
231
# File 'lib/release_manager/puppet_module.rb', line 228

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

#to_sObject



151
152
153
# File 'lib/release_manager/puppet_module.rb', line 151

def to_s
  JSON.pretty_generate()
end