class PuppetModule

Attributes

metadata_file[R]
name[R]
options[R]
path[R]
source[W]
upstream[R]
version[RW]

Public Class Methods

check_requirements(path) click to toggle source
# File lib/release_manager/puppet_module.rb, line 32
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') click to toggle source

@return [ControlRepo] - creates a new control repo object and clones the url unless already cloned @param url [String] - the upstream url @param branch [String] - the source branch

# File lib/release_manager/puppet_module.rb, line 271
def self.create(path, url, branch = 'master')
  options = {upstream: url, src_branch: branch}
  c = PuppetModule.new(path, options)
  c.clone(url, path)
  c
end
new(mod_path, options = {}) click to toggle source

@param mod_path [String] - the path to the module @param options [Hash] - a hash of options @option upstream [String] - the upstream url @option src_branch [String] - the source of the branch

# File lib/release_manager/puppet_module.rb, line 20
def initialize(mod_path, options = {})
  raise ModNotFoundException.new("#{mod_path} is not a valid puppet module path") if mod_path.nil?
  @path = mod_path
  @options = options
  @upstream = options[:upstream]
  @metadata_file = File.join(mod_path, 'metadata.json')
end

Public Instance Methods

add_upstream_remote() click to toggle source
# File lib/release_manager/puppet_module.rb, line 60
def add_upstream_remote
  add_remote(source,'upstream',true )
end
already_latest?() click to toggle source
# File lib/release_manager/puppet_module.rb, line 55
def already_latest?
  return false unless latest_tag
  up2date?(latest_tag, src_branch)
end
bump_major_version() click to toggle source

Updates the version in memory

# File lib/release_manager/puppet_module.rb, line 166
def bump_major_version
   metadata['version'] = next_version('major')
end
bump_minor_version() click to toggle source

Updates the version in memory

# File lib/release_manager/puppet_module.rb, line 161
def bump_minor_version
   metadata['version'] = next_version('minor')
end
bump_patch_version() click to toggle source

Updates the version in memory

# File lib/release_manager/puppet_module.rb, line 156
def bump_patch_version
   metadata['version'] = next_version('patch')
end
commit_metadata(remote = false) click to toggle source

@return [String] the oid of the commit that was created @param remote [Boolean] if true creates the commit on the remote repo

# File lib/release_manager/puppet_module.rb, line 216
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
commit_metadata_source(remote = false) click to toggle source

@return [String] the oid of the commit that was created

# File lib/release_manager/puppet_module.rb, line 234
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() click to toggle source

ensures the dev branch has been created and is up to date @deprecated Use {#create_src_branch} instead of this method which defaults to dev or master branch

# File lib/release_manager/puppet_module.rb, line 195
def create_dev_branch
  create_src_branch(src_branch)
end
create_src_branch(branch = src_branch) click to toggle source

@param branch [String] - the name of the source branch to create and rebase from creates a branch and checkouts out the branch with the latest source of the upstream source

# File lib/release_manager/puppet_module.rb, line 185
def create_src_branch(branch = src_branch)
  fetch('upstream')
  create_branch(branch, "upstream/#{branch}")
  # ensure we have updated our local branch
  checkout_branch(branch)
  rebase_branch(branch, branch, 'upstream')
end
git_upstream_set?() click to toggle source
# File lib/release_manager/puppet_module.rb, line 68
def git_upstream_set?
   source == git_upstream_url
end
git_upstream_url() click to toggle source
# File lib/release_manager/puppet_module.rb, line 64
def git_upstream_url
  repo.remotes['upstream'].url if remote_exists?('upstream')
end
latest_tag() click to toggle source

@return [String] - the latest tag in a series of versioned tags

# File lib/release_manager/puppet_module.rb, line 98
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
metadata() click to toggle source

@returns [Hash] the metadata object as a ruby hash

# File lib/release_manager/puppet_module.rb, line 47
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() click to toggle source

@returns [String] the name of the module found in the metadata file

# File lib/release_manager/puppet_module.rb, line 106
def mod_name
  metadata['name']
end
namespaced_name() click to toggle source
# File lib/release_manager/puppet_module.rb, line 42
def namespaced_name
  metadata['name']
end
next_version(level = 'patch') click to toggle source

@returns [String] the next version based on the release level

# File lib/release_manager/puppet_module.rb, line 120
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) click to toggle source
# File lib/release_manager/puppet_module.rb, line 84
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(id = nil) click to toggle source

pushes the source and tags @param id [String] - a ref spec to push

# File lib/release_manager/puppet_module.rb, line 209
def push_to_upstream(id = nil)
  push_branch(source, src_branch)
  push_tags(source, id)
end
r10k_module?() click to toggle source

@return [Boolean] - true if the module is an r10k-control repository

# File lib/release_manager/puppet_module.rb, line 175
def r10k_module?
  mod_name =~ /r10k[-_]?control/i
end
repo() click to toggle source
# File lib/release_manager/puppet_module.rb, line 28
def repo
  @repo ||= Rugged::Repository.new(path)
end
source() click to toggle source
# File lib/release_manager/puppet_module.rb, line 80
def source
  metadata['source']
end
src_branch() click to toggle source

@returns [String] - the source branch to push to if the user supplied the src_branch we use that otherwise if the module is r10k-control this branch will be dev, if the module is not r10k-control we use master

# File lib/release_manager/puppet_module.rb, line 203
def src_branch
  options[:src_branch] || (r10k_module? ? 'dev' : 'master')
end
tag_exists?(tag, remote = false) click to toggle source

@param tag [String] - the name of the tag @param remote [String] - check the remote for the tag, defaults to false @return [Boolean] - returns true if the tag exists

# File lib/release_manager/puppet_module.rb, line 254
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, release_notes = nil) click to toggle source

@param remote [Boolean] - create the tag remotely using the remote VCS @param id [String] - the commit id to tag to @param remote [Boolean] - use the vcs adapter instead of local tag @param release_notes [Boolean] - add release notes to the tag when remote is true

# File lib/release_manager/puppet_module.rb, line 145
def tag_module(remote = false, id = nil, release_notes = nil)
  id ||= repo.head.target_id
  if remote
    # where we get the latest from the changelog
    create_tag(source, "v#{version}", id, "v#{version}", release_notes)
  else
    create_local_tag("v#{version}", id)
  end
end
tags() click to toggle source
# File lib/release_manager/puppet_module.rb, line 72
def tags
  repo.tags.map{|v| pad_version_string(v.name)}
end
to_metadata_file() click to toggle source

creates a file with the puppet metadata.json content written to disk

# File lib/release_manager/puppet_module.rb, line 263
def to_metadata_file
  logger.info("Writing to file #{metadata_file}")
  File.write(metadata_file, to_s)
end
to_s() click to toggle source
# File lib/release_manager/puppet_module.rb, line 170
def to_s
  JSON.pretty_generate(metadata)
end
version=(v) click to toggle source
# File lib/release_manager/puppet_module.rb, line 110
def version=(v)
  metadata['version'] = v
end
version_tags() click to toggle source

@return [Array<String>] - returns a array of version strings with the v in the name

# File lib/release_manager/puppet_module.rb, line 93
def version_tags
  tags.find_all {|tag| tag =~ /\Av\d/ }
end