class Ra10ke::Validate::Validation

Attributes

puppetfile[R]

Public Class Methods

new(file) click to toggle source
# File lib/ra10ke/validate.rb, line 37
def initialize(file)
  file ||= './Puppetfile'
  @puppetfile = File.expand_path(file)
  abort("Puppetfile does not exist at #{puppetfile}") unless File.readable?(puppetfile)
end

Public Instance Methods

all_modules() click to toggle source

@return [Array] array of module information and git status

# File lib/ra10ke/validate.rb, line 44
def all_modules
  @all_modules ||= begin
    r10k_branch = Ra10ke::GitRepo.current_branch(File.dirname(puppetfile))
    git_modules(puppetfile).map do |mod|
      repo = Ra10ke::GitRepo.new(mod[:args][:git])
      ref = mod[:args][:ref] || mod[:args][:tag] || mod[:args][:branch] || mod[:args][:commit]
      # If using control_branch, try to guesstimate what the target branch should be
      if ref == ':control_branch'
        ref = ENV['CONTROL_BRANCH'] \
              || r10k_branch \
              || mod[:args][:default_branch_override] \
              || ENV['CONTROL_BRANCH_FALLBACK'] \
              || mod[:args][:default_branch] \
              || 'main'
      end
      valid_ref = repo.valid_ref?(ref) || repo.valid_commit?(mod[:args][:ref])
      {
        name: mod[:name],
        url: repo.url,
        ref: ref,
        valid_url?: repo.valid_url?,
        valid_ref?: valid_ref,
        status: valid_ref ? Ra10ke::Validate::GOOD_EMOJI : Ra10ke::Validate::BAD_EMOJI,
      }
    end
  end
end
bad_mods?() click to toggle source

@return [Boolean] - true if there are any bad mods

# File lib/ra10ke/validate.rb, line 73
def bad_mods?
  all_modules.find_all { |mod| !mod[:valid_ref?] }.count > 0
end
sorted_mods() click to toggle source

@return [Hash] - sorts the mods based on good/bad

# File lib/ra10ke/validate.rb, line 78
def sorted_mods
  all_modules.sort_by { |a| a[:valid_ref?] ? 1 : 0 }
end